blob: d1d950cd9d8077bcc9017edddcb56a555f283b11 [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';
11
12 public function setUp()
13 {
14 // set a baseline user agent
15 $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
16
17 $obj = new StdClass;
18 $obj->agent = new CI_User_agent();
19
20 $this->ci_instance($obj);
21
22 $this->agent = $obj->agent;
23 }
24
25 // --------------------------------------------------------------------
26
27 public function testAcceptLang()
28 {
29 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
30
31 $this->assertEquals('en', $this->agent->accept_lang());
32
33 unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
34 }
35
36 // --------------------------------------------------------------------
37
38 public function testMobile()
39 {
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
48 public function testUtilIsFunctions()
49 {
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
58 public function testAgentString()
59 {
60 $this->assertEquals($this->_user_agent, $this->agent->agent_string());
61 }
62
63 // --------------------------------------------------------------------
64
65 public function testBrowserInfo()
66 {
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 }
73
74 // --------------------------------------------------------------------
75
76 public function testCharsets()
77 {
78 $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
79
80 $charsets = $this->agent->charsets();
81
82 $this->assertEquals('utf8', $charsets[0]);
83
84 unset($_SERVER['HTTP_ACCEPT_CHARSET']);
85
86 $this->assertFalse($this->agent->accept_charset());
87 }
88
89 // --------------------------------------------------------------------
90
91}