MDL-80203 courseformat: Fix some typos and PHPDoc
[moodle.git] / lib / tests / useragent_test.php
blob308fafd29248bb2f502c5967f388081329028012
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 * User agent test suite.
20 * @package core
21 * @copyright 2013 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @covers \core_useragent
25 class useragent_test extends advanced_testcase {
27 /**
28 * Restores the user agent to the default one.
30 public function tearDown(): void {
31 core_useragent::instance(true);
34 /**
35 * Data provider for known user agents.
37 * @return array
39 public function user_agents_providers() {
40 // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list.
41 // This ensures that regression tests are applied to all known user agents.
42 return array(
43 'Microsoft Edge for Windows 10 Desktop' => array(
44 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136',
45 array(
46 'is_edge' => true,
47 'check_edge_version' => array(
48 '12' => true,
51 // Edge pretends to be WebKit.
52 'is_webkit' => true,
54 // Edge pretends to be Chrome.
55 // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
56 'is_chrome' => true,
57 'check_chrome_version' => array(
58 '7' => true,
59 '8' => true,
60 '10' => true,
61 '39' => true,
64 'versionclasses' => array(
65 'edge',
69 'Microsoft Edge for Windows 10 Mobile' => array(
70 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10136',
71 array(
72 'is_edge' => true,
73 'check_edge_version' => array(
74 '12' => true,
77 // Edge pretends to be WebKit.
78 'is_webkit' => true,
80 // Mobile Edge pretends to be Android.
81 'is_webkit_android' => true,
82 'check_webkit_android_version' => array(
83 '525' => true,
84 '527' => true,
87 // Edge pretends to be Chrome.
88 // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
89 'is_chrome' => true,
90 'check_chrome_version' => array(
91 '7' => true,
92 '8' => true,
93 '10' => true,
94 '39' => true,
97 'versionclasses' => array(
98 'edge'
101 'devicetype' => 'mobile',
105 // Windows XP; Firefox 1.0.6.
106 array(
107 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
108 array(
109 'is_firefox' => true,
111 'is_gecko' => true,
112 'check_gecko_version' => array(
113 '1' => true,
116 'versionclasses' => array(
117 'gecko',
118 'gecko17',
123 // Windows XP; Firefox 1.0.6.
124 array(
125 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
126 array(
127 'is_firefox' => true,
128 'check_firefox_version' => array(
129 '1.5' => true,
132 'is_gecko' => true,
133 'check_gecko_version' => array(
134 '1' => true,
135 '20030516' => true,
136 '20051116' => true,
139 'versionclasses' => array(
140 'gecko',
141 'gecko18',
146 // Windows XP; Firefox 1.5.0.1.
147 array(
148 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
149 array(
150 'is_firefox' => true,
151 'check_firefox_version' => array(
152 '1.5' => true,
155 'is_gecko' => true,
156 'check_gecko_version' => array(
157 '1' => true,
158 '20030516' => true,
159 '20051116' => true,
162 'versionclasses' => array(
163 'gecko',
164 'gecko18',
169 // Windows XP; Firefox 2.0.
170 array(
171 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
172 array(
173 'is_firefox' => true,
174 'check_firefox_version' => array(
175 '1.5' => true,
178 'is_gecko' => true,
179 'check_gecko_version' => array(
180 '1' => true,
181 '2' => true,
182 '20030516' => true,
183 '20051116' => true,
184 '2006010100' => true,
187 'versionclasses' => array(
188 'gecko',
189 'gecko18',
194 // Ubuntu Linux amd64; Firefox 2.0.
195 array(
196 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
197 array(
198 'is_firefox' => true,
199 'check_firefox_version' => array(
200 '1.5' => true,
203 'is_gecko' => true,
204 'check_gecko_version' => array(
205 '1' => true,
206 '2' => true,
207 '20030516' => true,
208 '20051116' => true,
209 '2006010100' => true,
212 'versionclasses' => array(
213 'gecko',
214 'gecko18',
219 // SUSE; Firefox 3.0.6.
220 array(
221 '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',
222 array(
223 'is_firefox' => true,
224 'check_firefox_version' => array(
225 '1.5' => true,
226 '3.0' => true,
229 'is_gecko' => true,
230 'check_gecko_version' => array(
231 '1' => true,
232 '2' => true,
233 '20030516' => true,
234 '20051116' => true,
235 '2006010100' => true,
238 'versionclasses' => array(
239 'gecko',
240 'gecko19',
245 // Linux i686; Firefox 3.6.
246 array(
247 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
248 array(
249 'is_firefox' => true,
250 'check_firefox_version' => array(
251 '1.5' => true,
252 '3.0' => true,
255 'is_gecko' => true,
256 'check_gecko_version' => array(
257 '1' => true,
258 '2' => true,
259 '20030516' => true,
260 '20051116' => true,
261 '2006010100' => true,
262 '3.6' => true,
263 '20100101' => true,
266 'versionclasses' => array(
267 'gecko',
268 'gecko20',
273 // Windows; Firefox 11.0.
274 array(
275 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
276 array(
277 'is_firefox' => true,
278 'check_firefox_version' => array(
279 '1.5' => true,
280 '3.0' => true,
281 '4' => true,
282 '10' => true,
285 'is_gecko' => true,
286 'check_gecko_version' => array(
287 '1' => true,
288 '2' => true,
289 '20030516' => true,
290 '20051116' => true,
291 '2006010100' => true,
292 '20100101' => true,
293 '3.6' => true,
294 '4.0' => true,
297 'versionclasses' => array(
298 'gecko',
303 // Windows; Firefox 15.0a2.
304 array(
305 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
306 array(
307 'is_firefox' => true,
308 'check_firefox_version' => array(
309 '1.5' => true,
310 '3.0' => true,
311 '4' => true,
312 '10' => true,
313 '15' => true,
316 'is_gecko' => true,
317 'check_gecko_version' => array(
318 '1' => true,
319 '2' => true,
320 '20030516' => true,
321 '20051116' => true,
322 '2006010100' => true,
323 '20100101' => true,
324 '3.6' => true,
325 '4.0' => true,
326 '15.0' => true,
329 'versionclasses' => array(
330 'gecko',
335 // Firefox 18; Mac OS X 10.
336 array(
337 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
338 array(
339 'is_firefox' => true,
340 'check_firefox_version' => array(
341 '1.5' => true,
342 '3.0' => true,
343 '4' => true,
344 '10' => true,
345 '15' => true,
346 '18' => true,
349 'is_gecko' => true,
350 'check_gecko_version' => array(
351 '1' => true,
352 '2' => true,
353 '20030516' => true,
354 '20051116' => true,
355 '2006010100' => true,
356 '3.6' => true,
357 '4.0' => true,
358 '15.0' => true,
359 '18.0' => true,
360 '20100101' => true,
363 'versionclasses' => array(
364 'gecko',
369 // Firefox 33; Mac OS X 10.10.
370 array(
371 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
372 array(
373 'is_firefox' => true,
374 'check_firefox_version' => array(
375 '1.5' => true,
376 '3.0' => true,
377 '4' => true,
378 '10' => true,
379 '15' => true,
380 '18' => true,
381 '19' => true,
382 '33' => true,
385 'is_gecko' => true,
386 'check_gecko_version' => array(
387 '1' => true,
388 '2' => true,
389 '20030516' => true,
390 '20051116' => true,
391 '2006010100' => true,
392 '3.6' => true,
393 '4.0' => true,
394 '15.0' => true,
395 '18.0' => true,
396 '19.0' => true,
397 '20100101' => true,
400 'versionclasses' => array(
401 'gecko',
406 // SeaMonkey 2.0; Windows.
407 array(
408 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
409 array(
410 'is_gecko' => true,
411 'check_gecko_version' => array(
412 '1' => true,
413 '2' => true,
414 '20030516' => true,
415 '20051106' => true,
416 '20051116' => true,
417 '2006010100' => true,
420 'versionclasses' => array(
421 'gecko',
422 'gecko19',
427 // SeaMonkey 2.1; Linux.
428 array(
429 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
430 array(
431 'is_gecko' => true,
432 'check_gecko_version' => array(
433 '1' => true,
434 '2' => true,
435 '20030516' => true,
436 '20051116' => true,
437 '2006010100' => true,
438 '20100101' => true,
439 '3.6' => true,
440 '4.0' => true,
443 'is_firefox' => true,
444 'check_firefox_version' => array(
445 '1.5' => true,
446 '3.0' => true,
447 '4' => true,
450 'versionclasses' => array(
451 'gecko',
452 'gecko20',
457 // SeaMonkey 2.3; FreeBSD.
458 array(
459 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
460 array(
461 'is_gecko' => true,
462 'check_gecko_version' => array(
463 '1' => true,
464 '2' => true,
465 '20030516' => true,
466 '20051116' => true,
467 '2006010100' => true,
468 '20100101' => true,
469 '3.6' => true,
470 '4.0' => true,
473 'is_firefox' => true,
474 'check_firefox_version' => array(
475 '1.5' => true,
476 '3.0' => true,
477 '4' => true,
480 'versionclasses' => array(
481 'gecko',
486 // Mac OS X; MS Word 14.
487 array(
488 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
489 array(
490 'versionclasses' => array(
493 'is_msword' => true,
497 // Safari 312; Max OS X.
498 array(
499 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
500 array(
501 'is_safari' => true,
502 'check_safari_version' => array(
503 '1' => true,
504 '312' => true,
507 'is_webkit' => true,
509 'versionclasses' => array(
510 'safari',
515 // Safari 412; Max OS X.
516 array(
517 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
518 array(
519 'is_safari' => true,
520 'check_safari_version' => array(
521 '1' => true,
522 '312' => true,
525 'is_webkit' => true,
527 'versionclasses' => array(
528 'safari',
533 // Safari 2.0; Max OS X.
534 array(
535 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
536 array(
537 'is_safari' => true,
538 'check_safari_version' => array(
539 '1' => true,
540 '312' => true,
543 'is_webkit' => true,
545 'versionclasses' => array(
546 'safari',
551 // iOS Safari 528; iPhone.
552 array(
553 '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',
554 array(
555 // Note: We do *not* identify mobile Safari as Safari.
556 'is_safari_ios' => true,
557 'is_ios' => true,
558 'check_safari_ios_version' => array(
559 '527' => true,
562 'is_webkit' => true,
564 'versionclasses' => array(
565 'ios'
568 'devicetype' => 'mobile',
572 // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
573 array(
574 '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',
575 array(
576 // Note: We do *not* identify mobile Safari as Safari.
577 'is_safari_ios' => true,
578 'is_ios' => true,
579 'check_safari_ios_version' => array(
580 '527' => true,
581 '590' => true,
582 '600' => true,
585 'is_webkit' => true,
587 'versionclasses' => array(
588 'ios',
591 'devicetype' => 'mobile',
595 // iOS Safari 533; iPad.
596 array(
597 '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',
598 array(
599 // Note: We do *not* identify mobile Safari as Safari.
600 'is_safari_ios' => true,
601 'is_ios' => true,
602 'check_safari_ios_version' => array(
603 '527' => true,
606 'is_webkit' => true,
608 'versionclasses' => array(
609 'ios',
612 'devicetype' => 'tablet',
616 // Android WebKit 525; G1 Phone.
617 'Android WebKit 525; G1 Phone' => array(
618 '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',
619 array(
620 'is_webkit_android' => true,
621 'check_webkit_android_version' => array(
622 '525' => true,
625 'is_webkit' => true,
627 'versionclasses' => array(
628 'android',
631 'devicetype' => 'mobile',
633 'supports_svg' => false,
637 // Android WebKit 530; Nexus.
638 'Android WebKit 530; Nexus' => array(
639 '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',
640 array(
641 'is_webkit_android' => true,
642 'check_webkit_android_version' => array(
643 '525' => true,
644 '527' => true,
647 'is_webkit' => true,
649 'versionclasses' => array(
650 'android',
653 'devicetype' => 'mobile',
655 'supports_svg' => false,
659 // Android WebKit 537; Samsung GT-9505.
660 array(
661 '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',
662 array(
663 'is_webkit_android' => true,
664 'check_webkit_android_version' => array(
665 '525' => true,
666 '527' => true,
669 'is_webkit' => true,
671 'is_chrome' => true,
672 'check_chrome_version' => array(
673 '7' => true,
674 '8' => true,
675 '10' => true,
678 'versionclasses' => array(
679 'chrome',
680 'android',
683 'devicetype' => 'mobile',
687 // Android WebKit 537; Nexus 5.
688 array(
689 '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',
690 array(
691 'is_webkit_android' => true,
692 'check_webkit_android_version' => array(
693 '525' => true,
694 '527' => true,
697 'is_webkit' => true,
699 'is_chrome' => true,
700 'check_chrome_version' => array(
701 '7' => true,
702 '8' => true,
703 '10' => true,
706 'versionclasses' => array(
707 'chrome',
708 'android',
711 'devicetype' => 'mobile',
715 // Chrome 8; Mac OS X.
716 array(
717 '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',
718 array(
719 'is_chrome' => true,
720 'check_chrome_version' => array(
721 '7' => true,
722 '8' => true,
725 'is_webkit' => true,
727 'versionclasses' => array(
728 'chrome',
733 // Chrome 39; Mac OS X.
734 array(
735 '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',
736 array(
737 'is_chrome' => true,
738 'check_chrome_version' => array(
739 '7' => true,
740 '8' => true,
741 '10' => true,
742 '39' => true,
745 'is_webkit' => true,
747 'versionclasses' => array(
748 'chrome',
753 // Opera 12.15 (Build 1748); Mac OS X.
754 array(
755 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
756 array(
757 'is_opera' => true,
758 'check_opera_version' => array(
759 '8.0' => true,
760 '9.0' => true,
761 '10.0' => true,
762 '12.15' => true,
765 'versionclasses' => array(
766 'opera',
771 // Google web crawlers.
772 array(
773 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
774 array(
775 'is_web_crawler' => true,
776 'versionclasses' => array(
780 array(
781 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
782 array(
783 'is_web_crawler' => true,
784 'versionclasses' => array(
788 array(
789 'Googlebot-Image/1.0',
790 array(
791 'is_web_crawler' => true,
792 'versionclasses' => array(
797 // Yahoo crawlers.
798 // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
799 array(
800 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
801 array(
802 'is_web_crawler' => true,
803 'versionclasses' => array(
808 // Bing / MSN / AdIdx crawlers.
809 // See http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0.
810 array(
811 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
812 array(
813 'is_web_crawler' => true,
814 'versionclasses' => array(
818 array(
819 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
820 array(
821 'is_web_crawler' => true,
822 'versionclasses' => array(
826 array(
827 '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)',
828 array(
829 'is_web_crawler' => true,
830 'is_webkit' => true,
831 'is_safari_ios' => true,
832 'is_ios' => true,
833 'check_safari_ios_version' => array(
834 '527' => true,
837 'versionclasses' => array(
838 'ios',
841 'devicetype' => 'mobile',
844 array(
845 '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)',
846 array(
847 'is_web_crawler' => true,
848 'is_ie' => true,
849 'check_ie_version' => array(
850 '0' => true,
851 '5.0' => true,
852 '5.5' => true,
853 '6.0' => true,
854 '7.0' => true,
855 '8.0' => true,
856 '9.0' => true,
857 '10' => true,
858 '11' => true,
860 'versionclasses' => array(
861 'ie',
862 'ie11',
864 'devicetype' => 'mobile',
868 array(
869 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
870 array(
871 'is_web_crawler' => true,
872 'versionclasses' => array(
876 array(
877 'msnbot/2.1',
878 array(
879 'is_web_crawler' => true,
880 'versionclasses' => array(
884 array(
885 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
886 array(
887 'is_web_crawler' => true,
888 'versionclasses' => array(
892 array(
893 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
894 array(
895 'is_web_crawler' => true,
896 'is_webkit' => true,
897 'is_safari' => true,
898 'check_safari_version' => array(
899 '1' => true,
900 '312' => true,
901 '500' => true,
904 'versionclasses' => array(
905 'safari',
909 array(
910 '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',
911 array(
912 'is_web_crawler' => true,
913 'is_ie' => true,
914 'check_ie_version' => array(
915 '0' => true,
916 '5.0' => true,
917 '5.5' => true,
918 '6.0' => true,
919 '7.0' => true,
920 '8.0' => true,
921 '9.0' => true,
922 '10' => true,
923 '11' => true,
925 'versionclasses' => array(
926 'ie',
927 'ie11',
929 'devicetype' => 'mobile',
933 // Yandex.
934 // See http://help.yandex.com/search/robots/agent.xml.
935 array(
936 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
937 array(
938 'is_web_crawler' => true,
939 'versionclasses' => array(
943 array(
944 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
945 array(
946 'is_web_crawler' => true,
947 'versionclasses' => array(
952 // AltaVista.
953 array(
954 'AltaVista V2.0B crawler@evreka.com',
955 array(
956 'is_web_crawler' => true,
957 'versionclasses' => array(
962 // ZoomSpider.
963 array(
964 'ZoomSpider - wrensoft.com [ZSEBOT]',
965 array(
966 'is_web_crawler' => true,
967 'versionclasses' => array(
972 // Baidu.
973 array(
974 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
975 array(
976 'is_web_crawler' => true,
977 'versionclasses' => array(
981 array(
982 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
983 array(
984 'is_web_crawler' => true,
985 'versionclasses' => array(
990 // Ask.com.
991 array(
992 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
993 array(
994 'is_web_crawler' => true,
995 'versionclasses' => array(
1000 // MoodleBot.
1001 array(
1002 'User-Agent: MoodleBot/3.8 (+https://moodle.org)',
1003 array(
1004 'is_web_crawler' => true,
1005 'versionclasses' => array(
1010 // Macos Desktop app.
1011 array(
1012 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) moodlemobile/3.6.0 Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36 MoodleMobile',
1013 array(
1014 'is_moodle_app' => true,
1015 'is_webkit' => true,
1016 'is_chrome' => true,
1017 'check_chrome_version' => array(
1018 '7' => true,
1019 '8' => true,
1020 '10' => true,
1021 '39' => true,
1023 'versionclasses' => array(
1024 'chrome',
1029 // Linux Desktop app.
1030 array(
1031 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) moodledesktop/3.6.0 Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36 MoodleMobile',
1032 array(
1033 'is_moodle_app' => true,
1034 'is_webkit' => true,
1035 'is_chrome' => true,
1036 'check_chrome_version' => array(
1037 '7' => true,
1038 '8' => true,
1039 '10' => true,
1040 '39' => true,
1042 'versionclasses' => array(
1043 'chrome',
1048 // Windows Desktop app.
1049 array(
1050 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) moodledesktop/3.6.0 Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36 MoodleMobile',
1051 array(
1052 'is_moodle_app' => true,
1053 'is_webkit' => true,
1054 'is_chrome' => true,
1055 'check_chrome_version' => array(
1056 '7' => true,
1057 '8' => true,
1058 '10' => true,
1059 '39' => true,
1061 'versionclasses' => array(
1062 'chrome',
1067 // Android app.
1068 array(
1069 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile',
1070 array(
1071 'is_moodle_app' => true,
1072 'is_webkit' => true,
1073 'is_webkit_android' => true,
1074 'is_chrome' => true,
1075 'check_chrome_version' => array(
1076 '7' => true,
1077 '8' => true,
1078 '10' => true,
1079 '39' => true,
1081 'devicetype' => 'mobile',
1082 'check_webkit_android_version' => array(
1083 '525' => true,
1084 '527' => true,
1086 'versionclasses' => array(
1087 'android',
1088 'chrome'
1093 // Android app, user agent lower case.
1094 array(
1095 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 moodlemobile',
1096 array(
1097 'is_moodle_app' => true,
1098 'is_webkit' => true,
1099 'is_webkit_android' => true,
1100 'is_chrome' => true,
1101 'check_chrome_version' => array(
1102 '7' => true,
1103 '8' => true,
1104 '10' => true,
1105 '39' => true,
1107 'devicetype' => 'mobile',
1108 'check_webkit_android_version' => array(
1109 '525' => true,
1110 '527' => true,
1112 'versionclasses' => array(
1113 'android',
1114 'chrome'
1119 // iOS (iPhone) app.
1120 array(
1121 'Mozilla/5.0 (iPhone; CPU OS 13_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MoodleMobile',
1122 array(
1123 'is_moodle_app' => true,
1124 'is_ios' => true,
1125 'is_webkit' => true,
1126 'devicetype' => 'mobile',
1127 'versionclasses' => array(
1132 // iOS (iPad) app.
1133 array(
1134 'Mozilla/5.0 (iPad; CPU OS 12_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D39 MoodleMobile',
1135 array(
1136 'is_moodle_app' => true,
1137 'is_ios' => true,
1138 'is_webkit' => true,
1139 'devicetype' => 'tablet',
1140 'versionclasses' => array(
1148 * Test instance generation.
1150 public function test_instance() {
1151 $this->assertInstanceOf('core_useragent', core_useragent::instance());
1152 $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
1156 * @dataProvider user_agents_providers
1158 public function test_useragent_edge($useragent, $tests) {
1159 // Setup the core_useragent instance.
1160 core_useragent::instance(true, $useragent);
1162 // Edge Tests.
1163 if (isset($tests['is_edge']) && $tests['is_edge']) {
1164 $this->assertTrue(core_useragent::is_edge());
1165 } else {
1166 $this->assertFalse(core_useragent::is_edge());
1169 $versions = array(
1170 // New versions of should be added here.
1171 '12' => false,
1174 if (isset($tests['check_edge_version'])) {
1175 // The test provider has overwritten some of the above checks.
1176 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1177 $versions = $tests['check_edge_version'] + $versions;
1180 foreach ($versions as $version => $result) {
1181 $this->assertEquals($result, core_useragent::check_edge_version($version),
1182 "Version incorrectly determined for Edge version '{$version}'");
1187 * @dataProvider user_agents_providers
1189 public function test_useragent_ie($useragent, $tests) {
1190 // Setup the core_useragent instance.
1191 core_useragent::instance(true, $useragent);
1193 // IE Tests.
1194 if (isset($tests['is_ie']) && $tests['is_ie']) {
1195 $this->assertTrue(core_useragent::is_ie());
1196 } else {
1197 $this->assertFalse(core_useragent::is_ie());
1200 $versions = array(
1201 // New versions of should be added here.
1202 '0' => false,
1203 '5.0' => false,
1204 '5.5' => false,
1205 '6.0' => false,
1206 '7.0' => false,
1207 '8.0' => false,
1208 '9.0' => false,
1209 '10' => false,
1210 '11' => false,
1211 '12' => false,
1212 '13' => false,
1213 '14' => false,
1216 if (isset($tests['check_ie_version'])) {
1217 // The test provider has overwritten some of the above checks.
1218 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1219 $versions = $tests['check_ie_version'] + $versions;
1222 foreach ($versions as $version => $result) {
1223 $this->assertEquals($result, core_useragent::check_ie_version($version),
1224 "Version incorrectly determined for IE version '{$version}'");
1227 // IE Compatibility mode.
1228 if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1229 $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1230 } else {
1231 $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1237 * @dataProvider user_agents_providers
1239 public function test_useragent_msword($useragent, $tests) {
1240 // Setup the core_useragent instance.
1241 core_useragent::instance(true, $useragent);
1243 // MSWord Tests.
1244 if (isset($tests['is_msword']) && $tests['is_msword']) {
1245 $this->assertTrue(core_useragent::is_msword());
1246 } else {
1247 $this->assertFalse(core_useragent::is_msword());
1252 * @dataProvider user_agents_providers
1254 public function test_useragent_supports($useragent, $tests) {
1255 // Setup the core_useragent instance.
1256 core_useragent::instance(true, $useragent);
1258 // Supports SVG.
1259 if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1260 $this->assertTrue(core_useragent::supports_svg(),
1261 "SVG Support was not reported (and should have been)");
1262 } else {
1263 $this->assertFalse(core_useragent::supports_svg(),
1264 "SVG Support was reported (and should not have been)");
1267 // Supports JSON ContentType.
1268 if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
1269 $this->assertTrue(core_useragent::supports_json_contenttype(),
1270 "JSON ContentType Support was not reported (and should have been)");
1271 } else {
1272 $this->assertFalse(core_useragent::supports_json_contenttype(),
1273 "JSON ContentType Support was reported (and should not have been)");
1278 * @dataProvider user_agents_providers
1280 public function test_useragent_webkit($useragent, $tests) {
1281 // Setup the core_useragent instance.
1282 core_useragent::instance(true, $useragent);
1284 if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1285 $this->assertTrue(core_useragent::is_webkit(),
1286 "Browser was not identified as a webkit browser");
1287 $this->assertTrue(core_useragent::check_webkit_version());
1288 } else {
1289 $this->assertFalse(core_useragent::is_webkit(),
1290 "Browser was incorrectly identified as a webkit browser");
1291 $this->assertFalse(core_useragent::check_webkit_version());
1294 $versions = array(
1295 // New versions should be added here.
1298 if (isset($tests['check_webkit_version'])) {
1299 // The test provider has overwritten some of the above checks.
1300 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1301 $versions = $tests['check_webkit_version'] + $versions;
1304 foreach ($versions as $version => $result) {
1305 $this->assertEquals($result, core_useragent::check_webkit_version($version),
1306 "Version incorrectly determined for Webkit version '{$version}'");
1311 * @dataProvider user_agents_providers
1313 public function test_useragent_webkit_android($useragent, $tests) {
1314 // Setup the core_useragent instance.
1315 core_useragent::instance(true, $useragent);
1317 if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1318 $this->assertTrue(core_useragent::is_webkit_android(),
1319 "Browser was not identified as an Android webkit browser");
1320 $this->assertTrue(core_useragent::check_webkit_android_version());
1321 } else {
1322 $this->assertFalse(core_useragent::is_webkit_android(),
1323 "Browser was incorrectly identified as an Android webkit browser");
1324 $this->assertFalse(core_useragent::check_webkit_android_version());
1327 $versions = array(
1328 // New versions should be added here.
1329 '525' => false,
1330 '527' => false,
1331 '590' => false,
1334 if (isset($tests['check_webkit_android_version'])) {
1335 // The test provider has overwritten some of the above checks.
1336 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1337 $versions = $tests['check_webkit_android_version'] + $versions;
1340 foreach ($versions as $version => $result) {
1341 $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1342 "Version incorrectly determined for Android webkit version '{$version}'");
1347 * @dataProvider user_agents_providers
1349 public function test_useragent_chrome($useragent, $tests) {
1350 // Setup the core_useragent instance.
1351 core_useragent::instance(true, $useragent);
1353 if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1354 $this->assertTrue(core_useragent::is_chrome(),
1355 "Browser was not identified as a chrome browser");
1356 $this->assertTrue(core_useragent::check_chrome_version());
1357 } else {
1358 $this->assertFalse(core_useragent::is_chrome(),
1359 "Browser was incorrectly identified as a chrome browser");
1360 $this->assertFalse(core_useragent::check_chrome_version());
1363 $versions = array(
1364 // New versions should be added here.
1365 '7' => false,
1366 '8' => false,
1367 '10' => false,
1368 '39' => false,
1371 if (isset($tests['check_chrome_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_chrome_version'] + $versions;
1377 foreach ($versions as $version => $result) {
1378 $this->assertEquals($result, core_useragent::check_chrome_version($version),
1379 "Version incorrectly determined for Chrome version '{$version}'");
1384 * @dataProvider user_agents_providers
1386 public function test_useragent_safari($useragent, $tests) {
1387 // Setup the core_useragent instance.
1388 core_useragent::instance(true, $useragent);
1390 if (isset($tests['is_safari']) && $tests['is_safari']) {
1391 $this->assertTrue(core_useragent::is_safari(),
1392 "Browser was not identified as a safari browser");
1393 $this->assertTrue(core_useragent::check_safari_version());
1394 } else {
1395 $this->assertFalse(core_useragent::is_safari(),
1396 "Browser was incorrectly identified as a safari browser");
1397 $this->assertFalse(core_useragent::check_safari_version());
1400 // Check Safari (generic).
1401 $versions = array(
1402 // New versions should be added here.
1403 '1' => false,
1404 '312' => false,
1405 '500' => false,
1408 if (isset($tests['check_safari_version'])) {
1409 // The test provider has overwritten some of the above checks.
1410 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1411 $versions = $tests['check_safari_version'] + $versions;
1414 foreach ($versions as $version => $result) {
1415 $this->assertEquals($result, core_useragent::check_safari_version($version),
1416 "Version incorrectly determined for Safari (generic) version '{$version}'");
1421 * @dataProvider user_agents_providers
1423 public function test_useragent_ios_safari($useragent, $tests) {
1424 // Setup the core_useragent instance.
1425 core_useragent::instance(true, $useragent);
1427 if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1428 $this->assertTrue(core_useragent::is_safari_ios(),
1429 "Browser was not identified as an iOS safari browser");
1430 $this->assertTrue(core_useragent::check_safari_ios_version());
1431 } else {
1432 $this->assertFalse(core_useragent::is_safari_ios(),
1433 "Browser was incorrectly identified as an iOS safari browser");
1434 $this->assertFalse(core_useragent::check_safari_ios_version());
1437 // Check iOS Safari.
1438 $versions = array(
1439 // New versions should be added here.
1440 '527' => false,
1441 '590' => false,
1442 '600' => false,
1445 if (isset($tests['check_safari_ios_version'])) {
1446 // The test provider has overwritten some of the above checks.
1447 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1448 $versions = $tests['check_safari_ios_version'] + $versions;
1451 foreach ($versions as $version => $result) {
1452 $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1453 "Version incorrectly determined for iOS Safari version '{$version}'");
1458 * @dataProvider user_agents_providers
1460 public function test_useragent_ios($useragent, $tests) {
1461 // Setup the core_useragent instance.
1462 core_useragent::instance(true, $useragent);
1464 if (isset($tests['is_ios']) && $tests['is_ios']) {
1465 $this->assertTrue(core_useragent::is_ios(),
1466 "Browser was not identified as an iOS device browser");
1467 // The iOS app is not Safari based.
1468 if (!isset($tests['is_moodle_app']) || !$tests['is_moodle_app']) {
1469 $this->assertTrue(core_useragent::check_safari_ios_version());
1471 } else {
1472 $this->assertFalse(core_useragent::is_ios(),
1473 "Browser was incorrectly identified as an iOS device browser");
1474 $this->assertFalse(core_useragent::check_safari_ios_version());
1479 * @dataProvider user_agents_providers
1481 public function test_useragent_gecko($useragent, $tests) {
1482 // Setup the core_useragent instance.
1483 core_useragent::instance(true, $useragent);
1485 if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1486 $this->assertTrue(core_useragent::is_gecko(),
1487 "Browser was not identified as a gecko browser");
1488 $this->assertTrue(core_useragent::check_gecko_version());
1489 } else {
1490 $this->assertFalse(core_useragent::is_gecko(),
1491 "Browser was incorrectly identified as a gecko browser");
1492 $this->assertFalse(core_useragent::check_gecko_version());
1495 $versions = array(
1496 // New versions should be added here.
1497 '1' => false,
1498 '2' => false,
1499 '3.6' => false,
1500 '4.0' => false,
1501 '20030516' => false,
1502 '20051116' => false,
1503 '2006010100' => false,
1504 '20100101' => false,
1505 '15.0' => false,
1506 '18.0' => false,
1507 '19.0' => false,
1510 if (isset($tests['check_gecko_version'])) {
1511 // The test provider has overwritten some of the above checks.
1512 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1513 $versions = $tests['check_gecko_version'] + $versions;
1516 foreach ($versions as $version => $result) {
1517 $this->assertEquals($result, core_useragent::check_gecko_version($version),
1518 "Version incorrectly determined for Gecko version '{$version}'");
1523 * @dataProvider user_agents_providers
1525 public function test_useragent_firefox($useragent, $tests) {
1526 // Setup the core_useragent instance.
1527 core_useragent::instance(true, $useragent);
1529 if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1530 $this->assertTrue(core_useragent::is_firefox(),
1531 "Browser was not identified as a firefox browser");
1532 $this->assertTrue(core_useragent::check_firefox_version());
1533 } else {
1534 $this->assertFalse(core_useragent::is_firefox(),
1535 "Browser was incorrectly identified as a firefox browser");
1536 $this->assertFalse(core_useragent::check_firefox_version());
1539 $versions = array(
1540 // New versions should be added here.
1541 '1.5' => false,
1542 '3.0' => false,
1543 '4' => false,
1544 '10' => false,
1545 '15' => false,
1546 '18' => false,
1547 '19' => false,
1548 '33' => false,
1551 if (isset($tests['check_firefox_version'])) {
1552 // The test provider has overwritten some of the above checks.
1553 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1554 $versions = $tests['check_firefox_version'] + $versions;
1557 foreach ($versions as $version => $result) {
1558 $this->assertEquals($result, core_useragent::check_firefox_version($version),
1559 "Version incorrectly determined for Firefox version '{$version}'");
1564 * @dataProvider user_agents_providers
1566 public function test_useragent_opera($useragent, $tests) {
1567 // Setup the core_useragent instance.
1568 core_useragent::instance(true, $useragent);
1570 if (isset($tests['is_opera']) && $tests['is_opera']) {
1571 $this->assertTrue(core_useragent::is_opera(),
1572 "Browser was not identified as a opera browser");
1573 $this->assertTrue(core_useragent::check_opera_version());
1574 } else {
1575 $this->assertFalse(core_useragent::is_opera(),
1576 "Browser was incorrectly identified as a opera browser");
1577 $this->assertFalse(core_useragent::check_opera_version());
1580 $versions = array(
1581 // New versions should be added here.
1582 '8.0' => false,
1583 '9.0' => false,
1584 '10.0' => false,
1585 '12.15' => false,
1588 if (isset($tests['check_opera_version'])) {
1589 // The test provider has overwritten some of the above checks.
1590 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1591 $versions = $tests['check_opera_version'] + $versions;
1594 foreach ($versions as $version => $result) {
1595 $this->assertEquals($result, core_useragent::check_opera_version($version),
1596 "Version incorrectly determined for Opera version '{$version}'");
1601 * @dataProvider user_agents_providers
1603 public function test_get_device_type($useragent, $tests) {
1604 // Setup the core_useragent instance.
1605 core_useragent::instance(true, $useragent);
1607 $expected = 'default';
1608 if (isset($tests['devicetype'])) {
1609 $expected = $tests['devicetype'];
1612 $this->assertEquals($expected, core_useragent::get_device_type(),
1613 "Device Type was not correctly identified");
1617 * @dataProvider user_agents_providers
1619 public function test_get_browser_version_classes($useragent, $tests) {
1620 // Setup the core_useragent instance.
1621 core_useragent::instance(true, $useragent);
1623 $actual = core_useragent::get_browser_version_classes();
1624 foreach ($tests['versionclasses'] as $expectedclass) {
1625 $this->assertContains($expectedclass, $actual);
1627 $this->assertCount(count($tests['versionclasses']), $actual);
1631 * @dataProvider user_agents_providers
1633 public function test_useragent_web_crawler($useragent, $tests) {
1634 // Setup the core_useragent instance.
1635 core_useragent::instance(true, $useragent);
1637 $expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
1638 $this->assertSame($expectation, core_useragent::is_web_crawler());
1642 * @dataProvider user_agents_providers
1644 public function test_useragent_moodle_app($useragent, $tests) {
1645 // Setup the core_useragent instance.
1646 core_useragent::instance(true, $useragent);
1648 $expectation = isset($tests['is_moodle_app']) ? $tests['is_moodle_app'] : false;
1649 $this->assertSame($expectation, core_useragent::is_moodle_app());