blob: 7dad7ac54097a1495b37ee645824c45885524092 [file] [log] [blame]
Greg Aker9512ab82011-04-21 15:10:48 -05001<?php
2
Taufan Adityaac5373a2012-03-28 16:03:38 +07003class UserAgent_test extends CI_TestCase {
4
Greg Aker9512ab82011-04-21 15:10:48 -05005 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 Barnes051a3172011-11-27 00:49:25 -05007
Eric Barnes68286a42011-04-21 22:00:33 -04008 public function set_up()
Greg Aker9512ab82011-04-21 15:10:48 -05009 {
10 // set a baseline user agent
11 $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
Eric Barnes051a3172011-11-27 00:49:25 -050012
Greg Aker9512ab82011-04-21 15:10:48 -050013 $obj = new StdClass;
Taufan Adityaac5373a2012-03-28 16:03:38 +070014 $obj->agent = new Mock_Libraries_UserAgent();
Eric Barnes051a3172011-11-27 00:49:25 -050015
Greg Aker9512ab82011-04-21 15:10:48 -050016 $this->ci_instance($obj);
Eric Barnes051a3172011-11-27 00:49:25 -050017
Greg Aker9512ab82011-04-21 15:10:48 -050018 $this->agent = $obj->agent;
19 }
20
21 // --------------------------------------------------------------------
22
Eric Barnes68286a42011-04-21 22:00:33 -040023 public function test_accept_lang()
Greg Aker9512ab82011-04-21 15:10:48 -050024 {
25 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
Eric Barnes051a3172011-11-27 00:49:25 -050026 $this->assertTrue($this->agent->accept_lang());
Greg Aker9512ab82011-04-21 15:10:48 -050027 unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
Eric Barnes051a3172011-11-27 00:49:25 -050028 $this->assertTrue($this->agent->accept_lang('en'));
29 $this->assertFalse($this->agent->accept_lang('fr'));
Greg Aker9512ab82011-04-21 15:10:48 -050030 }
31
32 // --------------------------------------------------------------------
33
Eric Barnes68286a42011-04-21 22:00:33 -040034 public function test_mobile()
Greg Aker9512ab82011-04-21 15:10:48 -050035 {
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 Barnes68286a42011-04-21 22:00:33 -040044 public function test_util_is_functions()
Greg Aker9512ab82011-04-21 15:10:48 -050045 {
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 Barnes68286a42011-04-21 22:00:33 -040054 public function test_agent_string()
Greg Aker9512ab82011-04-21 15:10:48 -050055 {
56 $this->assertEquals($this->_user_agent, $this->agent->agent_string());
57 }
58
59 // --------------------------------------------------------------------
60
Eric Barnes68286a42011-04-21 22:00:33 -040061 public function test_browser_info()
Greg Aker9512ab82011-04-21 15:10:48 -050062 {
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 Barnes051a3172011-11-27 00:49:25 -050069
Greg Aker9512ab82011-04-21 15:10:48 -050070 // --------------------------------------------------------------------
71
Eric Barnes68286a42011-04-21 22:00:33 -040072 public function test_charsets()
Greg Aker9512ab82011-04-21 15:10:48 -050073 {
74 $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
Eric Barnes051a3172011-11-27 00:49:25 -050075
Greg Aker9512ab82011-04-21 15:10:48 -050076 $charsets = $this->agent->charsets();
Eric Barnes051a3172011-11-27 00:49:25 -050077
Greg Aker9512ab82011-04-21 15:10:48 -050078 $this->assertEquals('utf8', $charsets[0]);
Eric Barnes051a3172011-11-27 00:49:25 -050079
Greg Aker9512ab82011-04-21 15:10:48 -050080 unset($_SERVER['HTTP_ACCEPT_CHARSET']);
Eric Barnes051a3172011-11-27 00:49:25 -050081
Greg Aker9512ab82011-04-21 15:10:48 -050082 $this->assertFalse($this->agent->accept_charset());
83 }
84
85 // --------------------------------------------------------------------
86
87}