MDL-36316 useragent: Reduce user agent sniffing
[moodle.git] / lib / tests / useragent_test.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17 /**
18  * Tests the user agent class.
19  *
20  * @package    core
21  * @copyright  2013 Sam Hemelryk
22  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 /**
26  * User agent test suite.
27  *
28  * @package    core
29  * @copyright  2013 Sam Hemelryk
30  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31  */
32 class core_useragent_testcase extends basic_testcase {
34     /**
35      * User agents we'll be using to test.
36      * @var array
37      */
38     protected $user_agents = array(
39         'MSIE' => array(
40             '5.0' => array(
41                 'Windows 98' => 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'
42             ),
43             '5.5' => array(
44                 'Windows 2000' => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'
45             ),
46             '6.0' => array(
47                 'Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
48             ),
49             '7.0' => array(
50                 'Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)'
51             ),
52             '8.0' => array(
53                 'Windows Vista' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)'
54             ),
55             '9.0' => array(
56                 'Windows 7' => 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'
57             ),
58             '9.0i' => array(
59                 'Windows 7' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)'
60             ),
61             '10.0' => array(
62                 'Windows 8' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'
63             ),
64             '10.0i' => array(
65                 'Windows 8' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)'
66             ),
67         ),
68         'Firefox' => array(
69             '1.0.6' => array(
70                 'Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6'
71             ),
72             '1.5' => array(
73                 'Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'
74             ),
75             '1.5.0.1' => array(
76                 'Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'
77             ),
78             '2.0' => array(
79                 'Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
80                 'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)'
81             ),
82             '3.0.6' => array(
83                 'SUSE' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.4 Firefox/3.0.6'
84             ),
85             '3.6' => array(
86                 'Linux' => 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6'
87             ),
88             '11.0' => array(
89                 'Windows' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0'
90             ),
91             '15.0a2' => array(
92                 'Windows' => 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2'
93             ),
94             '18.0' => array(
95                 'Mac OS X' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0'
96             ),
97         ),
98         'SeaMonkey' => array(
99             '2.0' => array(
100                 'Windows' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0'
101             ),
102             '2.1' => array(
103                 'Linux' => 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1'
104             ),
105             '2.3' => array(
106                 'FreeBSD' => 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3'
107             ),
108         ),
109         'Safari' => array(
110             '312' => array(
111                 'Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'
112             ),
113             '412' => array(
114                 'Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412'
115             ),
116             '2.0' => array(
117                 'Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412'
118             )
119         ),
120         'Safari iOS' => array(
121             '528' => array(
122                 'iPhone' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; cs-cz) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16'
123             ),
124             '533' => array(
125                 'iPad' => 'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5'
126             ),
127         ),
128         'WebKit Android' => array(
129             '525' => array(
130                 'G1 Phone' => 'Mozilla/5.0 (Linux; U; Android 1.1; en-gb; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 – G1 Phone'
131             ),
132             '530' => array(
133                 'Nexus' => 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 –Nexus'
134             ),
135         ),
136         'Chrome' => array(
137             '8' => array(
138                 'Mac OS X' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10'
139             ),
140         ),
141         'Opera' => array(
142             '8.51' => array(
143                 'Windows XP' => 'Opera/8.51 (Windows NT 5.1; U; en)'
144             ),
145             '9.0'  => array(
146                 'Windows XP' => 'Opera/9.0 (Windows NT 5.1; U; en)',
147                 'Debian Linux' => 'Opera/9.01 (X11; Linux i686; U; en)'
148             )
149         )
150     );
152     /**
153      * Test instance generation.
154      */
155     public function test_instance() {
156         $this->assertInstanceOf('core_useragent', core_useragent::instance());
157         $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
158     }
160     /**
161      * Modifies $_SERVER['HTTP_USER_AGENT'] manually to check if check_browser_version
162      * works as expected.
163      */
164     public function test_check_browser_version() {
165         core_useragent::instance(true, $this->user_agents['Safari']['412']['Mac OS X']);
166         $this->assertTrue(core_useragent::is_safari());
167         $this->assertTrue(core_useragent::check_safari_version());
168         $this->assertTrue(core_useragent::is_webkit());
169         $this->assertTrue(core_useragent::check_webkit_version());
170         $this->assertTrue(core_useragent::check_safari_version('312'));
171         $this->assertFalse(core_useragent::check_safari_version('500'));
172         $this->assertFalse(core_useragent::is_chrome());
173         $this->assertFalse(core_useragent::check_chrome_version());
174         $this->assertFalse(core_useragent::is_safari_ios());
175         $this->assertFalse(core_useragent::check_safari_ios_version());
177         core_useragent::instance(true, $this->user_agents['Safari iOS']['528']['iPhone']);
178         $this->assertTrue(core_useragent::is_safari_ios());
179         $this->assertTrue(core_useragent::check_safari_ios_version());
180         $this->assertTrue(core_useragent::is_webkit());
181         $this->assertTrue(core_useragent::check_webkit_version());
182         $this->assertTrue(core_useragent::check_safari_ios_version('527'));
183         $this->assertFalse(core_useragent::check_safari_ios_version(590));
184         $this->assertFalse(core_useragent::check_safari_version('312'));
185         $this->assertFalse(core_useragent::check_safari_version('500'));
186         $this->assertFalse(core_useragent::is_chrome());
187         $this->assertFalse(core_useragent::check_chrome_version());
189         core_useragent::instance(true, $this->user_agents['WebKit Android']['530']['Nexus']);
190         $this->assertTrue(core_useragent::is_webkit());
191         $this->assertTrue(core_useragent::check_webkit_version());
192         $this->assertTrue(core_useragent::check_webkit_android_version('527'));
193         $this->assertFalse(core_useragent::check_webkit_android_version(590));
194         $this->assertFalse(core_useragent::is_safari());
195         $this->assertFalse(core_useragent::check_safari_version());
196         $this->assertFalse(core_useragent::is_chrome());
197         $this->assertFalse(core_useragent::check_chrome_version());
199         core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']);
200         $this->assertTrue(core_useragent::is_chrome());
201         $this->assertTrue(core_useragent::check_chrome_version());
202         $this->assertTrue(core_useragent::is_webkit());
203         $this->assertTrue(core_useragent::check_webkit_version());
204         $this->assertTrue(core_useragent::check_chrome_version(8));
205         $this->assertFalse(core_useragent::check_chrome_version(10));
206         $this->assertFalse(core_useragent::check_safari_version('1'));
208         core_useragent::instance(true, $this->user_agents['Opera']['9.0']['Windows XP']);
209         $this->assertTrue(core_useragent::is_opera());
210         $this->assertTrue(core_useragent::check_opera_version());
211         $this->assertTrue(core_useragent::check_opera_version('8.0'));
212         $this->assertFalse(core_useragent::check_opera_version('10.0'));
214         core_useragent::instance(true, $this->user_agents['MSIE']['6.0']['Windows XP SP2']);
215         $this->assertTrue(core_useragent::is_ie());
216         $this->assertTrue(core_useragent::check_ie_version());
217         $this->assertTrue(core_useragent::check_ie_version('5.0'));
218         $this->assertFalse(core_useragent::check_ie_version('7.0'));
220         core_useragent::instance(true, $this->user_agents['MSIE']['5.0']['Windows 98']);
221         $this->assertFalse(core_useragent::is_ie());
222         $this->assertFalse(core_useragent::check_ie_version());
223         $this->assertTrue(core_useragent::check_ie_version(0));
224         $this->assertTrue(core_useragent::check_ie_version('5.0'));
225         $this->assertFalse(core_useragent::check_ie_version('7.0'));
227         core_useragent::instance(true, $this->user_agents['MSIE']['9.0']['Windows 7']);
228         $this->assertTrue(core_useragent::is_ie());
229         $this->assertTrue(core_useragent::check_ie_version());
230         $this->assertTrue(core_useragent::check_ie_version(0));
231         $this->assertTrue(core_useragent::check_ie_version('5.0'));
232         $this->assertTrue(core_useragent::check_ie_version('9.0'));
233         $this->assertFalse(core_useragent::check_ie_version('10'));
235         core_useragent::instance(true, $this->user_agents['MSIE']['9.0i']['Windows 7']);
236         $this->assertTrue(core_useragent::is_ie());
237         $this->assertTrue(core_useragent::check_ie_version());
238         $this->assertTrue(core_useragent::check_ie_version(0));
239         $this->assertTrue(core_useragent::check_ie_version('5.0'));
240         $this->assertTrue(core_useragent::check_ie_version('9.0'));
241         $this->assertFalse(core_useragent::check_ie_version('10'));
243         core_useragent::instance(true, $this->user_agents['MSIE']['10.0']['Windows 8']);
244         $this->assertTrue(core_useragent::is_ie());
245         $this->assertTrue(core_useragent::check_ie_version());
246         $this->assertTrue(core_useragent::check_ie_version(0));
247         $this->assertTrue(core_useragent::check_ie_version('5.0'));
248         $this->assertTrue(core_useragent::check_ie_version('9.0'));
249         $this->assertTrue(core_useragent::check_ie_version('10'));
250         $this->assertFalse(core_useragent::check_ie_version('11'));
252         core_useragent::instance(true, $this->user_agents['MSIE']['10.0i']['Windows 8']);
253         $this->assertTrue(core_useragent::is_ie());
254         $this->assertTrue(core_useragent::check_ie_version());
255         $this->assertTrue(core_useragent::check_ie_version(0));
256         $this->assertTrue(core_useragent::check_ie_version('5.0'));
257         $this->assertTrue(core_useragent::check_ie_version('9.0'));
258         $this->assertTrue(core_useragent::check_ie_version('10'));
259         $this->assertFalse(core_useragent::check_ie_version('11'));
261         core_useragent::instance(true, $this->user_agents['Firefox']['2.0']['Windows XP']);
262         $this->assertTrue(core_useragent::is_firefox());
263         $this->assertTrue(core_useragent::check_firefox_version());
264         $this->assertTrue(core_useragent::check_firefox_version('1.5'));
265         $this->assertFalse(core_useragent::check_firefox_version('3.0'));
266         $this->assertTrue(core_useragent::check_gecko_version('2'));
267         $this->assertTrue(core_useragent::check_gecko_version(20030516));
268         $this->assertTrue(core_useragent::check_gecko_version(20051106));
269         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
271         core_useragent::instance(true, $this->user_agents['Firefox']['1.0.6']['Windows XP']);
272         $this->assertTrue(core_useragent::is_firefox());
273         $this->assertTrue(core_useragent::check_firefox_version());
274         $this->assertTrue(core_useragent::check_gecko_version('1'));
275         $this->assertFalse(core_useragent::check_gecko_version(20030516));
276         $this->assertFalse(core_useragent::check_gecko_version(20051106));
277         $this->assertFalse(core_useragent::check_gecko_version(2006010100));
278         $this->assertFalse(core_useragent::check_firefox_version('1.5'));
279         $this->assertFalse(core_useragent::check_firefox_version('3.0'));
280         $this->assertFalse(core_useragent::check_gecko_version('2'));
282         core_useragent::instance(true, $this->user_agents['Firefox']['2.0']['Windows XP']);
283         $this->assertTrue(core_useragent::is_firefox());
284         $this->assertTrue(core_useragent::check_firefox_version());
285         $this->assertTrue(core_useragent::check_firefox_version('1.5'));
286         $this->assertTrue(core_useragent::check_gecko_version('1'));
287         $this->assertTrue(core_useragent::check_gecko_version('2'));
288         $this->assertTrue(core_useragent::check_gecko_version(20030516));
289         $this->assertTrue(core_useragent::check_gecko_version(20051106));
290         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
291         $this->assertFalse(core_useragent::check_firefox_version('3.0'));
293         core_useragent::instance(true, $this->user_agents['Firefox']['3.6']['Linux']);
294         $this->assertTrue(core_useragent::is_firefox());
295         $this->assertTrue(core_useragent::check_firefox_version());
296         $this->assertTrue(core_useragent::check_firefox_version('1.5'));
297         $this->assertTrue(core_useragent::check_firefox_version('3.0'));
298         $this->assertTrue(core_useragent::check_gecko_version('2'));
299         $this->assertTrue(core_useragent::check_gecko_version('3.6'));
300         $this->assertTrue(core_useragent::check_gecko_version(20030516));
301         $this->assertTrue(core_useragent::check_gecko_version(20051106));
302         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
303         $this->assertFalse(core_useragent::check_firefox_version('4'));
304         $this->assertFalse(core_useragent::check_firefox_version('10'));
306         core_useragent::instance(true, $this->user_agents['Firefox']['3.6']['Linux']);
307         $this->assertTrue(core_useragent::is_firefox());
308         $this->assertTrue(core_useragent::check_firefox_version());
309         $this->assertTrue(core_useragent::check_firefox_version('1.5'));
310         $this->assertTrue(core_useragent::check_firefox_version('3.0'));
311         $this->assertTrue(core_useragent::check_gecko_version('2'));
312         $this->assertTrue(core_useragent::check_gecko_version('3.6'));
313         $this->assertTrue(core_useragent::check_gecko_version(20030516));
314         $this->assertTrue(core_useragent::check_gecko_version(20051106));
315         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
316         $this->assertFalse(core_useragent::check_firefox_version('4'));
317         $this->assertFalse(core_useragent::check_firefox_version('10'));
318         $this->assertFalse(core_useragent::check_firefox_version('18'));
319         $this->assertFalse(core_useragent::check_gecko_version('4'));
321         core_useragent::instance(true, $this->user_agents['Firefox']['15.0a2']['Windows']);
322         $this->assertTrue(core_useragent::is_firefox());
323         $this->assertTrue(core_useragent::check_firefox_version());
324         $this->assertTrue(core_useragent::check_firefox_version('1.5'));
325         $this->assertTrue(core_useragent::check_firefox_version('3.0'));
326         $this->assertTrue(core_useragent::check_gecko_version('2'));
327         $this->assertTrue(core_useragent::check_gecko_version('3.6'));
328         $this->assertTrue(core_useragent::check_gecko_version('15.0'));
329         $this->assertTrue(core_useragent::check_gecko_version(20030516));
330         $this->assertTrue(core_useragent::check_gecko_version(20051106));
331         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
332         $this->assertTrue(core_useragent::check_firefox_version('4'));
333         $this->assertTrue(core_useragent::check_firefox_version('10'));
334         $this->assertTrue(core_useragent::check_firefox_version('15'));
335         $this->assertFalse(core_useragent::check_firefox_version('18'));
336         $this->assertFalse(core_useragent::check_gecko_version('18'));
338         core_useragent::instance(true, $this->user_agents['Firefox']['18.0']['Mac OS X']);
339         $this->assertTrue(core_useragent::is_firefox());
340         $this->assertTrue(core_useragent::check_firefox_version());
341         $this->assertTrue(core_useragent::check_firefox_version('1.5'));
342         $this->assertTrue(core_useragent::check_firefox_version('3.0'));
343         $this->assertTrue(core_useragent::check_gecko_version('2'));
344         $this->assertTrue(core_useragent::check_gecko_version('3.6'));
345         $this->assertTrue(core_useragent::check_gecko_version('15.0'));
346         $this->assertTrue(core_useragent::check_gecko_version('18.0'));
347         $this->assertTrue(core_useragent::check_gecko_version(20030516));
348         $this->assertTrue(core_useragent::check_gecko_version(20051106));
349         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
350         $this->assertTrue(core_useragent::check_firefox_version('4'));
351         $this->assertTrue(core_useragent::check_firefox_version('10'));
352         $this->assertTrue(core_useragent::check_firefox_version('15'));
353         $this->assertTrue(core_useragent::check_firefox_version('18'));
354         $this->assertFalse(core_useragent::check_firefox_version('19'));
355         $this->assertFalse(core_useragent::check_gecko_version('19'));
357         core_useragent::instance(true, $this->user_agents['SeaMonkey']['2.0']['Windows']);
358         $this->assertTrue(core_useragent::check_gecko_version('2'));
359         $this->assertTrue(core_useragent::check_gecko_version(20030516));
360         $this->assertTrue(core_useragent::check_gecko_version(20051106));
361         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
362         $this->assertFalse(core_useragent::check_gecko_version('3.6'));
363         $this->assertFalse(core_useragent::check_gecko_version('4.0'));
364         $this->assertFalse(core_useragent::is_firefox());
365         $this->assertFalse(core_useragent::check_firefox_version());
367         core_useragent::instance(true, $this->user_agents['SeaMonkey']['2.1']['Linux']);
368         $this->assertTrue(core_useragent::check_gecko_version('2'));
369         $this->assertTrue(core_useragent::check_gecko_version('3.6'));
370         $this->assertTrue(core_useragent::check_gecko_version('4.0'));
371         $this->assertTrue(core_useragent::check_gecko_version(20030516));
372         $this->assertTrue(core_useragent::check_gecko_version(20051106));
373         $this->assertTrue(core_useragent::check_gecko_version(2006010100));
374         $this->assertTrue(core_useragent::is_firefox());
375         $this->assertTrue(core_useragent::check_firefox_version());
376         $this->assertTrue(core_useragent::check_firefox_version(4.0));
377         $this->assertFalse(core_useragent::check_firefox_version(5));
378         $this->assertFalse(core_useragent::check_gecko_version('18.0'));
380     }
382     /**
383      * Test browser version classes functionality.
384      */
385     public function test_get_browser_version_classes() {
386         core_useragent::instance(true, $this->user_agents['Safari']['412']['Mac OS X']);
387         $this->assertEquals(array('safari'), core_useragent::get_browser_version_classes());
389         core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']);
390         $this->assertEquals(array('safari'), core_useragent::get_browser_version_classes());
392         core_useragent::instance(true, $this->user_agents['Safari iOS']['528']['iPhone']);
393         $this->assertEquals(array('safari', 'ios'), core_useragent::get_browser_version_classes());
395         core_useragent::instance(true, $this->user_agents['WebKit Android']['530']['Nexus']);
396         $this->assertEquals(array('safari', 'android'), core_useragent::get_browser_version_classes());
398         core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']);
399         $this->assertEquals(array('safari'), core_useragent::get_browser_version_classes());
401         core_useragent::instance(true, $this->user_agents['Opera']['9.0']['Windows XP']);
402         $this->assertEquals(array('opera'), core_useragent::get_browser_version_classes());
404         core_useragent::instance(true, $this->user_agents['MSIE']['6.0']['Windows XP SP2']);
405         $this->assertEquals(array('ie', 'ie6'), core_useragent::get_browser_version_classes());
407         core_useragent::instance(true, $this->user_agents['MSIE']['7.0']['Windows XP SP2']);
408         $this->assertEquals(array('ie', 'ie7'), core_useragent::get_browser_version_classes());
410         core_useragent::instance(true, $this->user_agents['MSIE']['8.0']['Windows Vista']);
411         $this->assertEquals(array('ie', 'ie8'), core_useragent::get_browser_version_classes());
413         core_useragent::instance(true, $this->user_agents['MSIE']['9.0']['Windows 7']);
414         $this->assertEquals(array('ie', 'ie9'), core_useragent::get_browser_version_classes());
416         core_useragent::instance(true, $this->user_agents['MSIE']['9.0i']['Windows 7']);
417         $this->assertEquals(array('ie', 'ie9'), core_useragent::get_browser_version_classes());
419         core_useragent::instance(true, $this->user_agents['MSIE']['10.0']['Windows 8']);
420         $this->assertEquals(array('ie', 'ie10'), core_useragent::get_browser_version_classes());
422         core_useragent::instance(true, $this->user_agents['MSIE']['10.0i']['Windows 8']);
423         $this->assertEquals(array('ie', 'ie10'), core_useragent::get_browser_version_classes());
425         core_useragent::instance(true, $this->user_agents['Firefox']['2.0']['Windows XP']);
426         $this->assertEquals(array('gecko', 'gecko18'), core_useragent::get_browser_version_classes());
428         core_useragent::instance(true, $this->user_agents['Firefox']['3.0.6']['SUSE']);
429         $this->assertEquals(array('gecko', 'gecko19'), core_useragent::get_browser_version_classes());
430     }
432     /**
433      * Test device type detection.
434      */
435     public function test_get_device_type() {
436         // IE8 (common pattern ~1.5% of IE7/8 users have embedded IE6 agent).
437         $ie8 = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BT Openworld BB; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Hotbar 10.2.197.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)';
438         core_useragent::instance(true, $ie8);
439         $this->assertEquals('default', core_useragent::get_device_type());
440         // Genuine IE6.
441         $ie6 = 'Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.0.3705; Media Center PC 2.8)';
442         core_useragent::instance(true, $ie6);
443         $this->assertEquals('legacy', core_useragent::get_device_type());
445         core_useragent::instance(true);
446     }