Merge branch 'MDL-49360-28' of git://github.com/lameze/moodle into MOODLE_28_STABLE
[moodle.git] / lib / tests / useragent_test.php
blobb4b230ca2a9ed3064f89e5d8c373efde4fb2a80d
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.
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.
20 * @package core
21 * @copyright 2013 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 /**
26 * User agent test suite.
28 * @package core
29 * @copyright 2013 Sam Hemelryk
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class core_useragent_testcase extends basic_testcase {
34 public function user_agents_providers() {
35 // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list.
36 // This ensures that regression tests are applied to all known user agents.
37 return array(
38 // Windows 98; Internet Explorer 5.0.
39 array(
40 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
41 array(
42 // MSIE 5.0 is not considered a browser at all: known false results.
43 'is_ie' => false,
44 'check_ie_version' => array(
45 '0' => true,
46 '5.0' => true,
48 'versionclasses' => array(
49 // IE 5.0 is not considered a browser.
52 // IE 5.0 is a legacy browser.
53 'devicetype' => 'legacy',
55 'supports_svg' => false,
56 'supports_json_contenttype' => false,
60 // Windows 2000; Internet Explorer 5.5.
61 array(
62 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
63 array(
64 'is_ie' => true,
65 'check_ie_version' => array(
66 '0' => true,
67 '5.0' => true,
68 '5.5' => true,
70 'versionclasses' => array(
71 'ie',
74 // IE 6.0 is a legacy browser.
75 'devicetype' => 'legacy',
77 'supports_svg' => false,
78 'supports_json_contenttype' => false,
82 // Windows XP SP2; Internet Explorer 6.0.
83 array(
84 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
85 array(
86 'is_ie' => true,
87 'check_ie_version' => array(
88 '0' => true,
89 '5.0' => true,
90 '5.5' => true,
91 '6.0' => true,
93 'versionclasses' => array(
94 'ie',
95 'ie6',
98 // IE 7.0 is a legacy browser.
99 'devicetype' => 'legacy',
101 'supports_svg' => false,
102 'supports_json_contenttype' => false,
106 // Windows XP SP2; Internet Explorer 7.0.
107 array(
108 '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)',
109 array(
110 'is_ie' => true,
111 'check_ie_version' => array(
112 '0' => true,
113 '5.0' => true,
114 '5.5' => true,
115 '6.0' => true,
116 '7.0' => true,
118 'versionclasses' => array(
119 'ie',
120 'ie7',
123 'supports_svg' => false,
124 'supports_json_contenttype' => false,
128 // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
129 array(
130 '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)',
131 array(
132 'is_ie' => true,
133 'check_ie_version' => array(
134 '0' => true,
135 '5.0' => true,
136 '5.5' => true,
137 '6.0' => true,
138 '7.0' => true,
140 'versionclasses' => array(
141 'ie',
142 'ie7',
145 'supports_svg' => false,
146 'supports_json_contenttype' => false,
150 // Windows Vista; Internet Explorer 8.0.
151 array(
152 '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)',
153 array(
154 'is_ie' => true,
155 'check_ie_version' => array(
156 '0' => true,
157 '5.0' => true,
158 '5.5' => true,
159 '6.0' => true,
160 '7.0' => true,
161 '8.0' => true,
163 'versionclasses' => array(
164 'ie',
165 'ie8',
168 'supports_svg' => false,
172 // Windows 7; Internet Explorer 9.0.
173 array(
174 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
175 array(
176 'is_ie' => true,
177 'check_ie_version' => array(
178 '0' => true,
179 '5.0' => true,
180 '5.5' => true,
181 '6.0' => true,
182 '7.0' => true,
183 '8.0' => true,
184 '9.0' => true,
186 'versionclasses' => array(
187 'ie',
188 'ie9',
193 // Windows 7; Internet Explorer 9.0i.
194 array(
195 '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)',
196 array(
197 'is_ie' => true,
198 'check_ie_version' => array(
199 '0' => true,
200 '5.0' => true,
201 '5.5' => true,
202 '6.0' => true,
203 '7.0' => true,
204 '8.0' => true,
205 '9.0' => true,
207 'versionclasses' => array(
208 'ie',
209 'ie9',
211 'iecompatibility' => true,
213 // IE 9 in Compatiblity mode does not support SVG.
214 'supports_svg' => false,
216 // IE in Compatiblity mode does not support JSON ContentType.
217 'supports_json_contenttype' => false,
221 // Windows 8; Internet Explorer 10.0.
222 array(
223 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
224 array(
225 'is_ie' => true,
226 'check_ie_version' => array(
227 '0' => true,
228 '5.0' => true,
229 '5.5' => true,
230 '6.0' => true,
231 '7.0' => true,
232 '8.0' => true,
233 '9.0' => true,
234 '10' => true,
236 'versionclasses' => array(
237 'ie',
238 'ie10',
243 // Windows 8; Internet Explorer 10.0i.
244 array(
245 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
246 array(
247 'is_ie' => true,
248 'check_ie_version' => array(
249 '0' => true,
250 '5.0' => true,
251 '5.5' => true,
252 '6.0' => true,
253 '7.0' => true,
254 '8.0' => true,
255 '9.0' => true,
256 '10' => true,
258 'iecompatibility' => true,
259 'versionclasses' => array(
260 'ie',
261 'ie10',
264 // IE in Compatiblity mode does not support JSON ContentType.
265 'supports_json_contenttype' => false,
269 // Windows 8.1; Internet Explorer 11.0.
270 array(
271 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
272 array(
273 'is_ie' => true,
274 'check_ie_version' => array(
275 '0' => true,
276 '5.0' => true,
277 '5.5' => true,
278 '6.0' => true,
279 '7.0' => true,
280 '8.0' => true,
281 '9.0' => true,
282 '10' => true,
283 '11' => true,
285 'versionclasses' => array(
286 'ie',
287 'ie11',
292 // Windows 8.1; Internet Explorer 11.0i.
293 array(
294 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
295 array(
296 'is_ie' => true,
297 'check_ie_version' => array(
298 '0' => true,
299 '5.0' => true,
300 '5.5' => true,
301 '6.0' => true,
302 '7.0' => true,
303 '8.0' => true,
304 '9.0' => true,
305 '10' => true,
306 '11' => true,
308 'iecompatibility' => true,
309 'versionclasses' => array(
310 'ie',
311 'ie11',
314 // IE in Compatiblity mode does not support JSON ContentType.
315 'supports_json_contenttype' => false,
319 // Windows XP; Firefox 1.0.6.
320 array(
321 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
322 array(
323 'is_firefox' => true,
325 'is_gecko' => true,
326 'check_gecko_version' => array(
327 '1' => true,
330 'versionclasses' => array(
331 'gecko',
332 'gecko17',
337 // Windows XP; Firefox 1.0.6.
338 array(
339 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
340 array(
341 'is_firefox' => true,
342 'check_firefox_version' => array(
343 '1.5' => true,
346 'is_gecko' => true,
347 'check_gecko_version' => array(
348 '1' => true,
349 '20030516' => true,
350 '20051116' => true,
353 'versionclasses' => array(
354 'gecko',
355 'gecko18',
360 // Windows XP; Firefox 1.5.0.1.
361 array(
362 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
363 array(
364 'is_firefox' => true,
365 'check_firefox_version' => array(
366 '1.5' => true,
369 'is_gecko' => true,
370 'check_gecko_version' => array(
371 '1' => true,
372 '20030516' => true,
373 '20051116' => true,
376 'versionclasses' => array(
377 'gecko',
378 'gecko18',
383 // Windows XP; Firefox 2.0.
384 array(
385 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
386 array(
387 'is_firefox' => true,
388 'check_firefox_version' => array(
389 '1.5' => true,
392 'is_gecko' => true,
393 'check_gecko_version' => array(
394 '1' => true,
395 '2' => true,
396 '20030516' => true,
397 '20051116' => true,
398 '2006010100' => true,
401 'versionclasses' => array(
402 'gecko',
403 'gecko18',
408 // Ubuntu Linux amd64; Firefox 2.0.
409 array(
410 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
411 array(
412 'is_firefox' => true,
413 'check_firefox_version' => array(
414 '1.5' => true,
417 'is_gecko' => true,
418 'check_gecko_version' => array(
419 '1' => true,
420 '2' => true,
421 '20030516' => true,
422 '20051116' => true,
423 '2006010100' => true,
426 'versionclasses' => array(
427 'gecko',
428 'gecko18',
433 // SUSE; Firefox 3.0.6.
434 array(
435 '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',
436 array(
437 'is_firefox' => true,
438 'check_firefox_version' => array(
439 '1.5' => true,
440 '3.0' => true,
443 'is_gecko' => true,
444 'check_gecko_version' => array(
445 '1' => true,
446 '2' => true,
447 '20030516' => true,
448 '20051116' => true,
449 '2006010100' => true,
452 'versionclasses' => array(
453 'gecko',
454 'gecko19',
459 // Linux i686; Firefox 3.6.
460 array(
461 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
462 array(
463 'is_firefox' => true,
464 'check_firefox_version' => array(
465 '1.5' => true,
466 '3.0' => true,
469 'is_gecko' => true,
470 'check_gecko_version' => array(
471 '1' => true,
472 '2' => true,
473 '20030516' => true,
474 '20051116' => true,
475 '2006010100' => true,
476 '3.6' => true,
477 '20100101' => true,
480 'versionclasses' => array(
481 'gecko',
482 'gecko20',
487 // Windows; Firefox 11.0.
488 array(
489 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
490 array(
491 'is_firefox' => true,
492 'check_firefox_version' => array(
493 '1.5' => true,
494 '3.0' => true,
495 '4' => true,
496 '10' => true,
499 'is_gecko' => true,
500 'check_gecko_version' => array(
501 '1' => true,
502 '2' => true,
503 '20030516' => true,
504 '20051116' => true,
505 '2006010100' => true,
506 '20100101' => true,
507 '3.6' => true,
508 '4.0' => true,
511 'versionclasses' => array(
512 'gecko',
517 // Windows; Firefox 15.0a2.
518 array(
519 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
520 array(
521 'is_firefox' => true,
522 'check_firefox_version' => array(
523 '1.5' => true,
524 '3.0' => true,
525 '4' => true,
526 '10' => true,
527 '15' => true,
530 'is_gecko' => true,
531 'check_gecko_version' => array(
532 '1' => true,
533 '2' => true,
534 '20030516' => true,
535 '20051116' => true,
536 '2006010100' => true,
537 '20100101' => true,
538 '3.6' => true,
539 '4.0' => true,
540 '15.0' => true,
543 'versionclasses' => array(
544 'gecko',
549 // Firefox 18; Mac OS X 10.
550 array(
551 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
552 array(
553 'is_firefox' => true,
554 'check_firefox_version' => array(
555 '1.5' => true,
556 '3.0' => true,
557 '4' => true,
558 '10' => true,
559 '15' => true,
560 '18' => true,
563 'is_gecko' => true,
564 'check_gecko_version' => array(
565 '1' => true,
566 '2' => true,
567 '20030516' => true,
568 '20051116' => true,
569 '2006010100' => true,
570 '3.6' => true,
571 '4.0' => true,
572 '15.0' => true,
573 '18.0' => true,
574 '20100101' => true,
577 'versionclasses' => array(
578 'gecko',
583 // Firefox 33; Mac OS X 10.10.
584 array(
585 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
586 array(
587 'is_firefox' => true,
588 'check_firefox_version' => array(
589 '1.5' => true,
590 '3.0' => true,
591 '4' => true,
592 '10' => true,
593 '15' => true,
594 '18' => true,
595 '19' => true,
596 '33' => true,
599 'is_gecko' => true,
600 'check_gecko_version' => array(
601 '1' => true,
602 '2' => true,
603 '20030516' => true,
604 '20051116' => true,
605 '2006010100' => true,
606 '3.6' => true,
607 '4.0' => true,
608 '15.0' => true,
609 '18.0' => true,
610 '19.0' => true,
611 '20100101' => true,
614 'versionclasses' => array(
615 'gecko',
620 // SeaMonkey 2.0; Windows.
621 array(
622 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
623 array(
624 'is_gecko' => true,
625 'check_gecko_version' => array(
626 '1' => true,
627 '2' => true,
628 '20030516' => true,
629 '20051106' => true,
630 '20051116' => true,
631 '2006010100' => true,
634 'versionclasses' => array(
635 'gecko',
636 'gecko19',
641 // SeaMonkey 2.1; Linux.
642 array(
643 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
644 array(
645 'is_gecko' => true,
646 'check_gecko_version' => array(
647 '1' => true,
648 '2' => true,
649 '20030516' => true,
650 '20051116' => true,
651 '2006010100' => true,
652 '20100101' => true,
653 '3.6' => true,
654 '4.0' => true,
657 'is_firefox' => true,
658 'check_firefox_version' => array(
659 '1.5' => true,
660 '3.0' => true,
661 '4' => true,
664 'versionclasses' => array(
665 'gecko',
666 'gecko20',
671 // SeaMonkey 2.3; FreeBSD.
672 array(
673 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
674 array(
675 'is_gecko' => true,
676 'check_gecko_version' => array(
677 '1' => true,
678 '2' => true,
679 '20030516' => true,
680 '20051116' => true,
681 '2006010100' => true,
682 '20100101' => true,
683 '3.6' => true,
684 '4.0' => true,
687 'is_firefox' => true,
688 'check_firefox_version' => array(
689 '1.5' => true,
690 '3.0' => true,
691 '4' => true,
694 'versionclasses' => array(
695 'gecko',
700 // Windows 7; MS Word 2010.
701 array(
702 '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)',
703 array(
704 'is_ie' => true,
705 'check_ie_version' => array(
706 '0' => true,
707 '5.0' => true,
708 '5.5' => true,
709 '6.0' => true,
710 '7.0' => true,
711 '8.0' => true,
713 'iecompatibility' => true,
714 'versionclasses' => array(
715 'ie',
716 'ie8',
719 'is_msword' => true,
721 'supports_svg' => false,
722 'supports_json_contenttype' => false,
726 // Windows 7; MS Outlook 2010.
727 array(
728 '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)',
729 array(
730 'is_ie' => true,
731 'check_ie_version' => array(
732 '0' => true,
733 '5.0' => true,
734 '5.5' => true,
735 '6.0' => true,
736 '7.0' => true,
737 '8.0' => true,
739 'iecompatibility' => true,
740 'versionclasses' => array(
741 'ie',
742 'ie8',
745 // Note: Outlook is deliberately not considered to be MS Word.
746 'is_msword' => false,
748 'supports_svg' => false,
749 'supports_json_contenttype' => false,
753 // Mac OS X; MS Word 14.
754 array(
755 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
756 array(
757 'versionclasses' => array(
760 'is_msword' => true,
764 // Safari 312; Max OS X.
765 array(
766 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
767 array(
768 'is_safari' => true,
769 'check_safari_version' => array(
770 '1' => true,
771 '312' => true,
774 'is_webkit' => true,
776 'versionclasses' => array(
777 'safari',
782 // Safari 412; Max OS X.
783 array(
784 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
785 array(
786 'is_safari' => true,
787 'check_safari_version' => array(
788 '1' => true,
789 '312' => true,
792 'is_webkit' => true,
794 'versionclasses' => array(
795 'safari',
800 // Safari 2.0; Max OS X.
801 array(
802 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
803 array(
804 'is_safari' => true,
805 'check_safari_version' => array(
806 '1' => true,
807 '312' => true,
810 'is_webkit' => true,
812 'versionclasses' => array(
813 'safari',
818 // iOS Safari 528; iPhone.
819 array(
820 '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',
821 array(
822 // Note: We do *not* identify mobile Safari as Safari.
823 'is_safari_ios' => true,
824 'check_safari_ios_version' => array(
825 '527' => true,
828 'is_webkit' => true,
830 'versionclasses' => array(
831 'safari',
832 'ios',
835 'devicetype' => 'mobile',
839 // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
840 array(
841 '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',
842 array(
843 // Note: We do *not* identify mobile Safari as Safari.
844 'is_safari_ios' => true,
845 'check_safari_ios_version' => array(
846 '527' => true,
847 '590' => true,
848 '600' => true,
851 'is_webkit' => true,
853 'versionclasses' => array(
854 'safari',
855 'ios',
858 'devicetype' => 'mobile',
862 // iOS Safari 533; iPad.
863 array(
864 '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',
865 array(
866 // Note: We do *not* identify mobile Safari as Safari.
867 'is_safari_ios' => true,
868 'check_safari_ios_version' => array(
869 '527' => true,
872 'is_webkit' => true,
874 'versionclasses' => array(
875 'safari',
876 'ios',
879 'devicetype' => 'tablet',
883 // Android WebKit 525; G1 Phone.
884 array(
885 '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',
886 array(
887 'is_webkit_android' => true,
888 'check_webkit_android_version' => array(
889 '525' => true,
892 'is_webkit' => true,
894 'versionclasses' => array(
895 'android',
896 'safari',
899 'devicetype' => 'mobile',
901 'supports_svg' => false,
905 // Android WebKit 530; Nexus.
906 array(
907 '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',
908 array(
909 'is_webkit_android' => true,
910 'check_webkit_android_version' => array(
911 '525' => true,
912 '527' => true,
915 'is_webkit' => true,
917 'versionclasses' => array(
918 'android',
919 'safari',
922 'devicetype' => 'mobile',
924 'supports_svg' => false,
928 // Android WebKit 537; Samsung GT-9505.
929 array(
930 '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',
931 array(
932 'is_webkit_android' => true,
933 'check_webkit_android_version' => array(
934 '525' => true,
935 '527' => true,
938 'is_webkit' => true,
940 'is_chrome' => true,
941 'check_chrome_version' => array(
942 '7' => true,
943 '8' => true,
944 '10' => true,
947 'versionclasses' => array(
948 'safari',
949 'android',
952 'devicetype' => 'mobile',
956 // Android WebKit 537; Nexus 5.
957 array(
958 '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',
959 array(
960 'is_webkit_android' => true,
961 'check_webkit_android_version' => array(
962 '525' => true,
963 '527' => true,
966 'is_webkit' => true,
968 'is_chrome' => true,
969 'check_chrome_version' => array(
970 '7' => true,
971 '8' => true,
972 '10' => true,
975 'versionclasses' => array(
976 'safari',
977 'android',
980 'devicetype' => 'mobile',
984 // Chrome 8; Mac OS X.
985 array(
986 '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',
987 array(
988 'is_chrome' => true,
989 'check_chrome_version' => array(
990 '7' => true,
991 '8' => true,
994 'is_webkit' => true,
996 'versionclasses' => array(
997 'safari',
1002 // Chrome 39; Mac OS X.
1003 array(
1004 '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',
1005 array(
1006 'is_chrome' => true,
1007 'check_chrome_version' => array(
1008 '7' => true,
1009 '8' => true,
1010 '10' => true,
1011 '39' => true,
1014 'is_webkit' => true,
1016 'versionclasses' => array(
1017 'safari',
1022 // Opera 8.51; Windows XP.
1023 array(
1024 'Opera/8.51 (Windows NT 5.1; U; en)',
1025 array(
1026 'is_opera' => true,
1027 'check_opera_version' => array(
1028 '8.0' => true,
1031 'versionclasses' => array(
1032 'opera',
1035 'supports_svg' => false,
1039 // Opera 9.0; Windows XP.
1040 array(
1041 'Opera/9.0 (Windows NT 5.1; U; en)',
1042 array(
1043 'is_opera' => true,
1044 'check_opera_version' => array(
1045 '8.0' => true,
1046 '9.0' => true,
1049 'versionclasses' => array(
1050 'opera',
1053 'supports_svg' => false,
1057 // Opera 12.15 (Build 1748); Mac OS X.
1058 array(
1059 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
1060 array(
1061 'is_opera' => true,
1062 'check_opera_version' => array(
1063 '8.0' => true,
1064 '9.0' => true,
1065 '10.0' => true,
1066 '12.15' => true,
1069 'versionclasses' => array(
1070 'opera',
1073 'supports_svg' => false,
1077 // Opera 9.0; Debian Linux.
1078 array(
1079 'Opera/9.01 (X11; Linux i686; U; en)',
1080 array(
1081 'is_opera' => true,
1082 'check_opera_version' => array(
1083 '8.0' => true,
1084 '9.0' => true,
1087 'versionclasses' => array(
1088 'opera',
1091 'supports_svg' => false,
1098 * Test instance generation.
1100 public function test_instance() {
1101 $this->assertInstanceOf('core_useragent', core_useragent::instance());
1102 $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
1106 * @dataProvider user_agents_providers
1108 public function test_useragent_ie($useragent, $tests) {
1109 // Setup the core_useragent instance.
1110 core_useragent::instance(true, $useragent);
1112 // IE Tests.
1113 if (isset($tests['is_ie']) && $tests['is_ie']) {
1114 $this->assertTrue(core_useragent::is_ie());
1115 } else {
1116 $this->assertFalse(core_useragent::is_ie());
1119 $versions = array(
1120 // New versions of should be added here.
1121 '0' => false,
1122 '5.0' => false,
1123 '5.5' => false,
1124 '6.0' => false,
1125 '7.0' => false,
1126 '8.0' => false,
1127 '9.0' => false,
1128 '10' => false,
1129 '11' => false,
1130 '12' => false,
1131 '13' => false,
1132 '14' => false,
1135 if (isset($tests['check_ie_version'])) {
1136 // The test provider has overwritten some of the above checks.
1137 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1138 $versions = $tests['check_ie_version'] + $versions;
1141 foreach ($versions as $version => $result) {
1142 $this->assertEquals($result, core_useragent::check_ie_version($version),
1143 "Version incorrectly determined for IE version '{$version}'");
1146 // IE Compatibility mode.
1147 if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1148 $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1149 } else {
1150 $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1156 * @dataProvider user_agents_providers
1158 public function test_useragent_msword($useragent, $tests) {
1159 // Setup the core_useragent instance.
1160 core_useragent::instance(true, $useragent);
1162 // MSWord Tests.
1163 if (isset($tests['is_msword']) && $tests['is_msword']) {
1164 $this->assertTrue(core_useragent::is_msword());
1165 } else {
1166 $this->assertFalse(core_useragent::is_msword());
1172 * @dataProvider user_agents_providers
1174 public function test_useragent_supports($useragent, $tests) {
1175 // Setup the core_useragent instance.
1176 core_useragent::instance(true, $useragent);
1178 // Supports SVG.
1179 if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1180 $this->assertTrue(core_useragent::supports_svg(),
1181 "SVG Support was not reported (and should have been)");
1182 } else {
1183 $this->assertFalse(core_useragent::supports_svg(),
1184 "SVG Support was reported (and should not have been)");
1187 // Supports JSON ContentType.
1188 if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
1189 $this->assertTrue(core_useragent::supports_json_contenttype(),
1190 "JSON ContentType Support was not reported (and should have been)");
1191 } else {
1192 $this->assertFalse(core_useragent::supports_json_contenttype(),
1193 "JSON ContentType Support was reported (and should not have been)");
1198 * @dataProvider user_agents_providers
1200 public function test_useragent_webkit($useragent, $tests) {
1201 // Setup the core_useragent instance.
1202 core_useragent::instance(true, $useragent);
1204 if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1205 $this->assertTrue(core_useragent::is_webkit(),
1206 "Browser was not identified as a webkit browser");
1207 $this->assertTrue(core_useragent::check_webkit_version());
1208 } else {
1209 $this->assertFalse(core_useragent::is_webkit(),
1210 "Browser was incorrectly identified as a webkit browser");
1211 $this->assertFalse(core_useragent::check_webkit_version());
1214 $versions = array(
1215 // New versions should be added here.
1218 if (isset($tests['check_webkit_version'])) {
1219 // The test provider has overwritten some of the above checks.
1220 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1221 $versions = $tests['check_webkit_version'] + $versions;
1224 foreach ($versions as $version => $result) {
1225 $this->assertEquals($result, core_useragent::check_webkit_version($version),
1226 "Version incorrectly determined for Webkit version '{$version}'");
1231 * @dataProvider user_agents_providers
1233 public function test_useragent_webkit_android($useragent, $tests) {
1234 // Setup the core_useragent instance.
1235 core_useragent::instance(true, $useragent);
1237 if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1238 $this->assertTrue(core_useragent::is_webkit_android(),
1239 "Browser was not identified as an Android webkit browser");
1240 $this->assertTrue(core_useragent::check_webkit_android_version());
1241 } else {
1242 $this->assertFalse(core_useragent::is_webkit_android(),
1243 "Browser was incorrectly identified as an Android webkit browser");
1244 $this->assertFalse(core_useragent::check_webkit_android_version());
1247 $versions = array(
1248 // New versions should be added here.
1249 '525' => false,
1250 '527' => false,
1251 '590' => false,
1254 if (isset($tests['check_webkit_android_version'])) {
1255 // The test provider has overwritten some of the above checks.
1256 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1257 $versions = $tests['check_webkit_android_version'] + $versions;
1260 foreach ($versions as $version => $result) {
1261 $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1262 "Version incorrectly determined for Android webkit version '{$version}'");
1267 * @dataProvider user_agents_providers
1269 public function test_useragent_chrome($useragent, $tests) {
1270 // Setup the core_useragent instance.
1271 core_useragent::instance(true, $useragent);
1273 if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1274 $this->assertTrue(core_useragent::is_chrome(),
1275 "Browser was not identified as a chrome browser");
1276 $this->assertTrue(core_useragent::check_chrome_version());
1277 } else {
1278 $this->assertFalse(core_useragent::is_chrome(),
1279 "Browser was incorrectly identified as a chrome browser");
1280 $this->assertFalse(core_useragent::check_chrome_version());
1283 $versions = array(
1284 // New versions should be added here.
1285 '7' => false,
1286 '8' => false,
1287 '10' => false,
1288 '39' => false,
1291 if (isset($tests['check_chrome_version'])) {
1292 // The test provider has overwritten some of the above checks.
1293 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1294 $versions = $tests['check_chrome_version'] + $versions;
1297 foreach ($versions as $version => $result) {
1298 $this->assertEquals($result, core_useragent::check_chrome_version($version),
1299 "Version incorrectly determined for Chrome version '{$version}'");
1304 * @dataProvider user_agents_providers
1306 public function test_useragent_safari($useragent, $tests) {
1307 // Setup the core_useragent instance.
1308 core_useragent::instance(true, $useragent);
1310 if (isset($tests['is_safari']) && $tests['is_safari']) {
1311 $this->assertTrue(core_useragent::is_safari(),
1312 "Browser was not identified as a safari browser");
1313 $this->assertTrue(core_useragent::check_safari_version());
1314 } else {
1315 $this->assertFalse(core_useragent::is_safari(),
1316 "Browser was incorrectly identified as a safari browser");
1317 $this->assertFalse(core_useragent::check_safari_version());
1320 // Check Safari (generic).
1321 $versions = array(
1322 // New versions should be added here.
1323 '1' => false,
1324 '312' => false,
1325 '500' => false,
1328 if (isset($tests['check_safari_version'])) {
1329 // The test provider has overwritten some of the above checks.
1330 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1331 $versions = $tests['check_safari_version'] + $versions;
1334 foreach ($versions as $version => $result) {
1335 $this->assertEquals($result, core_useragent::check_safari_version($version),
1336 "Version incorrectly determined for Safari (generic) version '{$version}'");
1341 * @dataProvider user_agents_providers
1343 public function test_useragent_ios_safari($useragent, $tests) {
1344 // Setup the core_useragent instance.
1345 core_useragent::instance(true, $useragent);
1347 if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1348 $this->assertTrue(core_useragent::is_safari_ios(),
1349 "Browser was not identified as an iOS safari browser");
1350 $this->assertTrue(core_useragent::check_safari_ios_version());
1351 } else {
1352 $this->assertFalse(core_useragent::is_safari_ios(),
1353 "Browser was incorrectly identified as an iOS safari browser");
1354 $this->assertFalse(core_useragent::check_safari_ios_version());
1357 // Check iOS Safari.
1358 $versions = array(
1359 // New versions should be added here.
1360 '527' => false,
1361 '590' => false,
1362 '600' => false,
1365 if (isset($tests['check_safari_ios_version'])) {
1366 // The test provider has overwritten some of the above checks.
1367 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1368 $versions = $tests['check_safari_ios_version'] + $versions;
1371 foreach ($versions as $version => $result) {
1372 $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1373 "Version incorrectly determined for iOS Safari version '{$version}'");
1378 * @dataProvider user_agents_providers
1380 public function test_useragent_gecko($useragent, $tests) {
1381 // Setup the core_useragent instance.
1382 core_useragent::instance(true, $useragent);
1384 if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1385 $this->assertTrue(core_useragent::is_gecko(),
1386 "Browser was not identified as a gecko browser");
1387 $this->assertTrue(core_useragent::check_gecko_version());
1388 } else {
1389 $this->assertFalse(core_useragent::is_gecko(),
1390 "Browser was incorrectly identified as a gecko browser");
1391 $this->assertFalse(core_useragent::check_gecko_version());
1394 $versions = array(
1395 // New versions should be added here.
1396 '1' => false,
1397 '2' => false,
1398 '3.6' => false,
1399 '4.0' => false,
1400 '20030516' => false,
1401 '20051116' => false,
1402 '2006010100' => false,
1403 '20100101' => false,
1404 '15.0' => false,
1405 '18.0' => false,
1406 '19.0' => false,
1409 if (isset($tests['check_gecko_version'])) {
1410 // The test provider has overwritten some of the above checks.
1411 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1412 $versions = $tests['check_gecko_version'] + $versions;
1415 foreach ($versions as $version => $result) {
1416 $this->assertEquals($result, core_useragent::check_gecko_version($version),
1417 "Version incorrectly determined for Gecko version '{$version}'");
1422 * @dataProvider user_agents_providers
1424 public function test_useragent_firefox($useragent, $tests) {
1425 // Setup the core_useragent instance.
1426 core_useragent::instance(true, $useragent);
1428 if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1429 $this->assertTrue(core_useragent::is_firefox(),
1430 "Browser was not identified as a firefox browser");
1431 $this->assertTrue(core_useragent::check_firefox_version());
1432 } else {
1433 $this->assertFalse(core_useragent::is_firefox(),
1434 "Browser was incorrectly identified as a firefox browser");
1435 $this->assertFalse(core_useragent::check_firefox_version());
1438 $versions = array(
1439 // New versions should be added here.
1440 '1.5' => false,
1441 '3.0' => false,
1442 '4' => false,
1443 '10' => false,
1444 '15' => false,
1445 '18' => false,
1446 '19' => false,
1447 '33' => false,
1450 if (isset($tests['check_firefox_version'])) {
1451 // The test provider has overwritten some of the above checks.
1452 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1453 $versions = $tests['check_firefox_version'] + $versions;
1456 foreach ($versions as $version => $result) {
1457 $this->assertEquals($result, core_useragent::check_firefox_version($version),
1458 "Version incorrectly determined for Firefox version '{$version}'");
1463 * @dataProvider user_agents_providers
1465 public function test_useragent_opera($useragent, $tests) {
1466 // Setup the core_useragent instance.
1467 core_useragent::instance(true, $useragent);
1469 if (isset($tests['is_opera']) && $tests['is_opera']) {
1470 $this->assertTrue(core_useragent::is_opera(),
1471 "Browser was not identified as a opera browser");
1472 $this->assertTrue(core_useragent::check_opera_version());
1473 } else {
1474 $this->assertFalse(core_useragent::is_opera(),
1475 "Browser was incorrectly identified as a opera browser");
1476 $this->assertFalse(core_useragent::check_opera_version());
1479 $versions = array(
1480 // New versions should be added here.
1481 '8.0' => false,
1482 '9.0' => false,
1483 '10.0' => false,
1484 '12.15' => false,
1487 if (isset($tests['check_opera_version'])) {
1488 // The test provider has overwritten some of the above checks.
1489 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1490 $versions = $tests['check_opera_version'] + $versions;
1493 foreach ($versions as $version => $result) {
1494 $this->assertEquals($result, core_useragent::check_opera_version($version),
1495 "Version incorrectly determined for Opera version '{$version}'");
1500 * @dataProvider user_agents_providers
1502 public function test_get_device_type($useragent, $tests) {
1503 // Setup the core_useragent instance.
1504 core_useragent::instance(true, $useragent);
1506 $expected = 'default';
1507 if (isset($tests['devicetype'])) {
1508 $expected = $tests['devicetype'];
1511 $this->assertEquals($expected, core_useragent::get_device_type(),
1512 "Device Type was not correctly identified");
1516 * @dataProvider user_agents_providers
1518 public function test_get_browser_version_classes($useragent, $tests) {
1519 // Setup the core_useragent instance.
1520 core_useragent::instance(true, $useragent);
1522 $actual = core_useragent::get_browser_version_classes();
1523 foreach ($tests['versionclasses'] as $expectedclass) {
1524 $this->assertContains($expectedclass, $actual);
1526 $this->assertCount(count($tests['versionclasses']), $actual);