summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/libraries/User_agent_test.php
diff options
context:
space:
mode:
authorGreg Aker <greg.aker@ellislab.com>2011-04-21 22:19:37 +0200
committerGreg Aker <greg.aker@ellislab.com>2011-04-21 22:19:37 +0200
commitb58aeaca9be4b342bb6d88138005fdc7138828b4 (patch)
treef986aefeec38cfb6938c93f90596c41631edd7ce /tests/codeigniter/libraries/User_agent_test.php
parent1d3021a26e3d542137ceddc6c0f4a08a4f80a096 (diff)
parent9512ab8a22ff14a3789cba6e5ace03aed4196e23 (diff)
Branch merge
Diffstat (limited to 'tests/codeigniter/libraries/User_agent_test.php')
-rw-r--r--tests/codeigniter/libraries/User_agent_test.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php
new file mode 100644
index 000000000..d1d950cd9
--- /dev/null
+++ b/tests/codeigniter/libraries/User_agent_test.php
@@ -0,0 +1,91 @@
+<?php
+
+require BASEPATH.'libraries/User_agent.php';
+
+// This class needs some work...
+
+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 setUp()
+ {
+ // set a baseline user agent
+ $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
+
+ $obj = new StdClass;
+ $obj->agent = new CI_User_agent();
+
+ $this->ci_instance($obj);
+
+ $this->agent = $obj->agent;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testAcceptLang()
+ {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
+
+ $this->assertEquals('en', $this->agent->accept_lang());
+
+ unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testMobile()
+ {
+ // Mobile Not Set
+ $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua;
+ $this->assertEquals('', $this->agent->mobile());
+ unset($_SERVER['HTTP_USER_AGENT']);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testUtilIsFunctions()
+ {
+ $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 testAgentString()
+ {
+ $this->assertEquals($this->_user_agent, $this->agent->agent_string());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testBrowserInfo()
+ {
+ $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 testCharsets()
+ {
+ $_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