blob: 277c12ed0444f3bfc2738b5eda6351226105c033 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 set_up()
{
// 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 test_accept_lang()
{
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
$this->assertEquals('en', $this->agent->accept_lang());
unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
}
// --------------------------------------------------------------------
public function test_mobile()
{
// Mobile Not Set
$_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua;
$this->assertEquals('', $this->agent->mobile());
unset($_SERVER['HTTP_USER_AGENT']);
}
// --------------------------------------------------------------------
public function test_util_is_functions()
{
$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 test_agent_string()
{
$this->assertEquals($this->_user_agent, $this->agent->agent_string());
}
// --------------------------------------------------------------------
public function test_browser_info()
{
$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 test_charsets()
{
$_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());
}
// --------------------------------------------------------------------
}
|