This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
/
JApplicationWebClientTest.php
259 lines (239 loc) · 13.5 KB
/
JApplicationWebClientTest.php
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/**
* @package Joomla.UnitTest
* @subpackage Application
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
require_once __DIR__ . '/stubs/JWebClientInspector.php';
/**
* Test class for JApplicationWebClient.
*/
class JApplicationWebClientTest extends PHPUnit_Framework_TestCase
{
/**
* An instance of a JWebClient inspector.
*
* @var JWebClientInspector
* @since 11.3
*/
protected $inspector;
/**
* Provides test data for user agent parsing.
*
* @return array
*
* @since 11.3
*/
public static function getUserAgentData()
{
// Platform, Mobile, Engine, Browser, Version, User Agent
return array(
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '10', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '9', 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '8', 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '7.0b', 'Mozilla/4.0(compatible; MSIE 7.0b; Windows NT 6.0)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '7.0b', 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; Media Center PC 3.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '7', 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.2)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '6.1', 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '6', 'Mozilla/4.0 (compatible;MSIE 6.0;Windows 98;Q312461)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '7', 'Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.6; AOLBuild 4340.128; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '8', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; Maxthon 2.0)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::TRIDENT, JApplicationWebClient::IE, '7', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; SlimBrowser)'),
array(JApplicationWebClient::MAC, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::CHROME, '13.0.782.32', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_3) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.32 Safari/535.1'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::CHROME, '12.0.742.113', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.113 Safari/534.30'),
array(JApplicationWebClient::LINUX, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::CHROME, '12.0.742.112', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::CHROME, '15.0.864.0', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.864.0 Safari/535.2'),
array(JApplicationWebClient::BLACKBERRY, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '6.0.0.546', 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; pt) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+'),
array(JApplicationWebClient::BLACKBERRY, true, JApplicationWebClient::WEBKIT, '', '', 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/120'),
array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '999.9', 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'),
array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'),
array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'),
array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.1.0-84) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=false'),
array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '12', ' Mozilla/5.0 (Android; Tablet; rv:12.0) Gecko/12.0 Firefox/12.0'),
array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::PRESTO, JApplicationWebClient::OPERA, '11.5', 'Opera/9.80 (Android 3.2.1; Linux; Opera Tablet/ADR-1111101157; U; en) Presto/2.9.201 Version/11.50'),
array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'),
array(JApplicationWebClient::IPHONE, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.5', '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/8B5097d Safari/6531.22.7'),
array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'),
array(JApplicationWebClient::IPOD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPod; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.4', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'),
array(JApplicationWebClient::MAC, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.3', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; ar) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '3.6.9', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 ( .NET CLR 3.5.30729; .NET CLR 4.0.20506)'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '4.0b8pre', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b8pre) Gecko/20101213 Firefox/4.0b8pre'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '5', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:5.0) Gecko/20100101 Firefox/5.0'),
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '6', 'Mozilla/5.0 (Windows NT 5.0; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0'),
array(JApplicationWebClient::MAC, false, JApplicationWebClient::GECKO, '', '', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en; rv:1.9.2.14pre) Gecko/20101212 Camino/2.1a1pre (like Firefox/3.6.14pre)'),
array(JApplicationWebClient::LINUX, false, JApplicationWebClient::KHTML, '', '', 'Mozilla/5.0 (compatible; Konqueror/4.4; Linux 2.6.32-22-generic; X11; en_US) KHTML/4.4.3 (like Gecko) Kubuntu'),
array('', false, JApplicationWebClient::AMAYA, '', '', 'amaya/11.3.1 libwww/5.4.1')
);
}
/**
* Provides test data for encoding parsing.
*
* @return array
*
* @since 11.3
*/
public static function getEncodingData()
{
// HTTP_ACCEPT_ENCODING, Supported Encodings
return array(
array('gzip, deflate', array('gzip', 'deflate')),
array('x-gzip, deflate', array('x-gzip', 'deflate')),
array('gzip, x-gzip, deflate', array('gzip', 'x-gzip', 'deflate')),
array(' gzip, deflate ', array('gzip', 'deflate')),
array('deflate, x-gzip', array('deflate', 'x-gzip')),
array('goober , flasm', array('goober', 'flasm')),
array('b2z, base64', array('b2z', 'base64'))
);
}
/**
* Provides test data for language parsing.
*
* @return array
*
* @since 11.3
*/
public static function getLanguageData()
{
// HTTP_ACCEPT_LANGUAGE, Supported Language
return array(
array('en-US, en-GB', array('en-US', 'en-GB')),
array('fr-FR, de-DE', array('fr-FR', 'de-DE')),
array('en-AU, en-CA, en-GB', array('en-AU', 'en-CA', 'en-GB')),
array(' nl-NL, de-DE ', array('nl-NL', 'de-DE')),
array('en, nl-NL', array('en', 'nl-NL')),
array('nerd , geek', array('nerd', 'geek')),
array('xx-XX, xx', array('xx-XX', 'xx'))
);
}
/**
* Setup for testing.
*
* @return void
*
* @since 11.3
*/
public function setUp()
{
parent::setUp();
$_SERVER['HTTP_HOST'] = 'mydomain.com';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0';
// Get a new JWebInspector instance.
$this->inspector = new JWebClientInspector();
}
/**
* Tests the JApplicationWebClient::__construct method.
*/
public function test__construct()
{
$this->markTestIncomplete();
}
/**
* Tests the JApplicationWebClient::__get method.
*/
public function test__get()
{
$this->markTestIncomplete();
}
/**
* Tests the JApplicationWebClient::detectBrowser method.
*
* @param string $p The expected platform.
* @param boolean $m The expected mobile result.
* @param string $e The expected engine.
* @param string $b The expected browser.
* @param string $v The expected browser version.
* @param string $ua The input user agent.
*
* @return void
*
* @dataProvider getUserAgentData
* @since 11.3
*/
public function testDetectBrowser($p, $m, $e, $b, $v, $ua)
{
$this->inspector->detectBrowser($ua);
// Test the assertions.
$this->assertEquals($this->inspector->browser, $b, 'Browser detection failed');
$this->assertEquals($this->inspector->browserVersion, $v, 'Version detection failed');
}
/**
* Tests the JApplicationWebClient::detectEncoding method.
*
* @param string $ae The input accept encoding.
* @param array $e The expected array of encodings.
*
* @return void
*
* @dataProvider getEncodingData
* @since 11.3
*/
public function testDetectEncoding($ae, $e)
{
$this->inspector->detectEncoding($ae);
// Test the assertions.
$this->assertEquals($this->inspector->encodings, $e, 'Encoding detection failed');
}
/**
* Tests the JApplicationWebClient::detectEngine method.
*
* @param string $p The expected platform.
* @param boolean $m The expected mobile result.
* @param string $e The expected engine.
* @param string $b The expected browser.
* @param string $v The expected browser version.
* @param string $ua The input user agent.
*
* @return void
*
* @dataProvider getUserAgentData
* @since 11.3
*/
public function testDetectEngine($p, $m, $e, $b, $v, $ua)
{
$this->inspector->detectEngine($ua);
// Test the assertion.
$this->assertEquals($this->inspector->engine, $e, 'Engine detection failed.');
}
/**
* Tests the JApplicationWebClient::detectLanguage method.
*
* @param string $al The input accept language.
* @param array $l The expected array of languages.
*
* @return void
*
* @dataProvider getLanguageData
* @since 11.3
*/
public function testDetectLanguage($al, $l)
{
$this->inspector->detectLanguage($al);
// Test the assertions.
$this->assertEquals($this->inspector->languages, $l, 'Language detection failed');
}
/**
* Tests the JApplicationWebClient::detectPlatform method.
*
* @param string $p The expected platform.
* @param boolean $m The expected mobile result.
* @param string $e The expected engine.
* @param string $b The expected browser.
* @param string $v The expected browser version.
* @param string $ua The input user agent.
*
* @return void
*
* @dataProvider getUserAgentData
* @since 11.3
*/
public function testDetectPlatform($p, $m, $e, $b, $v, $ua)
{
$this->inspector->detectPlatform($ua);
// Test the assertions.
$this->assertEquals($this->inspector->mobile, $m, 'Mobile detection failed.');
$this->assertEquals($this->inspector->platform, $p, 'Platform detection failed.');
}
}