diff options
author | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
---|---|---|
committer | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
commit | d6ce1e936d60487ad8ddd099a040fba7d8f88367 (patch) | |
tree | 31dcdda9a24e2ed12135659a4e38cb4f35b0af31 /tests/codeigniter/libraries/Useragent_test.php | |
parent | bcee50ff3247dee71d83bf273e52bc10096cd48c (diff) | |
parent | 9e2d5d130eff40592b49337a8ba4d8c170934de1 (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Conflicts:
system/core/Loader.php
system/database/DB_query_builder.php
system/database/drivers/cubrid/cubrid_driver.php
system/database/drivers/mssql/mssql_driver.php
system/database/drivers/mysql/mysql_driver.php
system/database/drivers/mysqli/mysqli_driver.php
system/database/drivers/oci8/oci8_driver.php
system/database/drivers/odbc/odbc_driver.php
system/database/drivers/pdo/pdo_driver.php
system/database/drivers/postgre/postgre_driver.php
system/database/drivers/sqlite/sqlite_driver.php
user_guide_src/source/changelog.rst
user_guide_src/source/database/query_builder.rst
Diffstat (limited to 'tests/codeigniter/libraries/Useragent_test.php')
-rw-r--r-- | tests/codeigniter/libraries/Useragent_test.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php new file mode 100644 index 000000000..7dad7ac54 --- /dev/null +++ b/tests/codeigniter/libraries/Useragent_test.php @@ -0,0 +1,87 @@ +<?php + +class UserAgent_test extends CI_TestCase { + + protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; + protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; + + public function set_up() + { + // set a baseline user agent + $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; + + $obj = new StdClass; + $obj->agent = new Mock_Libraries_UserAgent(); + + $this->ci_instance($obj); + + $this->agent = $obj->agent; + } + + // -------------------------------------------------------------------- + + public function test_accept_lang() + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; + $this->assertTrue($this->agent->accept_lang()); + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + $this->assertTrue($this->agent->accept_lang('en')); + $this->assertFalse($this->agent->accept_lang('fr')); + } + + // -------------------------------------------------------------------- + + public function test_mobile() + { + // Mobile Not Set + $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; + $this->assertEquals('', $this->agent->mobile()); + unset($_SERVER['HTTP_USER_AGENT']); + } + + // -------------------------------------------------------------------- + + public function test_util_is_functions() + { + $this->assertTrue($this->agent->is_browser()); + $this->assertFalse($this->agent->is_robot()); + $this->assertFalse($this->agent->is_mobile()); + $this->assertFalse($this->agent->is_referral()); + } + + // -------------------------------------------------------------------- + + public function test_agent_string() + { + $this->assertEquals($this->_user_agent, $this->agent->agent_string()); + } + + // -------------------------------------------------------------------- + + public function test_browser_info() + { + $this->assertEquals('Mac OS X', $this->agent->platform()); + $this->assertEquals('Safari', $this->agent->browser()); + $this->assertEquals('533.20.27', $this->agent->version()); + $this->assertEquals('', $this->agent->robot()); + $this->assertEquals('', $this->agent->referrer()); + } + + // -------------------------------------------------------------------- + + public function test_charsets() + { + $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; + + $charsets = $this->agent->charsets(); + + $this->assertEquals('utf8', $charsets[0]); + + unset($_SERVER['HTTP_ACCEPT_CHARSET']); + + $this->assertFalse($this->agent->accept_charset()); + } + + // -------------------------------------------------------------------- + +}
\ No newline at end of file |