Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 1 | <?php |
| 2 | |
Taufan Aditya | ac5373a | 2012-03-28 16:03:38 +0700 | [diff] [blame] | 3 | class UserAgent_test extends CI_TestCase { |
| 4 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 5 | 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'; |
| 6 | 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'; |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 7 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 8 | public function set_up() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 9 | { |
| 10 | // set a baseline user agent |
| 11 | $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 12 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 13 | $obj = new StdClass; |
Taufan Aditya | ac5373a | 2012-03-28 16:03:38 +0700 | [diff] [blame] | 14 | $obj->agent = new Mock_Libraries_UserAgent(); |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 15 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 16 | $this->ci_instance($obj); |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 17 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 18 | $this->agent = $obj->agent; |
| 19 | } |
| 20 | |
| 21 | // -------------------------------------------------------------------- |
| 22 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 23 | public function test_accept_lang() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 24 | { |
| 25 | $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 26 | $this->assertTrue($this->agent->accept_lang()); |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 27 | unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 28 | $this->assertTrue($this->agent->accept_lang('en')); |
| 29 | $this->assertFalse($this->agent->accept_lang('fr')); |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // -------------------------------------------------------------------- |
| 33 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 34 | public function test_mobile() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 35 | { |
| 36 | // Mobile Not Set |
| 37 | $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; |
| 38 | $this->assertEquals('', $this->agent->mobile()); |
| 39 | unset($_SERVER['HTTP_USER_AGENT']); |
| 40 | } |
| 41 | |
| 42 | // -------------------------------------------------------------------- |
| 43 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 44 | public function test_util_is_functions() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 45 | { |
| 46 | $this->assertTrue($this->agent->is_browser()); |
| 47 | $this->assertFalse($this->agent->is_robot()); |
| 48 | $this->assertFalse($this->agent->is_mobile()); |
| 49 | $this->assertFalse($this->agent->is_referral()); |
| 50 | } |
| 51 | |
| 52 | // -------------------------------------------------------------------- |
| 53 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 54 | public function test_agent_string() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 55 | { |
| 56 | $this->assertEquals($this->_user_agent, $this->agent->agent_string()); |
| 57 | } |
| 58 | |
| 59 | // -------------------------------------------------------------------- |
| 60 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 61 | public function test_browser_info() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 62 | { |
| 63 | $this->assertEquals('Mac OS X', $this->agent->platform()); |
| 64 | $this->assertEquals('Safari', $this->agent->browser()); |
| 65 | $this->assertEquals('533.20.27', $this->agent->version()); |
| 66 | $this->assertEquals('', $this->agent->robot()); |
| 67 | $this->assertEquals('', $this->agent->referrer()); |
| 68 | } |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 69 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 70 | // -------------------------------------------------------------------- |
| 71 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 72 | public function test_charsets() |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 73 | { |
| 74 | $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 75 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 76 | $charsets = $this->agent->charsets(); |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 77 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 78 | $this->assertEquals('utf8', $charsets[0]); |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 79 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 80 | unset($_SERVER['HTTP_ACCEPT_CHARSET']); |
Eric Barnes | 051a317 | 2011-11-27 00:49:25 -0500 | [diff] [blame] | 81 | |
Greg Aker | 9512ab8 | 2011-04-21 15:10:48 -0500 | [diff] [blame] | 82 | $this->assertFalse($this->agent->accept_charset()); |
| 83 | } |
| 84 | |
| 85 | // -------------------------------------------------------------------- |
| 86 | |
| 87 | } |