blob: 6f9e871962dd433d69d15ccb8c10e9f8dda49a32 [file] [log] [blame]
Greg Aker9512ab82011-04-21 15:10:48 -05001<?php
2
3require BASEPATH.'libraries/User_agent.php';
4
5// This class needs some work...
6
7class UserAgent_test extends CI_TestCase
8{
9 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';
10 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 -050011
Eric Barnes68286a42011-04-21 22:00:33 -040012 public function set_up()
Greg Aker9512ab82011-04-21 15:10:48 -050013 {
14 // set a baseline user agent
15 $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
Eric Barnes051a3172011-11-27 00:49:25 -050016
Greg Aker9512ab82011-04-21 15:10:48 -050017 $obj = new StdClass;
18 $obj->agent = new CI_User_agent();
Eric Barnes051a3172011-11-27 00:49:25 -050019
Greg Aker9512ab82011-04-21 15:10:48 -050020 $this->ci_instance($obj);
Eric Barnes051a3172011-11-27 00:49:25 -050021
Greg Aker9512ab82011-04-21 15:10:48 -050022 $this->agent = $obj->agent;
23 }
24
25 // --------------------------------------------------------------------
26
Eric Barnes68286a42011-04-21 22:00:33 -040027 public function test_accept_lang()
Greg Aker9512ab82011-04-21 15:10:48 -050028 {
29 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
Eric Barnes051a3172011-11-27 00:49:25 -050030 $this->assertTrue($this->agent->accept_lang());
Greg Aker9512ab82011-04-21 15:10:48 -050031 unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
Eric Barnes051a3172011-11-27 00:49:25 -050032 $this->assertTrue($this->agent->accept_lang('en'));
33 $this->assertFalse($this->agent->accept_lang('fr'));
Greg Aker9512ab82011-04-21 15:10:48 -050034 }
35
36 // --------------------------------------------------------------------
37
Eric Barnes68286a42011-04-21 22:00:33 -040038 public function test_mobile()
Greg Aker9512ab82011-04-21 15:10:48 -050039 {
40 // Mobile Not Set
41 $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua;
42 $this->assertEquals('', $this->agent->mobile());
43 unset($_SERVER['HTTP_USER_AGENT']);
44 }
45
46 // --------------------------------------------------------------------
47
Eric Barnes68286a42011-04-21 22:00:33 -040048 public function test_util_is_functions()
Greg Aker9512ab82011-04-21 15:10:48 -050049 {
50 $this->assertTrue($this->agent->is_browser());
51 $this->assertFalse($this->agent->is_robot());
52 $this->assertFalse($this->agent->is_mobile());
53 $this->assertFalse($this->agent->is_referral());
54 }
55
56 // --------------------------------------------------------------------
57
Eric Barnes68286a42011-04-21 22:00:33 -040058 public function test_agent_string()
Greg Aker9512ab82011-04-21 15:10:48 -050059 {
60 $this->assertEquals($this->_user_agent, $this->agent->agent_string());
61 }
62
63 // --------------------------------------------------------------------
64
Eric Barnes68286a42011-04-21 22:00:33 -040065 public function test_browser_info()
Greg Aker9512ab82011-04-21 15:10:48 -050066 {
67 $this->assertEquals('Mac OS X', $this->agent->platform());
68 $this->assertEquals('Safari', $this->agent->browser());
69 $this->assertEquals('533.20.27', $this->agent->version());
70 $this->assertEquals('', $this->agent->robot());
71 $this->assertEquals('', $this->agent->referrer());
72 }
Eric Barnes051a3172011-11-27 00:49:25 -050073
Greg Aker9512ab82011-04-21 15:10:48 -050074 // --------------------------------------------------------------------
75
Eric Barnes68286a42011-04-21 22:00:33 -040076 public function test_charsets()
Greg Aker9512ab82011-04-21 15:10:48 -050077 {
78 $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
Eric Barnes051a3172011-11-27 00:49:25 -050079
Greg Aker9512ab82011-04-21 15:10:48 -050080 $charsets = $this->agent->charsets();
Eric Barnes051a3172011-11-27 00:49:25 -050081
Greg Aker9512ab82011-04-21 15:10:48 -050082 $this->assertEquals('utf8', $charsets[0]);
Eric Barnes051a3172011-11-27 00:49:25 -050083
Greg Aker9512ab82011-04-21 15:10:48 -050084 unset($_SERVER['HTTP_ACCEPT_CHARSET']);
Eric Barnes051a3172011-11-27 00:49:25 -050085
Greg Aker9512ab82011-04-21 15:10:48 -050086 $this->assertFalse($this->agent->accept_charset());
87 }
88
89 // --------------------------------------------------------------------
90
91}