summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml5
-rw-r--r--application/config/autoload.php5
-rw-r--r--system/core/Loader.php11
-rw-r--r--system/libraries/User_agent.php23
-rw-r--r--tests/codeigniter/core/Benchmark_test.php26
-rw-r--r--tests/codeigniter/core/Input_test.php47
-rw-r--r--tests/codeigniter/core/Model_test.php37
-rw-r--r--tests/codeigniter/core/Utf8_test.php13
-rw-r--r--tests/codeigniter/libraries/Parser_test.php14
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php57
-rw-r--r--tests/mocks/core/utf8.php5
-rw-r--r--user_guide_src/source/changelog.rst3
12 files changed, 208 insertions, 38 deletions
diff --git a/.travis.yml b/.travis.yml
index 27fe3c670..718e6aaa6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,6 +26,11 @@ script: phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml
matrix:
allow_failures:
- php: hhvm
+ exclude:
+ - php: hhvm
+ env: DB=mysqli
+ env: DB=pgsql
+ env: DB=pdo/pgsql
branches:
only:
diff --git a/application/config/autoload.php b/application/config/autoload.php
index 5a20c943a..43d53155b 100644
--- a/application/config/autoload.php
+++ b/application/config/autoload.php
@@ -77,6 +77,11 @@ $autoload['packages'] = array();
| Prototype:
|
| $autoload['libraries'] = array('database', 'email', 'xmlrpc');
+|
+| You can also supply an alternative library name to be assigned
+| in the controller:
+|
+| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array();
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 78172580d..8c8d5a37c 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -184,9 +184,16 @@ class CI_Loader {
}
elseif (is_array($library))
{
- foreach ($library as $class)
+ foreach ($library as $key => $value)
{
- $this->library($class, $params);
+ if (is_int($key))
+ {
+ $this->library($value, $params);
+ }
+ else
+ {
+ $this->library($key, $params, $value);
+ }
}
return $this;
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 3a6b6bc98..1dfa3e72d 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -145,6 +145,15 @@ class CI_User_agent {
public $robot = '';
/**
+ * HTTP Referer
+ *
+ * @var mixed
+ */
+ public $referer;
+
+ // --------------------------------------------------------------------
+
+ /**
* Constructor
*
* Sets the User Agent and runs the compilation routine
@@ -358,7 +367,7 @@ class CI_User_agent {
{
if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
- $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
+ $this->languages = explode(',', preg_replace('/(;\s?q=[0-9\.]+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
}
if (count($this->languages) === 0)
@@ -378,7 +387,7 @@ class CI_User_agent {
{
if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET']))
{
- $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
+ $this->charsets = explode(',', preg_replace('/(;\s?q=.+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
}
if (count($this->charsets) === 0)
@@ -471,24 +480,22 @@ class CI_User_agent {
*/
public function is_referral()
{
- static $result;
-
- if ( ! isset($result))
+ if ( ! isset($this->referer))
{
if (empty($_SERVER['HTTP_REFERER']))
{
- $result = FALSE;
+ $this->referer = FALSE;
}
else
{
$referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$own_host = parse_url(config_item('base_url'), PHP_URL_HOST);
- $result = ($referer_host && $referer_host !== $own_host);
+ $this->referer = ($referer_host && $referer_host !== $own_host);
}
}
- return $result;
+ return $this->referer;
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index aff736a40..7fd0727e2 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -27,10 +27,34 @@ class Benchmark_test extends CI_TestCase {
$this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));
$this->benchmark->mark('code_start');
- sleep(1);
$this->benchmark->mark('code_end');
+ // Override values, because time isn't testable, but make sure the markers were set
+ if (isset($this->benchmark->marker['code_start']) && is_float($this->benchmark->marker['code_start']))
+ {
+ $this->benchmark->marker['code_start'] = 1389956144.1944;
+ }
+
+ if (isset($this->benchmark->marker['code_end']) && is_float($this->benchmark->marker['code_end']))
+ {
+ $this->benchmark->marker['code_end'] = 1389956145.1946;
+ }
+
$this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0));
+ $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
+ $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 2));
+ $this->assertEquals('1.000', $this->benchmark->elapsed_time('code_start', 'code_end', 3));
+ $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end', 4));
+ $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end'));
+
+ // Test with non-existing 2nd marker, but again - we need to override the value
+ $this->benchmark->elapsed_time('code_start', 'code_end2');
+ if (isset($this->benchmark->marker['code_end2']) && is_float($this->benchmark->marker['code_end2']))
+ {
+ $this->benchmark->marker['code_end2'] = 1389956146.2046;
+ }
+
+ $this->assertEquals('2.0102', $this->benchmark->elapsed_time('code_start', 'code_end2'));
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index 0a98e556c..95833fc91 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -138,13 +138,24 @@ class Input_test extends CI_TestCase {
public function test_valid_ip()
{
- $ip_v4 = '192.18.0.1';
- $this->assertTrue($this->input->valid_ip($ip_v4));
+ $this->assertTrue($this->input->valid_ip('192.18.0.1'));
+ $this->assertTrue($this->input->valid_ip('192.18.0.1', 'ipv4'));
+ $this->assertFalse($this->input->valid_ip('555.0.0.0'));
+ $this->assertFalse($this->input->valid_ip('2001:db8:0:85a3::ac1f:8001', 'ipv4'));
+
+ // v6 tests
+ $this->assertFalse($this->input->valid_ip('192.18.0.1', 'ipv6'));
+
+ $ip_v6 = array(
+ '2001:0db8:0000:85a3:0000:0000:ac1f:8001',
+ '2001:db8:0:85a3:0:0:ac1f:8001',
+ '2001:db8:0:85a3::ac1f:8001'
+ );
- $ip_v6 = array('2001:0db8:0000:85a3:0000:0000:ac1f:8001', '2001:db8:0:85a3:0:0:ac1f:8001', '2001:db8:0:85a3::ac1f:8001');
foreach ($ip_v6 as $ip)
{
$this->assertTrue($this->input->valid_ip($ip));
+ $this->assertTrue($this->input->valid_ip($ip, 'ipv6'));
}
}
@@ -171,4 +182,34 @@ class Input_test extends CI_TestCase {
$this->assertTrue($this->input->is_ajax_request());
}
+ // --------------------------------------------------------------------
+
+ public function test_input_stream()
+ {
+ $this->markTestSkipped('TODO: Find a way to test input://');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_cookie()
+ {
+ $this->markTestSkipped('TODO: Find a way to test HTTP headers');
+ }
+
+ public function test_ip_address()
+ {
+ // 127.0.0.1 is set in our Bootstrap file
+ $this->assertEquals('127.0.0.1', $this->input->ip_address());
+
+ // Invalid
+ $_SERVER['REMOTE_ADDR'] = 'invalid_ip_address';
+ $this->input->ip_address = FALSE; // reset cached value
+ $this->assertEquals('0.0.0.0', $this->input->ip_address());
+
+ // TODO: Add proxy_ips tests
+
+ // Back to reality
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Model_test.php b/tests/codeigniter/core/Model_test.php
new file mode 100644
index 000000000..80dc97b3b
--- /dev/null
+++ b/tests/codeigniter/core/Model_test.php
@@ -0,0 +1,37 @@
+<?php
+
+class Model_test extends CI_TestCase {
+
+ private $ci_obj;
+
+ public function set_up()
+ {
+ $loader = $this->ci_core_class('loader');
+ $this->load = new $loader();
+ $this->ci_obj = $this->ci_instance();
+ $this->ci_set_core_class('model', 'CI_Model');
+
+ $model_code =<<<MODEL
+<?php
+class Test_model extends CI_Model {
+
+ public \$property = 'foo';
+
+}
+MODEL;
+
+ $this->ci_vfs_create('Test_model', $model_code, $this->ci_app_root, 'models');
+ $this->load->model('test_model');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test__get()
+ {
+ $this->assertEquals('foo', $this->ci_obj->test_model->property);
+
+ $this->ci_obj->controller_property = 'bar';
+ $this->assertEquals('bar', $this->ci_obj->test_model->controller_property);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php
index caa7b6986..71299134e 100644
--- a/tests/codeigniter/core/Utf8_test.php
+++ b/tests/codeigniter/core/Utf8_test.php
@@ -11,10 +11,15 @@ class Utf8_test extends CI_TestCase {
public function test_convert_to_utf8()
{
- $this->assertEquals(
- $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251'),
- 'ั‚ะตัั‚'
- );
+ $this->assertEquals('ั‚ะตัั‚', $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_is_ascii()
+ {
+ $this->assertTrue($this->utf8->is_ascii_test('foo bar'));
+ $this->assertFalse($this->utf8->is_ascii_test('ั‚ะตัั‚'));
}
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index 6e5c192dd..3755cf1a0 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -33,7 +33,7 @@ class Parser_test extends CI_TestCase {
// --------------------------------------------------------------------
- public function test_parse_simple_string()
+ public function test_parse_string()
{
$data = array(
'title' => 'Page Title',
@@ -69,11 +69,7 @@ class Parser_test extends CI_TestCase {
{
$data = array(
'title' => 'Super Heroes',
- 'powers' => array(
- array(
- 'invisibility' => 'yes',
- 'flying' => 'no'),
- )
+ 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no'))
);
$template = "{title}\n{powers}{invisibility}\n{flying}{/powers}\nsecond:{powers} {invisibility} {flying}{/powers}";
@@ -87,11 +83,7 @@ class Parser_test extends CI_TestCase {
{
$data = array(
'title' => 'Super Heroes',
- 'powers' => array(
- array(
- 'invisibility' => 'yes',
- 'flying' => 'no'),
- )
+ 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no'))
);
$template = "{title}\n{powers}{invisibility}\n{flying}";
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index e3726554e..aed38b8c2 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -11,9 +11,7 @@ class UserAgent_test extends CI_TestCase {
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
$this->ci_vfs_clone('application/config/user_agents.php');
-
$this->agent = new Mock_Libraries_UserAgent();
-
$this->ci_instance_var('agent', $this->agent);
}
@@ -40,12 +38,27 @@ class UserAgent_test extends CI_TestCase {
// --------------------------------------------------------------------
- public function test_util_is_functions()
+ public function test_is_functions()
{
$this->assertTrue($this->agent->is_browser());
+ $this->assertTrue($this->agent->is_browser('Safari'));
+ $this->assertFalse($this->agent->is_browser('Firefox'));
$this->assertFalse($this->agent->is_robot());
$this->assertFalse($this->agent->is_mobile());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_referrer()
+ {
+ $_SERVER['HTTP_REFERER'] = 'http://codeigniter.com/user_guide/';
+ $this->assertTrue($this->agent->is_referral());
+ $this->assertEquals('http://codeigniter.com/user_guide/', $this->agent->referrer());
+
+ $this->agent->referer = NULL;
+ unset($_SERVER['HTTP_REFERER']);
$this->assertFalse($this->agent->is_referral());
+ $this->assertEquals('', $this->agent->referrer());
}
// --------------------------------------------------------------------
@@ -63,7 +76,6 @@ class UserAgent_test extends CI_TestCase {
$this->assertEquals('Safari', $this->agent->browser());
$this->assertEquals('533.20.27', $this->agent->version());
$this->assertEquals('', $this->agent->robot());
- $this->assertEquals('', $this->agent->referrer());
}
// --------------------------------------------------------------------
@@ -71,14 +83,43 @@ class UserAgent_test extends CI_TestCase {
public function test_charsets()
{
$_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
+ $this->agent->charsets = array();
+ $this->agent->charsets();
+ $this->assertTrue($this->agent->accept_charset('utf8'));
+ $this->assertFalse($this->agent->accept_charset('foo'));
+ $this->assertEquals('utf8', $this->agent->charsets[0]);
+
+ $_SERVER['HTTP_ACCEPT_CHARSET'] = '';
+ $this->agent->charsets = array();
+ $this->assertFalse($this->agent->accept_charset());
+ $this->assertEquals('Undefined', $this->agent->charsets[0]);
- $charsets = $this->agent->charsets();
-
- $this->assertEquals('utf8', $charsets[0]);
+ $_SERVER['HTTP_ACCEPT_CHARSET'] = 'iso-8859-5, unicode-1-1; q=0.8';
+ $this->agent->charsets = array();
+ $this->assertTrue($this->agent->accept_charset('iso-8859-5'));
+ $this->assertTrue($this->agent->accept_charset('unicode-1-1'));
+ $this->assertFalse($this->agent->accept_charset('foo'));
+ $this->assertEquals('iso-8859-5', $this->agent->charsets[0]);
+ $this->assertEquals('unicode-1-1', $this->agent->charsets[1]);
unset($_SERVER['HTTP_ACCEPT_CHARSET']);
+ }
- $this->assertFalse($this->agent->accept_charset());
+ public function test_parse()
+ {
+ $new_agent = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
+ $this->agent->parse($new_agent);
+
+ $this->assertEquals('Android', $this->agent->platform());
+ $this->assertEquals('Firefox', $this->agent->browser());
+ $this->assertEquals('13.0', $this->agent->version());
+ $this->assertEquals('', $this->agent->robot());
+ $this->assertEquals('Android', $this->agent->mobile());
+ $this->assertEquals($new_agent, $this->agent->agent_string());
+ $this->assertTrue($this->agent->is_browser());
+ $this->assertFalse($this->agent->is_robot());
+ $this->assertTrue($this->agent->is_mobile());
+ $this->assertTrue($this->agent->is_mobile('android'));
}
} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
index 068e74ac1..a43138fbc 100644
--- a/tests/mocks/core/utf8.php
+++ b/tests/mocks/core/utf8.php
@@ -23,4 +23,9 @@ class Mock_Core_Utf8 extends CI_Utf8 {
}
}
+ public function is_ascii_test($str)
+ {
+ return $this->_is_ascii($str);
+ }
+
} \ No newline at end of file
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 388bc28ce..237e237e2 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -421,7 +421,7 @@ Release Date: Not Released
- Added autoloading of drivers with ``$autoload['drivers']``.
- ``$config['rewrite_short_tags']`` now has no effect when using PHP 5.4 as ``<?=`` will always be available.
- Changed method ``config()`` to return whatever ``CI_Config::load()`` returns instead of always being void.
- - Added support for model aliasing on autoload.
+ - Added support for library and model aliasing on autoload.
- Changed method ``is_loaded()`` to ask for the (case sensitive) library name instead of its instance name.
- Removed ``$_base_classes`` property and unified all class data in ``$_ci_classes`` instead.
- Added method ``clear_vars()`` to allow clearing the cached variables for views.
@@ -676,6 +676,7 @@ Bug fixes for 3.0
- Fixed an edge case (#555) - incorrect browser version was reported for Opera 10+ due to a non-standard user-agent string.
- Fixed a bug (#133) - :doc:`Text Helper <helpers/text_helper>` :func:`ascii_to_entities()` stripped the last character if it happens to be in the extended ASCII group.
- Fixed a bug (#2822) - ``fwrite()`` was used incorrectly throughout the whole framework, allowing incomplete writes when writing to a network stream and possibly a few other edge cases.
+- Fixed a bug where :doc:`User Agent Library <libraries/user_agent>` methods ``accept_charset()`` and ``accept_lang()`` didn't properly parse HTTP headers that contain spaces.
- Fixed a bug where *default_controller* was called instad of triggering a 404 error if the current route is in a controller directory.
Version 2.1.4