2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * User agent test suite.
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
{
28 * Restores the user agent to the default one.
30 public function tearDown(): void
{
31 core_useragent
::instance(true);
35 * Data provider for known user agents.
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.
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',
47 'check_edge_version' => array(
51 // Edge pretends to be WebKit.
54 // Edge pretends to be Chrome.
55 // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
57 'check_chrome_version' => array(
64 'versionclasses' => array(
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',
73 'check_edge_version' => array(
77 // Edge pretends to be WebKit.
80 // Mobile Edge pretends to be Android.
81 'is_webkit_android' => true,
82 'check_webkit_android_version' => array(
87 // Edge pretends to be Chrome.
88 // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
90 'check_chrome_version' => array(
97 'versionclasses' => array(
101 'devicetype' => 'mobile',
104 // Windows 98; Internet Explorer 5.0.
106 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
108 // MSIE 5.0 is not considered a browser at all: known false results.
110 'check_ie_version' => array(
114 'versionclasses' => array(
115 // IE 5.0 is not considered a browser.
118 // IE 5.0 is a legacy browser.
119 'devicetype' => 'legacy',
121 'supports_svg' => false,
122 'supports_json_contenttype' => false,
126 // Windows 2000; Internet Explorer 5.5.
128 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
131 'check_ie_version' => array(
136 'versionclasses' => array(
140 // IE 6.0 is a legacy browser.
141 'devicetype' => 'legacy',
143 'supports_svg' => false,
144 'supports_json_contenttype' => false,
148 // Windows XP SP2; Internet Explorer 6.0.
150 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
153 'check_ie_version' => array(
159 'versionclasses' => array(
164 // IE 7.0 is a legacy browser.
165 'devicetype' => 'legacy',
167 'supports_svg' => false,
168 'supports_json_contenttype' => false,
172 // Windows XP SP2; Internet Explorer 7.0.
174 '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)',
177 'check_ie_version' => array(
184 'versionclasses' => array(
189 'supports_svg' => false,
190 'supports_json_contenttype' => false,
194 // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
196 '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)',
199 'check_ie_version' => array(
206 'versionclasses' => array(
211 'supports_svg' => false,
212 'supports_json_contenttype' => false,
216 // Windows Vista; Internet Explorer 8.0.
218 '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)',
221 'check_ie_version' => array(
229 'versionclasses' => array(
234 'supports_svg' => false,
238 // Windows 7; Internet Explorer 9.0.
240 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
243 'check_ie_version' => array(
252 'versionclasses' => array(
259 // Windows 7; Internet Explorer 9.0i.
261 '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)',
264 'check_ie_version' => array(
273 'versionclasses' => array(
277 'iecompatibility' => true,
279 // IE 9 in Compatiblity mode does not support SVG.
280 'supports_svg' => false,
282 // IE in Compatiblity mode does not support JSON ContentType.
283 'supports_json_contenttype' => false,
287 // Windows 8; Internet Explorer 10.0.
289 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
292 'check_ie_version' => array(
302 'versionclasses' => array(
309 // Windows 8; Internet Explorer 10.0i.
311 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
314 'check_ie_version' => array(
324 'iecompatibility' => true,
325 'versionclasses' => array(
330 // IE in Compatiblity mode does not support JSON ContentType.
331 'supports_json_contenttype' => false,
335 // Windows 8.1; Internet Explorer 11.0.
337 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
340 'check_ie_version' => array(
351 'versionclasses' => array(
358 // Windows 8.1; Internet Explorer 11.0i.
360 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
363 'check_ie_version' => array(
374 'iecompatibility' => true,
375 'versionclasses' => array(
380 // IE in Compatiblity mode does not support JSON ContentType.
381 'supports_json_contenttype' => false,
385 // Windows XP; Firefox 1.0.6.
387 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
389 'is_firefox' => true,
392 'check_gecko_version' => array(
396 'versionclasses' => array(
403 // Windows XP; Firefox 1.0.6.
405 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
407 'is_firefox' => true,
408 'check_firefox_version' => array(
413 'check_gecko_version' => array(
419 'versionclasses' => array(
426 // Windows XP; Firefox 1.5.0.1.
428 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
430 'is_firefox' => true,
431 'check_firefox_version' => array(
436 'check_gecko_version' => array(
442 'versionclasses' => array(
449 // Windows XP; Firefox 2.0.
451 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
453 'is_firefox' => true,
454 'check_firefox_version' => array(
459 'check_gecko_version' => array(
464 '2006010100' => true,
467 'versionclasses' => array(
474 // Ubuntu Linux amd64; Firefox 2.0.
476 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
478 'is_firefox' => true,
479 'check_firefox_version' => array(
484 'check_gecko_version' => array(
489 '2006010100' => true,
492 'versionclasses' => array(
499 // SUSE; Firefox 3.0.6.
501 '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',
503 'is_firefox' => true,
504 'check_firefox_version' => array(
510 'check_gecko_version' => array(
515 '2006010100' => true,
518 'versionclasses' => array(
525 // Linux i686; Firefox 3.6.
527 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
529 'is_firefox' => true,
530 'check_firefox_version' => array(
536 'check_gecko_version' => array(
541 '2006010100' => true,
546 'versionclasses' => array(
553 // Windows; Firefox 11.0.
555 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
557 'is_firefox' => true,
558 'check_firefox_version' => array(
566 'check_gecko_version' => array(
571 '2006010100' => true,
577 'versionclasses' => array(
583 // Windows; Firefox 15.0a2.
585 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
587 'is_firefox' => true,
588 'check_firefox_version' => array(
597 'check_gecko_version' => array(
602 '2006010100' => true,
609 'versionclasses' => array(
615 // Firefox 18; Mac OS X 10.
617 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
619 'is_firefox' => true,
620 'check_firefox_version' => array(
630 'check_gecko_version' => array(
635 '2006010100' => true,
643 'versionclasses' => array(
649 // Firefox 33; Mac OS X 10.10.
651 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
653 'is_firefox' => true,
654 'check_firefox_version' => array(
666 'check_gecko_version' => array(
671 '2006010100' => true,
680 'versionclasses' => array(
686 // SeaMonkey 2.0; Windows.
688 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
691 'check_gecko_version' => array(
697 '2006010100' => true,
700 'versionclasses' => array(
707 // SeaMonkey 2.1; Linux.
709 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
712 'check_gecko_version' => array(
717 '2006010100' => true,
723 'is_firefox' => true,
724 'check_firefox_version' => array(
730 'versionclasses' => array(
737 // SeaMonkey 2.3; FreeBSD.
739 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
742 'check_gecko_version' => array(
747 '2006010100' => true,
753 'is_firefox' => true,
754 'check_firefox_version' => array(
760 'versionclasses' => array(
766 // Windows 7; MS Word 2010.
768 '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)',
771 'check_ie_version' => array(
779 'iecompatibility' => true,
780 'versionclasses' => array(
787 'supports_svg' => false,
788 'supports_json_contenttype' => false,
792 // Windows 7; MS Outlook 2010.
794 '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)',
797 'check_ie_version' => array(
805 'iecompatibility' => true,
806 'versionclasses' => array(
811 // Note: Outlook is deliberately not considered to be MS Word.
812 'is_msword' => false,
814 'supports_svg' => false,
815 'supports_json_contenttype' => false,
819 // Mac OS X; MS Word 14.
821 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
823 'versionclasses' => array(
830 // Safari 312; Max OS X.
832 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
835 'check_safari_version' => array(
842 'versionclasses' => array(
848 // Safari 412; Max OS X.
850 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
853 'check_safari_version' => array(
860 'versionclasses' => array(
866 // Safari 2.0; Max OS X.
868 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
871 'check_safari_version' => array(
878 'versionclasses' => array(
884 // iOS Safari 528; iPhone.
886 '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',
888 // Note: We do *not* identify mobile Safari as Safari.
889 'is_safari_ios' => true,
891 'check_safari_ios_version' => array(
897 'versionclasses' => array(
901 'devicetype' => 'mobile',
905 // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
907 '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',
909 // Note: We do *not* identify mobile Safari as Safari.
910 'is_safari_ios' => true,
912 'check_safari_ios_version' => array(
920 'versionclasses' => array(
924 'devicetype' => 'mobile',
928 // iOS Safari 533; iPad.
930 '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',
932 // Note: We do *not* identify mobile Safari as Safari.
933 'is_safari_ios' => true,
935 'check_safari_ios_version' => array(
941 'versionclasses' => array(
945 'devicetype' => 'tablet',
949 // Android WebKit 525; G1 Phone.
950 'Android WebKit 525; G1 Phone' => array(
951 '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',
953 'is_webkit_android' => true,
954 'check_webkit_android_version' => array(
960 'versionclasses' => array(
964 'devicetype' => 'mobile',
966 'supports_svg' => false,
970 // Android WebKit 530; Nexus.
971 'Android WebKit 530; Nexus' => array(
972 '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',
974 'is_webkit_android' => true,
975 'check_webkit_android_version' => array(
982 'versionclasses' => array(
986 'devicetype' => 'mobile',
988 'supports_svg' => false,
992 // Android WebKit 537; Samsung GT-9505.
994 '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',
996 'is_webkit_android' => true,
997 'check_webkit_android_version' => array(
1002 'is_webkit' => true,
1004 'is_chrome' => true,
1005 'check_chrome_version' => array(
1011 'versionclasses' => array(
1016 'devicetype' => 'mobile',
1020 // Android WebKit 537; Nexus 5.
1022 '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',
1024 'is_webkit_android' => true,
1025 'check_webkit_android_version' => array(
1030 'is_webkit' => true,
1032 'is_chrome' => true,
1033 'check_chrome_version' => array(
1039 'versionclasses' => array(
1044 'devicetype' => 'mobile',
1048 // Chrome 8; Mac OS X.
1050 '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',
1052 'is_chrome' => true,
1053 'check_chrome_version' => array(
1058 'is_webkit' => true,
1060 'versionclasses' => array(
1066 // Chrome 39; Mac OS X.
1068 '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',
1070 'is_chrome' => true,
1071 'check_chrome_version' => array(
1078 'is_webkit' => true,
1080 'versionclasses' => array(
1086 // Opera 8.51; Windows XP.
1088 'Opera/8.51 (Windows NT 5.1; U; en)',
1091 'check_opera_version' => array(
1095 'versionclasses' => array(
1099 'supports_svg' => false,
1103 // Opera 9.0; Windows XP.
1105 'Opera/9.0 (Windows NT 5.1; U; en)',
1108 'check_opera_version' => array(
1113 'versionclasses' => array(
1117 'supports_svg' => false,
1121 // Opera 12.15 (Build 1748); Mac OS X.
1123 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
1126 'check_opera_version' => array(
1133 'versionclasses' => array(
1137 'supports_svg' => false,
1141 // Opera 9.0; Debian Linux.
1143 'Opera/9.01 (X11; Linux i686; U; en)',
1146 'check_opera_version' => array(
1151 'versionclasses' => array(
1155 'supports_svg' => false,
1159 // Google web crawlers.
1161 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
1163 'is_web_crawler' => true,
1164 'versionclasses' => array(
1169 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
1171 'is_web_crawler' => true,
1172 'versionclasses' => array(
1177 'Googlebot-Image/1.0',
1179 'is_web_crawler' => true,
1180 'versionclasses' => array(
1186 // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
1188 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
1190 'is_web_crawler' => true,
1191 'versionclasses' => array(
1196 // Bing / MSN / AdIdx crawlers.
1197 // See http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0.
1199 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
1201 'is_web_crawler' => true,
1202 'versionclasses' => array(
1207 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
1209 'is_web_crawler' => true,
1210 'versionclasses' => array(
1215 '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)',
1217 'is_web_crawler' => true,
1218 'is_webkit' => true,
1219 'is_safari_ios' => true,
1221 'check_safari_ios_version' => array(
1225 'versionclasses' => array(
1229 'devicetype' => 'mobile',
1233 '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)',
1235 'is_web_crawler' => true,
1237 'check_ie_version' => array(
1248 'versionclasses' => array(
1252 'devicetype' => 'mobile',
1257 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
1259 'is_web_crawler' => true,
1260 'versionclasses' => array(
1267 'is_web_crawler' => true,
1268 'versionclasses' => array(
1273 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
1275 'is_web_crawler' => true,
1276 'versionclasses' => array(
1281 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
1283 'is_web_crawler' => true,
1284 'is_webkit' => true,
1285 'is_safari' => true,
1286 'check_safari_version' => array(
1292 'versionclasses' => array(
1298 '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',
1300 'is_web_crawler' => true,
1302 'check_ie_version' => array(
1313 'versionclasses' => array(
1317 'devicetype' => 'mobile',
1322 // See http://help.yandex.com/search/robots/agent.xml.
1324 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
1326 'is_web_crawler' => true,
1327 'versionclasses' => array(
1332 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
1334 'is_web_crawler' => true,
1335 'versionclasses' => array(
1342 'AltaVista V2.0B crawler@evreka.com',
1344 'is_web_crawler' => true,
1345 'versionclasses' => array(
1352 'ZoomSpider - wrensoft.com [ZSEBOT]',
1354 'is_web_crawler' => true,
1355 'versionclasses' => array(
1362 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
1364 'is_web_crawler' => true,
1365 'versionclasses' => array(
1370 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
1372 'is_web_crawler' => true,
1373 'versionclasses' => array(
1380 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
1382 'is_web_crawler' => true,
1383 'versionclasses' => array(
1390 'User-Agent: MoodleBot/3.8 (+https://moodle.org)',
1392 'is_web_crawler' => true,
1393 'versionclasses' => array(
1398 // Macos Desktop app.
1400 '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',
1402 'is_moodle_app' => true,
1403 'is_webkit' => true,
1404 'is_chrome' => true,
1405 'check_chrome_version' => array(
1411 'versionclasses' => array(
1417 // Linux Desktop app.
1419 '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',
1421 'is_moodle_app' => true,
1422 'is_webkit' => true,
1423 'is_chrome' => true,
1424 'check_chrome_version' => array(
1430 'versionclasses' => array(
1436 // Windows Desktop app.
1438 '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',
1440 'is_moodle_app' => true,
1441 'is_webkit' => true,
1442 'is_chrome' => true,
1443 'check_chrome_version' => array(
1449 'versionclasses' => array(
1457 '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',
1459 'is_moodle_app' => true,
1460 'is_webkit' => true,
1461 'is_webkit_android' => true,
1462 'is_chrome' => true,
1463 'check_chrome_version' => array(
1469 'devicetype' => 'mobile',
1470 'check_webkit_android_version' => array(
1474 'versionclasses' => array(
1481 // Android app, user agent lower case.
1483 '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',
1485 'is_moodle_app' => true,
1486 'is_webkit' => true,
1487 'is_webkit_android' => true,
1488 'is_chrome' => true,
1489 'check_chrome_version' => array(
1495 'devicetype' => 'mobile',
1496 'check_webkit_android_version' => array(
1500 'versionclasses' => array(
1507 // iOS (iPhone) app.
1509 'Mozilla/5.0 (iPhone; CPU OS 13_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MoodleMobile',
1511 'is_moodle_app' => true,
1513 'is_webkit' => true,
1514 'devicetype' => 'mobile',
1515 'versionclasses' => array(
1522 'Mozilla/5.0 (iPad; CPU OS 12_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D39 MoodleMobile',
1524 'is_moodle_app' => true,
1526 'is_webkit' => true,
1527 'devicetype' => 'tablet',
1528 'versionclasses' => array(
1536 * Test instance generation.
1538 public function test_instance() {
1539 $this->assertInstanceOf('core_useragent', core_useragent
::instance());
1540 $this->assertInstanceOf('core_useragent', core_useragent
::instance(true));
1544 * @dataProvider user_agents_providers
1546 public function test_useragent_edge($useragent, $tests) {
1547 // Setup the core_useragent instance.
1548 core_useragent
::instance(true, $useragent);
1551 if (isset($tests['is_edge']) && $tests['is_edge']) {
1552 $this->assertTrue(core_useragent
::is_edge());
1554 $this->assertFalse(core_useragent
::is_edge());
1558 // New versions of should be added here.
1562 if (isset($tests['check_edge_version'])) {
1563 // The test provider has overwritten some of the above checks.
1564 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1565 $versions = $tests['check_edge_version'] +
$versions;
1568 foreach ($versions as $version => $result) {
1569 $this->assertEquals($result, core_useragent
::check_edge_version($version),
1570 "Version incorrectly determined for Edge version '{$version}'");
1575 * @dataProvider user_agents_providers
1577 public function test_useragent_ie($useragent, $tests) {
1578 // Setup the core_useragent instance.
1579 core_useragent
::instance(true, $useragent);
1582 if (isset($tests['is_ie']) && $tests['is_ie']) {
1583 $this->assertTrue(core_useragent
::is_ie());
1585 $this->assertFalse(core_useragent
::is_ie());
1589 // New versions of should be added here.
1604 if (isset($tests['check_ie_version'])) {
1605 // The test provider has overwritten some of the above checks.
1606 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1607 $versions = $tests['check_ie_version'] +
$versions;
1610 foreach ($versions as $version => $result) {
1611 $this->assertEquals($result, core_useragent
::check_ie_version($version),
1612 "Version incorrectly determined for IE version '{$version}'");
1615 // IE Compatibility mode.
1616 if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1617 $this->assertTrue(core_useragent
::check_ie_compatibility_view(), "IE Compability false negative");
1619 $this->assertFalse(core_useragent
::check_ie_compatibility_view(), "IE Compability false positive");
1625 * @dataProvider user_agents_providers
1627 public function test_useragent_msword($useragent, $tests) {
1628 // Setup the core_useragent instance.
1629 core_useragent
::instance(true, $useragent);
1632 if (isset($tests['is_msword']) && $tests['is_msword']) {
1633 $this->assertTrue(core_useragent
::is_msword());
1635 $this->assertFalse(core_useragent
::is_msword());
1640 * @dataProvider user_agents_providers
1642 public function test_useragent_supports($useragent, $tests) {
1643 // Setup the core_useragent instance.
1644 core_useragent
::instance(true, $useragent);
1647 if (!isset($tests['supports_svg']) ||
$tests['supports_svg']) {
1648 $this->assertTrue(core_useragent
::supports_svg(),
1649 "SVG Support was not reported (and should have been)");
1651 $this->assertFalse(core_useragent
::supports_svg(),
1652 "SVG Support was reported (and should not have been)");
1655 // Supports JSON ContentType.
1656 if (!isset($tests['supports_json_contenttype']) ||
$tests['supports_json_contenttype']) {
1657 $this->assertTrue(core_useragent
::supports_json_contenttype(),
1658 "JSON ContentType Support was not reported (and should have been)");
1660 $this->assertFalse(core_useragent
::supports_json_contenttype(),
1661 "JSON ContentType Support was reported (and should not have been)");
1666 * @dataProvider user_agents_providers
1668 public function test_useragent_webkit($useragent, $tests) {
1669 // Setup the core_useragent instance.
1670 core_useragent
::instance(true, $useragent);
1672 if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1673 $this->assertTrue(core_useragent
::is_webkit(),
1674 "Browser was not identified as a webkit browser");
1675 $this->assertTrue(core_useragent
::check_webkit_version());
1677 $this->assertFalse(core_useragent
::is_webkit(),
1678 "Browser was incorrectly identified as a webkit browser");
1679 $this->assertFalse(core_useragent
::check_webkit_version());
1683 // New versions should be added here.
1686 if (isset($tests['check_webkit_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_webkit_version'] +
$versions;
1692 foreach ($versions as $version => $result) {
1693 $this->assertEquals($result, core_useragent
::check_webkit_version($version),
1694 "Version incorrectly determined for Webkit version '{$version}'");
1699 * @dataProvider user_agents_providers
1701 public function test_useragent_webkit_android($useragent, $tests) {
1702 // Setup the core_useragent instance.
1703 core_useragent
::instance(true, $useragent);
1705 if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1706 $this->assertTrue(core_useragent
::is_webkit_android(),
1707 "Browser was not identified as an Android webkit browser");
1708 $this->assertTrue(core_useragent
::check_webkit_android_version());
1710 $this->assertFalse(core_useragent
::is_webkit_android(),
1711 "Browser was incorrectly identified as an Android webkit browser");
1712 $this->assertFalse(core_useragent
::check_webkit_android_version());
1716 // New versions should be added here.
1722 if (isset($tests['check_webkit_android_version'])) {
1723 // The test provider has overwritten some of the above checks.
1724 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1725 $versions = $tests['check_webkit_android_version'] +
$versions;
1728 foreach ($versions as $version => $result) {
1729 $this->assertEquals($result, core_useragent
::check_webkit_android_version($version),
1730 "Version incorrectly determined for Android webkit version '{$version}'");
1735 * @dataProvider user_agents_providers
1737 public function test_useragent_chrome($useragent, $tests) {
1738 // Setup the core_useragent instance.
1739 core_useragent
::instance(true, $useragent);
1741 if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1742 $this->assertTrue(core_useragent
::is_chrome(),
1743 "Browser was not identified as a chrome browser");
1744 $this->assertTrue(core_useragent
::check_chrome_version());
1746 $this->assertFalse(core_useragent
::is_chrome(),
1747 "Browser was incorrectly identified as a chrome browser");
1748 $this->assertFalse(core_useragent
::check_chrome_version());
1752 // New versions should be added here.
1759 if (isset($tests['check_chrome_version'])) {
1760 // The test provider has overwritten some of the above checks.
1761 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1762 $versions = $tests['check_chrome_version'] +
$versions;
1765 foreach ($versions as $version => $result) {
1766 $this->assertEquals($result, core_useragent
::check_chrome_version($version),
1767 "Version incorrectly determined for Chrome version '{$version}'");
1772 * @dataProvider user_agents_providers
1774 public function test_useragent_safari($useragent, $tests) {
1775 // Setup the core_useragent instance.
1776 core_useragent
::instance(true, $useragent);
1778 if (isset($tests['is_safari']) && $tests['is_safari']) {
1779 $this->assertTrue(core_useragent
::is_safari(),
1780 "Browser was not identified as a safari browser");
1781 $this->assertTrue(core_useragent
::check_safari_version());
1783 $this->assertFalse(core_useragent
::is_safari(),
1784 "Browser was incorrectly identified as a safari browser");
1785 $this->assertFalse(core_useragent
::check_safari_version());
1788 // Check Safari (generic).
1790 // New versions should be added here.
1796 if (isset($tests['check_safari_version'])) {
1797 // The test provider has overwritten some of the above checks.
1798 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1799 $versions = $tests['check_safari_version'] +
$versions;
1802 foreach ($versions as $version => $result) {
1803 $this->assertEquals($result, core_useragent
::check_safari_version($version),
1804 "Version incorrectly determined for Safari (generic) version '{$version}'");
1809 * @dataProvider user_agents_providers
1811 public function test_useragent_ios_safari($useragent, $tests) {
1812 // Setup the core_useragent instance.
1813 core_useragent
::instance(true, $useragent);
1815 if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1816 $this->assertTrue(core_useragent
::is_safari_ios(),
1817 "Browser was not identified as an iOS safari browser");
1818 $this->assertTrue(core_useragent
::check_safari_ios_version());
1820 $this->assertFalse(core_useragent
::is_safari_ios(),
1821 "Browser was incorrectly identified as an iOS safari browser");
1822 $this->assertFalse(core_useragent
::check_safari_ios_version());
1825 // Check iOS Safari.
1827 // New versions should be added here.
1833 if (isset($tests['check_safari_ios_version'])) {
1834 // The test provider has overwritten some of the above checks.
1835 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1836 $versions = $tests['check_safari_ios_version'] +
$versions;
1839 foreach ($versions as $version => $result) {
1840 $this->assertEquals($result, core_useragent
::check_safari_ios_version($version),
1841 "Version incorrectly determined for iOS Safari version '{$version}'");
1846 * @dataProvider user_agents_providers
1848 public function test_useragent_ios($useragent, $tests) {
1849 // Setup the core_useragent instance.
1850 core_useragent
::instance(true, $useragent);
1852 if (isset($tests['is_ios']) && $tests['is_ios']) {
1853 $this->assertTrue(core_useragent
::is_ios(),
1854 "Browser was not identified as an iOS device browser");
1855 // The iOS app is not Safari based.
1856 if (!isset($tests['is_moodle_app']) ||
!$tests['is_moodle_app']) {
1857 $this->assertTrue(core_useragent
::check_safari_ios_version());
1860 $this->assertFalse(core_useragent
::is_ios(),
1861 "Browser was incorrectly identified as an iOS device browser");
1862 $this->assertFalse(core_useragent
::check_safari_ios_version());
1867 * @dataProvider user_agents_providers
1869 public function test_useragent_gecko($useragent, $tests) {
1870 // Setup the core_useragent instance.
1871 core_useragent
::instance(true, $useragent);
1873 if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1874 $this->assertTrue(core_useragent
::is_gecko(),
1875 "Browser was not identified as a gecko browser");
1876 $this->assertTrue(core_useragent
::check_gecko_version());
1878 $this->assertFalse(core_useragent
::is_gecko(),
1879 "Browser was incorrectly identified as a gecko browser");
1880 $this->assertFalse(core_useragent
::check_gecko_version());
1884 // New versions should be added here.
1889 '20030516' => false,
1890 '20051116' => false,
1891 '2006010100' => false,
1892 '20100101' => false,
1898 if (isset($tests['check_gecko_version'])) {
1899 // The test provider has overwritten some of the above checks.
1900 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1901 $versions = $tests['check_gecko_version'] +
$versions;
1904 foreach ($versions as $version => $result) {
1905 $this->assertEquals($result, core_useragent
::check_gecko_version($version),
1906 "Version incorrectly determined for Gecko version '{$version}'");
1911 * @dataProvider user_agents_providers
1913 public function test_useragent_firefox($useragent, $tests) {
1914 // Setup the core_useragent instance.
1915 core_useragent
::instance(true, $useragent);
1917 if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1918 $this->assertTrue(core_useragent
::is_firefox(),
1919 "Browser was not identified as a firefox browser");
1920 $this->assertTrue(core_useragent
::check_firefox_version());
1922 $this->assertFalse(core_useragent
::is_firefox(),
1923 "Browser was incorrectly identified as a firefox browser");
1924 $this->assertFalse(core_useragent
::check_firefox_version());
1928 // New versions should be added here.
1939 if (isset($tests['check_firefox_version'])) {
1940 // The test provider has overwritten some of the above checks.
1941 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1942 $versions = $tests['check_firefox_version'] +
$versions;
1945 foreach ($versions as $version => $result) {
1946 $this->assertEquals($result, core_useragent
::check_firefox_version($version),
1947 "Version incorrectly determined for Firefox version '{$version}'");
1952 * @dataProvider user_agents_providers
1954 public function test_useragent_opera($useragent, $tests) {
1955 // Setup the core_useragent instance.
1956 core_useragent
::instance(true, $useragent);
1958 if (isset($tests['is_opera']) && $tests['is_opera']) {
1959 $this->assertTrue(core_useragent
::is_opera(),
1960 "Browser was not identified as a opera browser");
1961 $this->assertTrue(core_useragent
::check_opera_version());
1963 $this->assertFalse(core_useragent
::is_opera(),
1964 "Browser was incorrectly identified as a opera browser");
1965 $this->assertFalse(core_useragent
::check_opera_version());
1969 // New versions should be added here.
1976 if (isset($tests['check_opera_version'])) {
1977 // The test provider has overwritten some of the above checks.
1978 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1979 $versions = $tests['check_opera_version'] +
$versions;
1982 foreach ($versions as $version => $result) {
1983 $this->assertEquals($result, core_useragent
::check_opera_version($version),
1984 "Version incorrectly determined for Opera version '{$version}'");
1989 * @dataProvider user_agents_providers
1991 public function test_get_device_type($useragent, $tests) {
1992 // Setup the core_useragent instance.
1993 core_useragent
::instance(true, $useragent);
1995 $expected = 'default';
1996 if (isset($tests['devicetype'])) {
1997 $expected = $tests['devicetype'];
2000 $this->assertEquals($expected, core_useragent
::get_device_type(),
2001 "Device Type was not correctly identified");
2005 * @dataProvider user_agents_providers
2007 public function test_get_browser_version_classes($useragent, $tests) {
2008 // Setup the core_useragent instance.
2009 core_useragent
::instance(true, $useragent);
2011 $actual = core_useragent
::get_browser_version_classes();
2012 foreach ($tests['versionclasses'] as $expectedclass) {
2013 $this->assertContains($expectedclass, $actual);
2015 $this->assertCount(count($tests['versionclasses']), $actual);
2019 * @dataProvider user_agents_providers
2021 public function test_useragent_web_crawler($useragent, $tests) {
2022 // Setup the core_useragent instance.
2023 core_useragent
::instance(true, $useragent);
2025 $expectation = isset($tests['is_web_crawler']) ?
$tests['is_web_crawler'] : false;
2026 $this->assertSame($expectation, core_useragent
::is_web_crawler());
2030 * @dataProvider user_agents_providers
2032 public function test_useragent_moodle_app($useragent, $tests) {
2033 // Setup the core_useragent instance.
2034 core_useragent
::instance(true, $useragent);
2036 $expectation = isset($tests['is_moodle_app']) ?
$tests['is_moodle_app'] : false;
2037 $this->assertSame($expectation, core_useragent
::is_moodle_app());