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',
105 // Windows XP; Firefox 1.0.6.
107 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
109 'is_firefox' => true,
112 'check_gecko_version' => array(
116 'versionclasses' => array(
123 // Windows XP; Firefox 1.0.6.
125 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
127 'is_firefox' => true,
128 'check_firefox_version' => array(
133 'check_gecko_version' => array(
139 'versionclasses' => array(
146 // Windows XP; Firefox 1.5.0.1.
148 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
150 'is_firefox' => true,
151 'check_firefox_version' => array(
156 'check_gecko_version' => array(
162 'versionclasses' => array(
169 // Windows XP; Firefox 2.0.
171 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
173 'is_firefox' => true,
174 'check_firefox_version' => array(
179 'check_gecko_version' => array(
184 '2006010100' => true,
187 'versionclasses' => array(
194 // Ubuntu Linux amd64; Firefox 2.0.
196 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
198 'is_firefox' => true,
199 'check_firefox_version' => array(
204 'check_gecko_version' => array(
209 '2006010100' => true,
212 'versionclasses' => array(
219 // SUSE; Firefox 3.0.6.
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',
223 'is_firefox' => true,
224 'check_firefox_version' => array(
230 'check_gecko_version' => array(
235 '2006010100' => true,
238 'versionclasses' => array(
245 // Linux i686; Firefox 3.6.
247 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
249 'is_firefox' => true,
250 'check_firefox_version' => array(
256 'check_gecko_version' => array(
261 '2006010100' => true,
266 'versionclasses' => array(
273 // Windows; Firefox 11.0.
275 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
277 'is_firefox' => true,
278 'check_firefox_version' => array(
286 'check_gecko_version' => array(
291 '2006010100' => true,
297 'versionclasses' => array(
303 // Windows; Firefox 15.0a2.
305 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
307 'is_firefox' => true,
308 'check_firefox_version' => array(
317 'check_gecko_version' => array(
322 '2006010100' => true,
329 'versionclasses' => array(
335 // Firefox 18; Mac OS X 10.
337 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
339 'is_firefox' => true,
340 'check_firefox_version' => array(
350 'check_gecko_version' => array(
355 '2006010100' => true,
363 'versionclasses' => array(
369 // Firefox 33; Mac OS X 10.10.
371 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
373 'is_firefox' => true,
374 'check_firefox_version' => array(
386 'check_gecko_version' => array(
391 '2006010100' => true,
400 'versionclasses' => array(
406 // SeaMonkey 2.0; Windows.
408 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
411 'check_gecko_version' => array(
417 '2006010100' => true,
420 'versionclasses' => array(
427 // SeaMonkey 2.1; Linux.
429 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
432 'check_gecko_version' => array(
437 '2006010100' => true,
443 'is_firefox' => true,
444 'check_firefox_version' => array(
450 'versionclasses' => array(
457 // SeaMonkey 2.3; FreeBSD.
459 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
462 'check_gecko_version' => array(
467 '2006010100' => true,
473 'is_firefox' => true,
474 'check_firefox_version' => array(
480 'versionclasses' => array(
486 // Mac OS X; MS Word 14.
488 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
490 'versionclasses' => array(
497 // Safari 312; Max OS X.
499 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
502 'check_safari_version' => array(
509 'versionclasses' => array(
515 // Safari 412; Max OS X.
517 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
520 'check_safari_version' => array(
527 'versionclasses' => array(
533 // Safari 2.0; Max OS X.
535 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
538 'check_safari_version' => array(
545 'versionclasses' => array(
551 // iOS Safari 528; iPhone.
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',
555 // Note: We do *not* identify mobile Safari as Safari.
556 'is_safari_ios' => true,
558 'check_safari_ios_version' => array(
564 'versionclasses' => array(
568 'devicetype' => 'mobile',
572 // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
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',
576 // Note: We do *not* identify mobile Safari as Safari.
577 'is_safari_ios' => true,
579 'check_safari_ios_version' => array(
587 'versionclasses' => array(
591 'devicetype' => 'mobile',
595 // iOS Safari 533; iPad.
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',
599 // Note: We do *not* identify mobile Safari as Safari.
600 'is_safari_ios' => true,
602 'check_safari_ios_version' => array(
608 'versionclasses' => array(
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',
620 'is_webkit_android' => true,
621 'check_webkit_android_version' => array(
627 'versionclasses' => array(
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',
641 'is_webkit_android' => true,
642 'check_webkit_android_version' => array(
649 'versionclasses' => array(
653 'devicetype' => 'mobile',
655 'supports_svg' => false,
659 // Android WebKit 537; Samsung GT-9505.
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',
663 'is_webkit_android' => true,
664 'check_webkit_android_version' => array(
672 'check_chrome_version' => array(
678 'versionclasses' => array(
683 'devicetype' => 'mobile',
687 // Android WebKit 537; Nexus 5.
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',
691 'is_webkit_android' => true,
692 'check_webkit_android_version' => array(
700 'check_chrome_version' => array(
706 'versionclasses' => array(
711 'devicetype' => 'mobile',
715 // Chrome 8; Mac OS X.
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',
720 'check_chrome_version' => array(
727 'versionclasses' => array(
733 // Chrome 39; Mac OS X.
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',
738 'check_chrome_version' => array(
747 'versionclasses' => array(
753 // Opera 12.15 (Build 1748); Mac OS X.
755 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
758 'check_opera_version' => array(
765 'versionclasses' => array(
771 // Google web crawlers.
773 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
775 'is_web_crawler' => true,
776 'versionclasses' => array(
781 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
783 'is_web_crawler' => true,
784 'versionclasses' => array(
789 'Googlebot-Image/1.0',
791 'is_web_crawler' => true,
792 'versionclasses' => array(
798 // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
800 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
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.
811 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
813 'is_web_crawler' => true,
814 'versionclasses' => array(
819 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
821 'is_web_crawler' => true,
822 'versionclasses' => 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)',
829 'is_web_crawler' => true,
831 'is_safari_ios' => true,
833 'check_safari_ios_version' => array(
837 'versionclasses' => array(
841 'devicetype' => 'mobile',
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)',
847 'is_web_crawler' => true,
849 'check_ie_version' => array(
860 'versionclasses' => array(
864 'devicetype' => 'mobile',
869 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
871 'is_web_crawler' => true,
872 'versionclasses' => array(
879 'is_web_crawler' => true,
880 'versionclasses' => array(
885 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
887 'is_web_crawler' => true,
888 'versionclasses' => array(
893 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
895 'is_web_crawler' => true,
898 'check_safari_version' => array(
904 'versionclasses' => 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',
912 'is_web_crawler' => true,
914 'check_ie_version' => array(
925 'versionclasses' => array(
929 'devicetype' => 'mobile',
934 // See http://help.yandex.com/search/robots/agent.xml.
936 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
938 'is_web_crawler' => true,
939 'versionclasses' => array(
944 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
946 'is_web_crawler' => true,
947 'versionclasses' => array(
954 'AltaVista V2.0B crawler@evreka.com',
956 'is_web_crawler' => true,
957 'versionclasses' => array(
964 'ZoomSpider - wrensoft.com [ZSEBOT]',
966 'is_web_crawler' => true,
967 'versionclasses' => array(
974 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
976 'is_web_crawler' => true,
977 'versionclasses' => array(
982 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
984 'is_web_crawler' => true,
985 'versionclasses' => array(
992 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
994 'is_web_crawler' => true,
995 'versionclasses' => array(
1002 'User-Agent: MoodleBot/3.8 (+https://moodle.org)',
1004 'is_web_crawler' => true,
1005 'versionclasses' => array(
1010 // Macos Desktop app.
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',
1014 'is_moodle_app' => true,
1015 'is_webkit' => true,
1016 'is_chrome' => true,
1017 'check_chrome_version' => array(
1023 'versionclasses' => array(
1029 // Linux Desktop app.
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',
1033 'is_moodle_app' => true,
1034 'is_webkit' => true,
1035 'is_chrome' => true,
1036 'check_chrome_version' => array(
1042 'versionclasses' => array(
1048 // Windows Desktop app.
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',
1052 'is_moodle_app' => true,
1053 'is_webkit' => true,
1054 'is_chrome' => true,
1055 'check_chrome_version' => array(
1061 'versionclasses' => 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',
1071 'is_moodle_app' => true,
1072 'is_webkit' => true,
1073 'is_webkit_android' => true,
1074 'is_chrome' => true,
1075 'check_chrome_version' => array(
1081 'devicetype' => 'mobile',
1082 'check_webkit_android_version' => array(
1086 'versionclasses' => array(
1093 // Android app, user agent lower case.
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',
1097 'is_moodle_app' => true,
1098 'is_webkit' => true,
1099 'is_webkit_android' => true,
1100 'is_chrome' => true,
1101 'check_chrome_version' => array(
1107 'devicetype' => 'mobile',
1108 'check_webkit_android_version' => array(
1112 'versionclasses' => array(
1119 // iOS (iPhone) app.
1121 'Mozilla/5.0 (iPhone; CPU OS 13_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MoodleMobile',
1123 'is_moodle_app' => true,
1125 'is_webkit' => true,
1126 'devicetype' => 'mobile',
1127 'versionclasses' => 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',
1136 'is_moodle_app' => 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);
1163 if (isset($tests['is_edge']) && $tests['is_edge']) {
1164 $this->assertTrue(core_useragent
::is_edge());
1166 $this->assertFalse(core_useragent
::is_edge());
1170 // New versions of should be added here.
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);
1194 if (isset($tests['is_ie']) && $tests['is_ie']) {
1195 $this->assertTrue(core_useragent
::is_ie());
1197 $this->assertFalse(core_useragent
::is_ie());
1201 // New versions of should be added here.
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");
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);
1244 if (isset($tests['is_msword']) && $tests['is_msword']) {
1245 $this->assertTrue(core_useragent
::is_msword());
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);
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)");
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)");
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());
1289 $this->assertFalse(core_useragent
::is_webkit(),
1290 "Browser was incorrectly identified as a webkit browser");
1291 $this->assertFalse(core_useragent
::check_webkit_version());
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());
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());
1328 // New versions should be added here.
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());
1358 $this->assertFalse(core_useragent
::is_chrome(),
1359 "Browser was incorrectly identified as a chrome browser");
1360 $this->assertFalse(core_useragent
::check_chrome_version());
1364 // New versions should be added here.
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());
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).
1402 // New versions should be added here.
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());
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.
1439 // New versions should be added here.
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());
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());
1490 $this->assertFalse(core_useragent
::is_gecko(),
1491 "Browser was incorrectly identified as a gecko browser");
1492 $this->assertFalse(core_useragent
::check_gecko_version());
1496 // New versions should be added here.
1501 '20030516' => false,
1502 '20051116' => false,
1503 '2006010100' => false,
1504 '20100101' => 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());
1534 $this->assertFalse(core_useragent
::is_firefox(),
1535 "Browser was incorrectly identified as a firefox browser");
1536 $this->assertFalse(core_useragent
::check_firefox_version());
1540 // New versions should be added here.
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());
1575 $this->assertFalse(core_useragent
::is_opera(),
1576 "Browser was incorrectly identified as a opera browser");
1577 $this->assertFalse(core_useragent
::check_opera_version());
1581 // New versions should be added here.
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());