weekly release 3.0dev
[moodle.git] / lib / tests / useragent_test.php
CommitLineData
c3d2fbf9
SH
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/>.
16
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 */
24
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 */
32class core_useragent_testcase extends basic_testcase {
33
c3e1c9b1
DM
34 /**
35 * Restores the user agent to the default one.
36 */
37 public function tearDown() {
38 core_useragent::instance(true);
39 }
40
7c10ad33 41 public function user_agents_providers() {
96a54631
AN
42 // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list.
43 // This ensures that regression tests are applied to all known user agents.
7c10ad33
AN
44 return array(
45 // Windows 98; Internet Explorer 5.0.
46 array(
47 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
48 array(
49 // MSIE 5.0 is not considered a browser at all: known false results.
50 'is_ie' => false,
51 'check_ie_version' => array(
52 '0' => true,
53 '5.0' => true,
54 ),
55 'versionclasses' => array(
56 // IE 5.0 is not considered a browser.
57 ),
58
59 // IE 5.0 is a legacy browser.
96a54631 60 'devicetype' => 'legacy',
7c10ad33
AN
61
62 'supports_svg' => false,
83af1329 63 'supports_json_contenttype' => false,
7c10ad33 64 ),
c3d2fbf9 65 ),
7c10ad33
AN
66
67 // Windows 2000; Internet Explorer 5.5.
68 array(
69 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
70 array(
71 'is_ie' => true,
72 'check_ie_version' => array(
73 '0' => true,
74 '5.0' => true,
75 '5.5' => true,
76 ),
77 'versionclasses' => array(
78 'ie',
79 ),
80
81 // IE 6.0 is a legacy browser.
96a54631 82 'devicetype' => 'legacy',
7c10ad33
AN
83
84 'supports_svg' => false,
83af1329 85 'supports_json_contenttype' => false,
7c10ad33 86 ),
c3d2fbf9 87 ),
7c10ad33
AN
88
89 // Windows XP SP2; Internet Explorer 6.0.
90 array(
91 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
92 array(
93 'is_ie' => true,
94 'check_ie_version' => array(
95 '0' => true,
96 '5.0' => true,
97 '5.5' => true,
98 '6.0' => true,
99 ),
100 'versionclasses' => array(
101 'ie',
102 'ie6',
103 ),
104
105 // IE 7.0 is a legacy browser.
106 'devicetype' => 'legacy',
107
108 'supports_svg' => false,
83af1329 109 'supports_json_contenttype' => false,
7c10ad33 110 ),
c3d2fbf9 111 ),
7c10ad33
AN
112
113 // Windows XP SP2; Internet Explorer 7.0.
114 array(
115 '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)',
116 array(
117 'is_ie' => true,
118 'check_ie_version' => array(
119 '0' => true,
120 '5.0' => true,
121 '5.5' => true,
122 '6.0' => true,
123 '7.0' => true,
124 ),
125 'versionclasses' => array(
126 'ie',
127 'ie7',
128 ),
129
130 'supports_svg' => false,
83af1329 131 'supports_json_contenttype' => false,
7c10ad33 132 ),
c3d2fbf9 133 ),
7c10ad33
AN
134
135 // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
136 array(
137 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Meridio for Excel 5.0.251; Meridio for PowerPoint 5.0.251; Meridio for Word 5.0.251; Meridio Protocol; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)',
138 array(
139 'is_ie' => true,
140 'check_ie_version' => array(
141 '0' => true,
142 '5.0' => true,
143 '5.5' => true,
144 '6.0' => true,
145 '7.0' => true,
146 ),
147 'versionclasses' => array(
148 'ie',
149 'ie7',
150 ),
151
152 'supports_svg' => false,
83af1329 153 'supports_json_contenttype' => false,
7c10ad33 154 ),
d2fdad7c 155 ),
7c10ad33
AN
156
157 // Windows Vista; Internet Explorer 8.0.
158 array(
159 '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)',
160 array(
161 'is_ie' => true,
162 'check_ie_version' => array(
163 '0' => true,
164 '5.0' => true,
165 '5.5' => true,
166 '6.0' => true,
167 '7.0' => true,
168 '8.0' => true,
169 ),
7c10ad33
AN
170 'versionclasses' => array(
171 'ie',
172 'ie8',
173 ),
174
175 'supports_svg' => false,
176 ),
c3d2fbf9 177 ),
7c10ad33
AN
178
179 // Windows 7; Internet Explorer 9.0.
180 array(
181 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
182 array(
183 'is_ie' => true,
184 'check_ie_version' => array(
185 '0' => true,
186 '5.0' => true,
187 '5.5' => true,
188 '6.0' => true,
189 '7.0' => true,
190 '8.0' => true,
191 '9.0' => true,
192 ),
193 'versionclasses' => array(
194 'ie',
195 'ie9',
196 ),
197 ),
c3d2fbf9 198 ),
7c10ad33
AN
199
200 // Windows 7; Internet Explorer 9.0i.
201 array(
202 '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)',
203 array(
204 'is_ie' => true,
205 'check_ie_version' => array(
206 '0' => true,
207 '5.0' => true,
208 '5.5' => true,
209 '6.0' => true,
210 '7.0' => true,
211 '8.0' => true,
212 '9.0' => true,
213 ),
214 'versionclasses' => array(
215 'ie',
216 'ie9',
217 ),
218 'iecompatibility' => true,
219
220 // IE 9 in Compatiblity mode does not support SVG.
221 'supports_svg' => false,
83af1329
AN
222
223 // IE in Compatiblity mode does not support JSON ContentType.
224 'supports_json_contenttype' => false,
7c10ad33 225 ),
c3d2fbf9 226 ),
7c10ad33
AN
227
228 // Windows 8; Internet Explorer 10.0.
229 array(
230 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
231 array(
232 'is_ie' => true,
233 'check_ie_version' => array(
234 '0' => true,
235 '5.0' => true,
236 '5.5' => true,
237 '6.0' => true,
238 '7.0' => true,
239 '8.0' => true,
240 '9.0' => true,
241 '10' => true,
242 ),
243 'versionclasses' => array(
244 'ie',
245 'ie10',
246 ),
247 ),
c3d2fbf9 248 ),
c3d2fbf9 249
7c10ad33
AN
250 // Windows 8; Internet Explorer 10.0i.
251 array(
252 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
253 array(
254 'is_ie' => true,
255 'check_ie_version' => array(
256 '0' => true,
257 '5.0' => true,
258 '5.5' => true,
259 '6.0' => true,
260 '7.0' => true,
261 '8.0' => true,
262 '9.0' => true,
263 '10' => true,
264 ),
265 'iecompatibility' => true,
266 'versionclasses' => array(
267 'ie',
268 'ie10',
269 ),
83af1329
AN
270
271 // IE in Compatiblity mode does not support JSON ContentType.
272 'supports_json_contenttype' => false,
7c10ad33
AN
273 ),
274 ),
c3d2fbf9 275
7c10ad33
AN
276 // Windows 8.1; Internet Explorer 11.0.
277 array(
278 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
279 array(
280 'is_ie' => true,
281 'check_ie_version' => array(
282 '0' => true,
283 '5.0' => true,
284 '5.5' => true,
285 '6.0' => true,
286 '7.0' => true,
287 '8.0' => true,
288 '9.0' => true,
289 '10' => true,
290 '11' => true,
291 ),
292 'versionclasses' => array(
293 'ie',
294 'ie11',
295 ),
296 ),
297 ),
c3d2fbf9 298
7c10ad33
AN
299 // Windows 8.1; Internet Explorer 11.0i.
300 array(
301 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
302 array(
303 'is_ie' => true,
304 'check_ie_version' => array(
305 '0' => true,
306 '5.0' => true,
307 '5.5' => true,
308 '6.0' => true,
309 '7.0' => true,
310 '8.0' => true,
311 '9.0' => true,
312 '10' => true,
313 '11' => true,
314 ),
315 'iecompatibility' => true,
316 'versionclasses' => array(
317 'ie',
318 'ie11',
319 ),
83af1329
AN
320
321 // IE in Compatiblity mode does not support JSON ContentType.
322 'supports_json_contenttype' => false,
7c10ad33
AN
323 ),
324 ),
325
326 // Windows XP; Firefox 1.0.6.
327 array(
328 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
329 array(
330 'is_firefox' => true,
331
332 'is_gecko' => true,
333 'check_gecko_version' => array(
334 '1' => true,
335 ),
336
337 'versionclasses' => array(
338 'gecko',
339 'gecko17',
340 ),
341 ),
342 ),
343
344 // Windows XP; Firefox 1.0.6.
345 array(
346 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
347 array(
348 'is_firefox' => true,
349 'check_firefox_version' => array(
350 '1.5' => true,
351 ),
352
353 'is_gecko' => true,
354 'check_gecko_version' => array(
355 '1' => true,
356 '20030516' => true,
357 '20051116' => true,
358 ),
359
360 'versionclasses' => array(
361 'gecko',
362 'gecko18',
363 ),
364 ),
365 ),
366
367 // Windows XP; Firefox 1.5.0.1.
368 array(
369 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
370 array(
371 'is_firefox' => true,
372 'check_firefox_version' => array(
373 '1.5' => true,
374 ),
375
376 'is_gecko' => true,
377 'check_gecko_version' => array(
378 '1' => true,
379 '20030516' => true,
380 '20051116' => true,
381 ),
382
383 'versionclasses' => array(
384 'gecko',
385 'gecko18',
386 ),
387 ),
388 ),
389
390 // Windows XP; Firefox 2.0.
391 array(
392 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
393 array(
394 'is_firefox' => true,
395 'check_firefox_version' => array(
396 '1.5' => true,
397 ),
398
399 'is_gecko' => true,
400 'check_gecko_version' => array(
401 '1' => true,
402 '2' => true,
403 '20030516' => true,
404 '20051116' => true,
405 '2006010100' => true,
406 ),
407
408 'versionclasses' => array(
409 'gecko',
410 'gecko18',
411 ),
412 ),
413 ),
414
415 // Ubuntu Linux amd64; Firefox 2.0.
416 array(
417 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
418 array(
419 'is_firefox' => true,
420 'check_firefox_version' => array(
421 '1.5' => true,
422 ),
423
424 'is_gecko' => true,
425 'check_gecko_version' => array(
426 '1' => true,
427 '2' => true,
428 '20030516' => true,
429 '20051116' => true,
430 '2006010100' => true,
431 ),
432
433 'versionclasses' => array(
434 'gecko',
435 'gecko18',
436 ),
437 ),
438 ),
439
440 // SUSE; Firefox 3.0.6.
441 array(
442 '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',
443 array(
444 'is_firefox' => true,
445 'check_firefox_version' => array(
446 '1.5' => true,
447 '3.0' => true,
448 ),
449
450 'is_gecko' => true,
451 'check_gecko_version' => array(
452 '1' => true,
453 '2' => true,
454 '20030516' => true,
455 '20051116' => true,
456 '2006010100' => true,
457 ),
458
459 'versionclasses' => array(
460 'gecko',
461 'gecko19',
462 ),
463 ),
464 ),
465
466 // Linux i686; Firefox 3.6.
467 array(
468 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
469 array(
470 'is_firefox' => true,
471 'check_firefox_version' => array(
472 '1.5' => true,
473 '3.0' => true,
474 ),
475
476 'is_gecko' => true,
477 'check_gecko_version' => array(
478 '1' => true,
479 '2' => true,
480 '20030516' => true,
481 '20051116' => true,
482 '2006010100' => true,
483 '3.6' => true,
5ee4f581 484 '20100101' => true,
7c10ad33
AN
485 ),
486
487 'versionclasses' => array(
488 'gecko',
489 'gecko20',
490 ),
491 ),
492 ),
493
494 // Windows; Firefox 11.0.
495 array(
496 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
497 array(
498 'is_firefox' => true,
499 'check_firefox_version' => array(
500 '1.5' => true,
501 '3.0' => true,
502 '4' => true,
503 '10' => true,
504 ),
505
506 'is_gecko' => true,
507 'check_gecko_version' => array(
508 '1' => true,
509 '2' => true,
510 '20030516' => true,
511 '20051116' => true,
512 '2006010100' => true,
5ee4f581 513 '20100101' => true,
7c10ad33
AN
514 '3.6' => true,
515 '4.0' => true,
516 ),
517
518 'versionclasses' => array(
519 'gecko',
520 ),
521 ),
522 ),
523
524 // Windows; Firefox 15.0a2.
525 array(
526 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
527 array(
528 'is_firefox' => true,
529 'check_firefox_version' => array(
530 '1.5' => true,
531 '3.0' => true,
532 '4' => true,
533 '10' => true,
534 '15' => true,
535 ),
536
537 'is_gecko' => true,
538 'check_gecko_version' => array(
539 '1' => true,
540 '2' => true,
541 '20030516' => true,
542 '20051116' => true,
543 '2006010100' => true,
5ee4f581 544 '20100101' => true,
7c10ad33
AN
545 '3.6' => true,
546 '4.0' => true,
547 '15.0' => true,
548 ),
549
550 'versionclasses' => array(
551 'gecko',
552 ),
553 ),
554 ),
555
556 // Firefox 18; Mac OS X 10.
557 array(
558 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
559 array(
560 'is_firefox' => true,
561 'check_firefox_version' => array(
562 '1.5' => true,
563 '3.0' => true,
564 '4' => true,
565 '10' => true,
566 '15' => true,
567 '18' => true,
568 ),
569
570 'is_gecko' => true,
571 'check_gecko_version' => array(
572 '1' => true,
573 '2' => true,
574 '20030516' => true,
575 '20051116' => true,
576 '2006010100' => true,
577 '3.6' => true,
578 '4.0' => true,
579 '15.0' => true,
580 '18.0' => true,
5ee4f581
AN
581 '20100101' => true,
582 ),
583
584 'versionclasses' => array(
585 'gecko',
586 ),
587 ),
588 ),
589
590 // Firefox 33; Mac OS X 10.10.
591 array(
592 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
593 array(
594 'is_firefox' => true,
595 'check_firefox_version' => array(
596 '1.5' => true,
597 '3.0' => true,
598 '4' => true,
599 '10' => true,
600 '15' => true,
601 '18' => true,
602 '19' => true,
603 '33' => true,
604 ),
605
606 'is_gecko' => true,
607 'check_gecko_version' => array(
608 '1' => true,
609 '2' => true,
610 '20030516' => true,
611 '20051116' => true,
612 '2006010100' => true,
613 '3.6' => true,
614 '4.0' => true,
615 '15.0' => true,
616 '18.0' => true,
617 '19.0' => true,
618 '20100101' => true,
7c10ad33
AN
619 ),
620
621 'versionclasses' => array(
622 'gecko',
623 ),
624 ),
625 ),
626
627 // SeaMonkey 2.0; Windows.
628 array(
629 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
630 array(
631 'is_gecko' => true,
632 'check_gecko_version' => array(
633 '1' => true,
634 '2' => true,
635 '20030516' => true,
636 '20051106' => true,
637 '20051116' => true,
638 '2006010100' => true,
639 ),
640
641 'versionclasses' => array(
642 'gecko',
643 'gecko19',
644 ),
645 ),
646 ),
647
648 // SeaMonkey 2.1; Linux.
649 array(
650 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
651 array(
652 'is_gecko' => true,
653 'check_gecko_version' => array(
654 '1' => true,
655 '2' => true,
656 '20030516' => true,
657 '20051116' => true,
658 '2006010100' => true,
5ee4f581 659 '20100101' => true,
7c10ad33
AN
660 '3.6' => true,
661 '4.0' => true,
662 ),
663
664 'is_firefox' => true,
665 'check_firefox_version' => array(
666 '1.5' => true,
667 '3.0' => true,
668 '4' => true,
669 ),
670
671 'versionclasses' => array(
672 'gecko',
673 'gecko20',
674 ),
675 ),
676 ),
677
678 // SeaMonkey 2.3; FreeBSD.
679 array(
680 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
681 array(
682 'is_gecko' => true,
683 'check_gecko_version' => array(
684 '1' => true,
685 '2' => true,
686 '20030516' => true,
687 '20051116' => true,
688 '2006010100' => true,
5ee4f581 689 '20100101' => true,
7c10ad33
AN
690 '3.6' => true,
691 '4.0' => true,
692 ),
693
694 'is_firefox' => true,
695 'check_firefox_version' => array(
696 '1.5' => true,
697 '3.0' => true,
698 '4' => true,
699 ),
700
701 'versionclasses' => array(
702 'gecko',
703 ),
704 ),
705 ),
706
707 // Windows 7; MS Word 2010.
708 array(
709 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; ms-office)',
710 array(
711 'is_ie' => true,
712 'check_ie_version' => array(
713 '0' => true,
714 '5.0' => true,
715 '5.5' => true,
716 '6.0' => true,
717 '7.0' => true,
718 '8.0' => true,
719 ),
720 'iecompatibility' => true,
721 'versionclasses' => array(
722 'ie',
723 'ie8',
724 ),
725
726 'is_msword' => true,
727
728 'supports_svg' => false,
83af1329 729 'supports_json_contenttype' => false,
7c10ad33
AN
730 ),
731 ),
732
733 // Windows 7; MS Outlook 2010.
734 array(
735 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Microsoft Outlook 14.0.7113; ms-office; MSOffice 14)',
736 array(
737 'is_ie' => true,
738 'check_ie_version' => array(
739 '0' => true,
740 '5.0' => true,
741 '5.5' => true,
742 '6.0' => true,
743 '7.0' => true,
744 '8.0' => true,
745 ),
746 'iecompatibility' => true,
747 'versionclasses' => array(
748 'ie',
749 'ie8',
750 ),
751
752 // Note: Outlook is deliberately not considered to be MS Word.
753 'is_msword' => false,
754
755 'supports_svg' => false,
83af1329 756 'supports_json_contenttype' => false,
7c10ad33
AN
757 ),
758 ),
759
760 // Mac OS X; MS Word 14.
761 array(
762 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
763 array(
764 'versionclasses' => array(
765 ),
766
767 'is_msword' => true,
768 ),
769 ),
770
771 // Safari 312; Max OS X.
772 array(
773 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
774 array(
775 'is_safari' => true,
776 'check_safari_version' => array(
777 '1' => true,
778 '312' => true,
779 ),
780
781 'is_webkit' => true,
782
783 'versionclasses' => array(
784 'safari',
785 ),
786 ),
787 ),
788
789 // Safari 412; Max OS X.
790 array(
791 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
792 array(
793 'is_safari' => true,
794 'check_safari_version' => array(
795 '1' => true,
796 '312' => true,
797 ),
798
799 'is_webkit' => true,
800
801 'versionclasses' => array(
802 'safari',
803 ),
804 ),
805 ),
657a94fc 806
7c10ad33
AN
807 // Safari 2.0; Max OS X.
808 array(
809 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
810 array(
811 'is_safari' => true,
812 'check_safari_version' => array(
813 '1' => true,
814 '312' => true,
815 ),
816
817 'is_webkit' => true,
818
819 'versionclasses' => array(
820 'safari',
821 ),
822 ),
823 ),
657a94fc 824
7c10ad33
AN
825 // iOS Safari 528; iPhone.
826 array(
827 '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',
828 array(
829 // Note: We do *not* identify mobile Safari as Safari.
830 'is_safari_ios' => true,
831 'check_safari_ios_version' => array(
832 '527' => true,
833 ),
834
835 'is_webkit' => true,
836
837 'versionclasses' => array(
838 'safari',
839 'ios',
840 ),
841
842 'devicetype' => 'mobile',
843 ),
844 ),
657a94fc 845
5ee4f581
AN
846 // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
847 array(
848 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_10 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4',
849 array(
850 // Note: We do *not* identify mobile Safari as Safari.
851 'is_safari_ios' => true,
852 'check_safari_ios_version' => array(
853 '527' => true,
854 '590' => true,
855 '600' => true,
856 ),
857
858 'is_webkit' => true,
859
860 'versionclasses' => array(
861 'safari',
862 'ios',
863 ),
864
865 'devicetype' => 'mobile',
866 ),
867 ),
868
7c10ad33
AN
869 // iOS Safari 533; iPad.
870 array(
871 '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',
872 array(
873 // Note: We do *not* identify mobile Safari as Safari.
874 'is_safari_ios' => true,
875 'check_safari_ios_version' => array(
876 '527' => true,
877 ),
878
879 'is_webkit' => true,
880
881 'versionclasses' => array(
882 'safari',
883 'ios',
884 ),
885
886 'devicetype' => 'tablet',
887 ),
888 ),
657a94fc 889
7c10ad33
AN
890 // Android WebKit 525; G1 Phone.
891 array(
892 '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',
893 array(
894 'is_webkit_android' => true,
895 'check_webkit_android_version' => array(
896 '525' => true,
897 ),
657a94fc 898
7c10ad33 899 'is_webkit' => true,
657a94fc 900
7c10ad33
AN
901 'versionclasses' => array(
902 'android',
903 'safari',
904 ),
657a94fc 905
7c10ad33 906 'devicetype' => 'mobile',
657a94fc 907
7c10ad33
AN
908 'supports_svg' => false,
909 ),
910 ),
657a94fc 911
7c10ad33
AN
912 // Android WebKit 530; Nexus.
913 array(
914 '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',
915 array(
916 'is_webkit_android' => true,
917 'check_webkit_android_version' => array(
918 '525' => true,
919 '527' => true,
920 ),
657a94fc 921
7c10ad33 922 'is_webkit' => true,
657a94fc 923
7c10ad33
AN
924 'versionclasses' => array(
925 'android',
926 'safari',
927 ),
657a94fc 928
7c10ad33 929 'devicetype' => 'mobile',
657a94fc 930
7c10ad33
AN
931 'supports_svg' => false,
932 ),
933 ),
657a94fc 934
7c10ad33
AN
935 // Android WebKit 537; Samsung GT-9505.
936 array(
937 'Mozilla/5.0 (Linux; Android 4.3; it-it; SAMSUNG GT-I9505/I9505XXUEMJ7 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36',
938 array(
939 'is_webkit_android' => true,
940 'check_webkit_android_version' => array(
941 '525' => true,
942 '527' => true,
943 ),
944
945 'is_webkit' => true,
946
947 'is_chrome' => true,
948 'check_chrome_version' => array(
949 '7' => true,
950 '8' => true,
951 '10' => true,
952 ),
953
954 'versionclasses' => array(
955 'safari',
956 'android',
957 ),
958
959 'devicetype' => 'mobile',
960 ),
961 ),
962
963 // Android WebKit 537; Nexus 5.
964 array(
965 'Mozilla/5.0 (Linux; Android 5.0; Nexus 5 Build/LPX13D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.102 Mobile Safari/537.36',
966 array(
967 'is_webkit_android' => true,
968 'check_webkit_android_version' => array(
969 '525' => true,
970 '527' => true,
971 ),
972
973 'is_webkit' => true,
974
975 'is_chrome' => true,
976 'check_chrome_version' => array(
977 '7' => true,
978 '8' => true,
979 '10' => true,
980 ),
981
982 'versionclasses' => array(
983 'safari',
984 'android',
985 ),
986
987 'devicetype' => 'mobile',
988 ),
989 ),
990
991 // Chrome 8; Mac OS X.
992 array(
993 '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',
994 array(
995 'is_chrome' => true,
996 'check_chrome_version' => array(
997 '7' => true,
998 '8' => true,
999 ),
1000
1001 'is_webkit' => true,
1002
1003 'versionclasses' => array(
1004 'safari',
1005 ),
1006 ),
1007 ),
1008
5ee4f581
AN
1009 // Chrome 39; Mac OS X.
1010 array(
1011 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
1012 array(
1013 'is_chrome' => true,
1014 'check_chrome_version' => array(
1015 '7' => true,
1016 '8' => true,
1017 '10' => true,
1018 '39' => true,
1019 ),
1020
1021 'is_webkit' => true,
1022
1023 'versionclasses' => array(
1024 'safari',
1025 ),
1026 ),
1027 ),
1028
7c10ad33
AN
1029 // Opera 8.51; Windows XP.
1030 array(
1031 'Opera/8.51 (Windows NT 5.1; U; en)',
1032 array(
1033 'is_opera' => true,
1034 'check_opera_version' => array(
1035 '8.0' => true,
1036 ),
1037
1038 'versionclasses' => array(
1039 'opera',
1040 ),
1041
1042 'supports_svg' => false,
1043 ),
1044 ),
657a94fc 1045
7c10ad33
AN
1046 // Opera 9.0; Windows XP.
1047 array(
1048 'Opera/9.0 (Windows NT 5.1; U; en)',
1049 array(
1050 'is_opera' => true,
1051 'check_opera_version' => array(
1052 '8.0' => true,
5ee4f581
AN
1053 '9.0' => true,
1054 ),
1055
1056 'versionclasses' => array(
1057 'opera',
1058 ),
1059
1060 'supports_svg' => false,
1061 ),
1062 ),
1063
1064 // Opera 12.15 (Build 1748); Mac OS X.
1065 array(
1066 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
1067 array(
1068 'is_opera' => true,
1069 'check_opera_version' => array(
1070 '8.0' => true,
1071 '9.0' => true,
1072 '10.0' => true,
1073 '12.15' => true,
7c10ad33
AN
1074 ),
1075
1076 'versionclasses' => array(
1077 'opera',
1078 ),
1079
1080 'supports_svg' => false,
1081 ),
1082 ),
657a94fc 1083
7c10ad33
AN
1084 // Opera 9.0; Debian Linux.
1085 array(
1086 'Opera/9.01 (X11; Linux i686; U; en)',
1087 array(
1088 'is_opera' => true,
1089 'check_opera_version' => array(
1090 '8.0' => true,
5ee4f581 1091 '9.0' => true,
7c10ad33
AN
1092 ),
1093
1094 'versionclasses' => array(
1095 'opera',
1096 ),
1097
1098 'supports_svg' => false,
1099 ),
1100 ),
34c6ec18
AN
1101
1102 // Google web crawlers.
1103 array(
1104 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
1105 array(
1106 'is_web_crawler' => true,
1107 'versionclasses' => array(
1108 ),
1109 ),
1110 ),
1111 array(
1112 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
1113 array(
1114 'is_web_crawler' => true,
1115 'versionclasses' => array(
1116 ),
1117 ),
1118 ),
1119 array(
1120 'Googlebot-Image/1.0',
1121 array(
1122 'is_web_crawler' => true,
1123 'versionclasses' => array(
1124 ),
1125 ),
1126 ),
1127
1128 // Yahoo crawlers.
1129 // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
1130 array(
1131 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
1132 array(
1133 'is_web_crawler' => true,
1134 'versionclasses' => array(
1135 ),
1136 ),
1137 ),
1138
1139 // Bing / MSN / AdIdx crawlers.
1140 // See http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0.
1141 array(
1142 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
1143 array(
1144 'is_web_crawler' => true,
1145 'versionclasses' => array(
1146 ),
1147 ),
1148 ),
1149 array(
1150 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
1151 array(
1152 'is_web_crawler' => true,
1153 'versionclasses' => array(
1154 ),
1155 ),
1156 ),
1157 array(
1158 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
1159 array(
1160 'is_web_crawler' => true,
1161 'is_webkit' => true,
1162 'is_safari_ios' => true,
1163 'check_safari_ios_version' => array(
1164 '527' => true,
1165 ),
1166
1167 'versionclasses' => array(
1168 'safari',
1169 'ios',
1170 ),
1171
1172 'devicetype' => 'mobile',
1173 ),
1174 ),
1175 array(
1176 'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
1177 array(
1178 'is_web_crawler' => true,
1179 'is_ie' => true,
1180 'check_ie_version' => array(
1181 '0' => true,
1182 '5.0' => true,
1183 '5.5' => true,
1184 '6.0' => true,
1185 '7.0' => true,
1186 '8.0' => true,
1187 '9.0' => true,
1188 '10' => true,
1189 '11' => true,
1190 ),
1191 'versionclasses' => array(
1192 'ie',
1193 'ie11',
1194 ),
1195 'devicetype' => 'mobile',
1196 ),
1197 ),
1198
1199 array(
1200 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
1201 array(
1202 'is_web_crawler' => true,
1203 'versionclasses' => array(
1204 ),
1205 ),
1206 ),
1207 array(
1208 'msnbot/2.1',
1209 array(
1210 'is_web_crawler' => true,
1211 'versionclasses' => array(
1212 ),
1213 ),
1214 ),
1215 array(
1216 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
1217 array(
1218 'is_web_crawler' => true,
1219 'versionclasses' => array(
1220 ),
1221 ),
1222 ),
1223 array(
1224 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
1225 array(
1226 'is_web_crawler' => true,
1227 'is_webkit' => true,
1228 'is_safari' => true,
1229 'check_safari_version' => array(
1230 '1' => true,
1231 '312' => true,
1232 '500' => true,
1233 ),
1234
1235 'versionclasses' => array(
1236 'safari',
1237 ),
1238 ),
1239 ),
1240 array(
1241 'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko BingPreview/1.0b',
1242 array(
1243 'is_web_crawler' => true,
1244 'is_ie' => true,
1245 'check_ie_version' => array(
1246 '0' => true,
1247 '5.0' => true,
1248 '5.5' => true,
1249 '6.0' => true,
1250 '7.0' => true,
1251 '8.0' => true,
1252 '9.0' => true,
1253 '10' => true,
1254 '11' => true,
1255 ),
1256 'versionclasses' => array(
1257 'ie',
1258 'ie11',
1259 ),
1260 'devicetype' => 'mobile',
1261 ),
1262 ),
1263
1264 // Yandex.
1265 // See http://help.yandex.com/search/robots/agent.xml.
1266 array(
1267 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
1268 array(
1269 'is_web_crawler' => true,
1270 'versionclasses' => array(
1271 ),
1272 ),
1273 ),
1274 array(
1275 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
1276 array(
1277 'is_web_crawler' => true,
1278 'versionclasses' => array(
1279 ),
1280 ),
1281 ),
1282
1283 // AltaVista.
1284 array(
1285 'AltaVista V2.0B crawler@evreka.com',
1286 array(
1287 'is_web_crawler' => true,
1288 'versionclasses' => array(
1289 ),
1290 ),
1291 ),
1292
1293 // ZoomSpider.
1294 array(
1295 'ZoomSpider - wrensoft.com [ZSEBOT]',
1296 array(
1297 'is_web_crawler' => true,
1298 'versionclasses' => array(
1299 ),
1300 ),
1301 ),
1302
1303 // Baidu.
1304 array(
1305 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
1306 array(
1307 'is_web_crawler' => true,
1308 'versionclasses' => array(
1309 ),
1310 ),
1311 ),
1312 array(
1313 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
1314 array(
1315 'is_web_crawler' => true,
1316 'versionclasses' => array(
1317 ),
1318 ),
1319 ),
1320
1321 // Ask.com.
1322 array(
1323 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
1324 array(
1325 'is_web_crawler' => true,
1326 'versionclasses' => array(
1327 ),
1328 ),
1329 ),
7c10ad33 1330 );
657a94fc
MS
1331 }
1332
c3d2fbf9 1333 /**
7c10ad33 1334 * Test instance generation.
c3d2fbf9 1335 */
7c10ad33
AN
1336 public function test_instance() {
1337 $this->assertInstanceOf('core_useragent', core_useragent::instance());
1338 $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
1339 }
c3d2fbf9 1340
7c10ad33
AN
1341 /**
1342 * @dataProvider user_agents_providers
1343 */
1344 public function test_useragent_ie($useragent, $tests) {
1345 // Setup the core_useragent instance.
1346 core_useragent::instance(true, $useragent);
1347
1348 // IE Tests.
1349 if (isset($tests['is_ie']) && $tests['is_ie']) {
1350 $this->assertTrue(core_useragent::is_ie());
1351 } else {
1352 $this->assertFalse(core_useragent::is_ie());
1353 }
1354
1355 $versions = array(
1356 // New versions of should be added here.
1357 '0' => false,
1358 '5.0' => false,
1359 '5.5' => false,
1360 '6.0' => false,
1361 '7.0' => false,
1362 '8.0' => false,
1363 '9.0' => false,
1364 '10' => false,
1365 '11' => false,
1366 '12' => false,
1367 '13' => false,
1368 '14' => false,
1369 );
1370
1371 if (isset($tests['check_ie_version'])) {
1372 // The test provider has overwritten some of the above checks.
1373 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1374 $versions = $tests['check_ie_version'] + $versions;
1375 }
1376
1377 foreach ($versions as $version => $result) {
1378 $this->assertEquals($result, core_useragent::check_ie_version($version),
1379 "Version incorrectly determined for IE version '{$version}'");
1380 }
1381
1382 // IE Compatibility mode.
1383 if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1384 $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1385 } else {
1386 $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1387 }
c3d2fbf9 1388
7c10ad33 1389 }
c3d2fbf9 1390
7c10ad33
AN
1391 /**
1392 * @dataProvider user_agents_providers
1393 */
1394 public function test_useragent_msword($useragent, $tests) {
1395 // Setup the core_useragent instance.
1396 core_useragent::instance(true, $useragent);
1397
1398 // MSWord Tests.
1399 if (isset($tests['is_msword']) && $tests['is_msword']) {
1400 $this->assertTrue(core_useragent::is_msword());
1401 } else {
1402 $this->assertFalse(core_useragent::is_msword());
1403 }
1404 }
c3d2fbf9 1405
c3d2fbf9 1406
7c10ad33
AN
1407 /**
1408 * @dataProvider user_agents_providers
1409 */
1410 public function test_useragent_supports($useragent, $tests) {
1411 // Setup the core_useragent instance.
1412 core_useragent::instance(true, $useragent);
1413
1414 // Supports SVG.
1415 if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1416 $this->assertTrue(core_useragent::supports_svg(),
1417 "SVG Support was not reported (and should have been)");
1418 } else {
1419 $this->assertFalse(core_useragent::supports_svg(),
1420 "SVG Support was reported (and should not have been)");
1421 }
83af1329
AN
1422
1423 // Supports JSON ContentType.
1424 if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
1425 $this->assertTrue(core_useragent::supports_json_contenttype(),
1426 "JSON ContentType Support was not reported (and should have been)");
1427 } else {
1428 $this->assertFalse(core_useragent::supports_json_contenttype(),
1429 "JSON ContentType Support was reported (and should not have been)");
1430 }
7c10ad33 1431 }
c3d2fbf9 1432
7c10ad33
AN
1433 /**
1434 * @dataProvider user_agents_providers
1435 */
1436 public function test_useragent_webkit($useragent, $tests) {
1437 // Setup the core_useragent instance.
1438 core_useragent::instance(true, $useragent);
1439
1440 if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1441 $this->assertTrue(core_useragent::is_webkit(),
1442 "Browser was not identified as a webkit browser");
1443 $this->assertTrue(core_useragent::check_webkit_version());
1444 } else {
1445 $this->assertFalse(core_useragent::is_webkit(),
1446 "Browser was incorrectly identified as a webkit browser");
1447 $this->assertFalse(core_useragent::check_webkit_version());
1448 }
1449
1450 $versions = array(
1451 // New versions should be added here.
1452 );
1453
1454 if (isset($tests['check_webkit_version'])) {
1455 // The test provider has overwritten some of the above checks.
1456 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1457 $versions = $tests['check_webkit_version'] + $versions;
1458 }
1459
1460 foreach ($versions as $version => $result) {
1461 $this->assertEquals($result, core_useragent::check_webkit_version($version),
1462 "Version incorrectly determined for Webkit version '{$version}'");
1463 }
1464 }
c3d2fbf9 1465
7c10ad33
AN
1466 /**
1467 * @dataProvider user_agents_providers
1468 */
1469 public function test_useragent_webkit_android($useragent, $tests) {
1470 // Setup the core_useragent instance.
1471 core_useragent::instance(true, $useragent);
1472
1473 if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1474 $this->assertTrue(core_useragent::is_webkit_android(),
1475 "Browser was not identified as an Android webkit browser");
1476 $this->assertTrue(core_useragent::check_webkit_android_version());
1477 } else {
1478 $this->assertFalse(core_useragent::is_webkit_android(),
1479 "Browser was incorrectly identified as an Android webkit browser");
1480 $this->assertFalse(core_useragent::check_webkit_android_version());
1481 }
1482
1483 $versions = array(
1484 // New versions should be added here.
1485 '525' => false,
1486 '527' => false,
1487 '590' => false,
1488 );
1489
1490 if (isset($tests['check_webkit_android_version'])) {
1491 // The test provider has overwritten some of the above checks.
1492 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1493 $versions = $tests['check_webkit_android_version'] + $versions;
1494 }
1495
1496 foreach ($versions as $version => $result) {
1497 $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1498 "Version incorrectly determined for Android webkit version '{$version}'");
1499 }
1500 }
c3d2fbf9 1501
7c10ad33
AN
1502 /**
1503 * @dataProvider user_agents_providers
1504 */
1505 public function test_useragent_chrome($useragent, $tests) {
1506 // Setup the core_useragent instance.
1507 core_useragent::instance(true, $useragent);
1508
1509 if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1510 $this->assertTrue(core_useragent::is_chrome(),
1511 "Browser was not identified as a chrome browser");
1512 $this->assertTrue(core_useragent::check_chrome_version());
1513 } else {
1514 $this->assertFalse(core_useragent::is_chrome(),
1515 "Browser was incorrectly identified as a chrome browser");
1516 $this->assertFalse(core_useragent::check_chrome_version());
1517 }
1518
1519 $versions = array(
1520 // New versions should be added here.
1521 '7' => false,
1522 '8' => false,
1523 '10' => false,
5ee4f581 1524 '39' => false,
7c10ad33
AN
1525 );
1526
1527 if (isset($tests['check_chrome_version'])) {
1528 // The test provider has overwritten some of the above checks.
1529 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1530 $versions = $tests['check_chrome_version'] + $versions;
1531 }
1532
1533 foreach ($versions as $version => $result) {
1534 $this->assertEquals($result, core_useragent::check_chrome_version($version),
1535 "Version incorrectly determined for Chrome version '{$version}'");
1536 }
1537 }
c3d2fbf9 1538
7c10ad33
AN
1539 /**
1540 * @dataProvider user_agents_providers
1541 */
1542 public function test_useragent_safari($useragent, $tests) {
1543 // Setup the core_useragent instance.
1544 core_useragent::instance(true, $useragent);
1545
1546 if (isset($tests['is_safari']) && $tests['is_safari']) {
1547 $this->assertTrue(core_useragent::is_safari(),
1548 "Browser was not identified as a safari browser");
1549 $this->assertTrue(core_useragent::check_safari_version());
1550 } else {
1551 $this->assertFalse(core_useragent::is_safari(),
1552 "Browser was incorrectly identified as a safari browser");
1553 $this->assertFalse(core_useragent::check_safari_version());
1554 }
1555
1556 // Check Safari (generic).
1557 $versions = array(
1558 // New versions should be added here.
1559 '1' => false,
1560 '312' => false,
1561 '500' => false,
1562 );
1563
1564 if (isset($tests['check_safari_version'])) {
1565 // The test provider has overwritten some of the above checks.
1566 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1567 $versions = $tests['check_safari_version'] + $versions;
1568 }
1569
1570 foreach ($versions as $version => $result) {
1571 $this->assertEquals($result, core_useragent::check_safari_version($version),
1572 "Version incorrectly determined for Safari (generic) version '{$version}'");
1573 }
1574 }
c3d2fbf9 1575
7c10ad33
AN
1576 /**
1577 * @dataProvider user_agents_providers
1578 */
1579 public function test_useragent_ios_safari($useragent, $tests) {
1580 // Setup the core_useragent instance.
1581 core_useragent::instance(true, $useragent);
1582
1583 if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1584 $this->assertTrue(core_useragent::is_safari_ios(),
1585 "Browser was not identified as an iOS safari browser");
1586 $this->assertTrue(core_useragent::check_safari_ios_version());
1587 } else {
1588 $this->assertFalse(core_useragent::is_safari_ios(),
1589 "Browser was incorrectly identified as an iOS safari browser");
1590 $this->assertFalse(core_useragent::check_safari_ios_version());
1591 }
1592
1593 // Check iOS Safari.
1594 $versions = array(
1595 // New versions should be added here.
1596 '527' => false,
1597 '590' => false,
5ee4f581 1598 '600' => false,
7c10ad33
AN
1599 );
1600
1601 if (isset($tests['check_safari_ios_version'])) {
1602 // The test provider has overwritten some of the above checks.
1603 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1604 $versions = $tests['check_safari_ios_version'] + $versions;
1605 }
1606
1607 foreach ($versions as $version => $result) {
1608 $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1609 "Version incorrectly determined for iOS Safari version '{$version}'");
1610 }
1611 }
1612
1613 /**
1614 * @dataProvider user_agents_providers
1615 */
1616 public function test_useragent_gecko($useragent, $tests) {
1617 // Setup the core_useragent instance.
1618 core_useragent::instance(true, $useragent);
1619
1620 if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1621 $this->assertTrue(core_useragent::is_gecko(),
1622 "Browser was not identified as a gecko browser");
1623 $this->assertTrue(core_useragent::check_gecko_version());
1624 } else {
1625 $this->assertFalse(core_useragent::is_gecko(),
1626 "Browser was incorrectly identified as a gecko browser");
1627 $this->assertFalse(core_useragent::check_gecko_version());
1628 }
1629
1630 $versions = array(
1631 // New versions should be added here.
1632 '1' => false,
1633 '2' => false,
1634 '3.6' => false,
1635 '4.0' => false,
1636 '20030516' => false,
1637 '20051116' => false,
1638 '2006010100' => false,
5ee4f581 1639 '20100101' => false,
7c10ad33
AN
1640 '15.0' => false,
1641 '18.0' => false,
1642 '19.0' => false,
1643 );
1644
1645 if (isset($tests['check_gecko_version'])) {
1646 // The test provider has overwritten some of the above checks.
1647 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1648 $versions = $tests['check_gecko_version'] + $versions;
1649 }
1650
1651 foreach ($versions as $version => $result) {
1652 $this->assertEquals($result, core_useragent::check_gecko_version($version),
1653 "Version incorrectly determined for Gecko version '{$version}'");
1654 }
1655 }
1656
1657 /**
1658 * @dataProvider user_agents_providers
1659 */
1660 public function test_useragent_firefox($useragent, $tests) {
1661 // Setup the core_useragent instance.
1662 core_useragent::instance(true, $useragent);
1663
1664 if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1665 $this->assertTrue(core_useragent::is_firefox(),
1666 "Browser was not identified as a firefox browser");
1667 $this->assertTrue(core_useragent::check_firefox_version());
1668 } else {
1669 $this->assertFalse(core_useragent::is_firefox(),
1670 "Browser was incorrectly identified as a firefox browser");
1671 $this->assertFalse(core_useragent::check_firefox_version());
1672 }
1673
1674 $versions = array(
1675 // New versions should be added here.
1676 '1.5' => false,
1677 '3.0' => false,
1678 '4' => false,
1679 '10' => false,
1680 '15' => false,
1681 '18' => false,
1682 '19' => false,
5ee4f581 1683 '33' => false,
7c10ad33
AN
1684 );
1685
1686 if (isset($tests['check_firefox_version'])) {
1687 // The test provider has overwritten some of the above checks.
1688 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1689 $versions = $tests['check_firefox_version'] + $versions;
1690 }
1691
1692 foreach ($versions as $version => $result) {
1693 $this->assertEquals($result, core_useragent::check_firefox_version($version),
1694 "Version incorrectly determined for Firefox version '{$version}'");
1695 }
1696 }
c3d2fbf9 1697
7c10ad33
AN
1698 /**
1699 * @dataProvider user_agents_providers
1700 */
1701 public function test_useragent_opera($useragent, $tests) {
1702 // Setup the core_useragent instance.
1703 core_useragent::instance(true, $useragent);
1704
1705 if (isset($tests['is_opera']) && $tests['is_opera']) {
1706 $this->assertTrue(core_useragent::is_opera(),
1707 "Browser was not identified as a opera browser");
1708 $this->assertTrue(core_useragent::check_opera_version());
1709 } else {
1710 $this->assertFalse(core_useragent::is_opera(),
1711 "Browser was incorrectly identified as a opera browser");
1712 $this->assertFalse(core_useragent::check_opera_version());
1713 }
1714
1715 $versions = array(
1716 // New versions should be added here.
1717 '8.0' => false,
5ee4f581 1718 '9.0' => false,
7c10ad33 1719 '10.0' => false,
5ee4f581 1720 '12.15' => false,
7c10ad33
AN
1721 );
1722
1723 if (isset($tests['check_opera_version'])) {
1724 // The test provider has overwritten some of the above checks.
1725 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1726 $versions = $tests['check_opera_version'] + $versions;
1727 }
1728
1729 foreach ($versions as $version => $result) {
1730 $this->assertEquals($result, core_useragent::check_opera_version($version),
1731 "Version incorrectly determined for Opera version '{$version}'");
1732 }
1733 }
c3d2fbf9 1734
7c10ad33
AN
1735 /**
1736 * @dataProvider user_agents_providers
1737 */
1738 public function test_get_device_type($useragent, $tests) {
1739 // Setup the core_useragent instance.
1740 core_useragent::instance(true, $useragent);
c3d2fbf9 1741
7c10ad33
AN
1742 $expected = 'default';
1743 if (isset($tests['devicetype'])) {
1744 $expected = $tests['devicetype'];
1745 }
c3d2fbf9 1746
7c10ad33
AN
1747 $this->assertEquals($expected, core_useragent::get_device_type(),
1748 "Device Type was not correctly identified");
c3d2fbf9
SH
1749 }
1750
1751 /**
7c10ad33 1752 * @dataProvider user_agents_providers
c3d2fbf9 1753 */
7c10ad33
AN
1754 public function test_get_browser_version_classes($useragent, $tests) {
1755 // Setup the core_useragent instance.
1756 core_useragent::instance(true, $useragent);
1757
1758 $actual = core_useragent::get_browser_version_classes();
1759 foreach ($tests['versionclasses'] as $expectedclass) {
1760 $this->assertContains($expectedclass, $actual);
1761 }
1762 $this->assertCount(count($tests['versionclasses']), $actual);
c3d2fbf9 1763 }
34c6ec18
AN
1764
1765 /**
1766 * @dataProvider user_agents_providers
1767 */
1768 public function test_useragent_web_crawler($useragent, $tests) {
1769 // Setup the core_useragent instance.
1770 core_useragent::instance(true, $useragent);
1771
1772 $expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
1773 $this->assertSame($expectation, core_useragent::is_web_crawler());
1774 }
378b3eac 1775}