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 * Tests the user agent class.
21 * @copyright 2013 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 * User agent test suite.
29 * @copyright 2013 Sam Hemelryk
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class core_useragent_testcase
extends basic_testcase
{
34 public function user_agents_providers() {
35 // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list.
36 // This ensures that regression tests are applied to all known user agents.
38 // Windows 98; Internet Explorer 5.0.
40 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
42 // MSIE 5.0 is not considered a browser at all: known false results.
44 'check_ie_version' => array(
48 'versionclasses' => array(
49 // IE 5.0 is not considered a browser.
52 // IE 5.0 is a legacy browser.
53 'devicetype' => 'legacy',
55 'supports_svg' => false,
56 'supports_json_contenttype' => false,
60 // Windows 2000; Internet Explorer 5.5.
62 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
65 'check_ie_version' => array(
70 'versionclasses' => array(
74 // IE 6.0 is a legacy browser.
75 'devicetype' => 'legacy',
77 'supports_svg' => false,
78 'supports_json_contenttype' => false,
82 // Windows XP SP2; Internet Explorer 6.0.
84 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
87 'check_ie_version' => array(
93 'versionclasses' => array(
98 // IE 7.0 is a legacy browser.
99 'devicetype' => 'legacy',
101 'supports_svg' => false,
102 'supports_json_contenttype' => false,
106 // Windows XP SP2; Internet Explorer 7.0.
108 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
111 'check_ie_version' => array(
118 'versionclasses' => array(
123 'supports_svg' => false,
124 'supports_json_contenttype' => false,
128 // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
130 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Meridio for Excel 5.0.251; Meridio for PowerPoint 5.0.251; Meridio for Word 5.0.251; Meridio Protocol; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)',
133 'check_ie_version' => array(
140 'versionclasses' => array(
145 'supports_svg' => false,
146 'supports_json_contenttype' => false,
150 // Windows Vista; Internet Explorer 8.0.
152 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)',
155 'check_ie_version' => array(
163 'versionclasses' => array(
168 'supports_svg' => false,
172 // Windows 7; Internet Explorer 9.0.
174 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
177 'check_ie_version' => array(
186 'versionclasses' => array(
193 // Windows 7; Internet Explorer 9.0i.
195 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)',
198 'check_ie_version' => array(
207 'versionclasses' => array(
211 'iecompatibility' => true,
213 // IE 9 in Compatiblity mode does not support SVG.
214 'supports_svg' => false,
216 // IE in Compatiblity mode does not support JSON ContentType.
217 'supports_json_contenttype' => false,
221 // Windows 8; Internet Explorer 10.0.
223 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
226 'check_ie_version' => array(
236 'versionclasses' => array(
243 // Windows 8; Internet Explorer 10.0i.
245 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
248 'check_ie_version' => array(
258 'iecompatibility' => true,
259 'versionclasses' => array(
264 // IE in Compatiblity mode does not support JSON ContentType.
265 'supports_json_contenttype' => false,
269 // Windows 8.1; Internet Explorer 11.0.
271 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
274 'check_ie_version' => array(
285 'versionclasses' => array(
292 // Windows 8.1; Internet Explorer 11.0i.
294 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
297 'check_ie_version' => array(
308 'iecompatibility' => true,
309 'versionclasses' => array(
314 // IE in Compatiblity mode does not support JSON ContentType.
315 'supports_json_contenttype' => false,
319 // Windows XP; Firefox 1.0.6.
321 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
323 'is_firefox' => true,
326 'check_gecko_version' => array(
330 'versionclasses' => array(
337 // Windows XP; Firefox 1.0.6.
339 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
341 'is_firefox' => true,
342 'check_firefox_version' => array(
347 'check_gecko_version' => array(
353 'versionclasses' => array(
360 // Windows XP; Firefox 1.5.0.1.
362 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
364 'is_firefox' => true,
365 'check_firefox_version' => array(
370 'check_gecko_version' => array(
376 'versionclasses' => array(
383 // Windows XP; Firefox 2.0.
385 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
387 'is_firefox' => true,
388 'check_firefox_version' => array(
393 'check_gecko_version' => array(
398 '2006010100' => true,
401 'versionclasses' => array(
408 // Ubuntu Linux amd64; Firefox 2.0.
410 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
412 'is_firefox' => true,
413 'check_firefox_version' => array(
418 'check_gecko_version' => array(
423 '2006010100' => true,
426 'versionclasses' => array(
433 // SUSE; Firefox 3.0.6.
435 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.4 Firefox/3.0.6',
437 'is_firefox' => true,
438 'check_firefox_version' => array(
444 'check_gecko_version' => array(
449 '2006010100' => true,
452 'versionclasses' => array(
459 // Linux i686; Firefox 3.6.
461 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
463 'is_firefox' => true,
464 'check_firefox_version' => array(
470 'check_gecko_version' => array(
475 '2006010100' => true,
480 'versionclasses' => array(
487 // Windows; Firefox 11.0.
489 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
491 'is_firefox' => true,
492 'check_firefox_version' => array(
500 'check_gecko_version' => array(
505 '2006010100' => true,
511 'versionclasses' => array(
517 // Windows; Firefox 15.0a2.
519 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
521 'is_firefox' => true,
522 'check_firefox_version' => array(
531 'check_gecko_version' => array(
536 '2006010100' => true,
543 'versionclasses' => array(
549 // Firefox 18; Mac OS X 10.
551 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
553 'is_firefox' => true,
554 'check_firefox_version' => array(
564 'check_gecko_version' => array(
569 '2006010100' => true,
577 'versionclasses' => array(
583 // Firefox 33; Mac OS X 10.10.
585 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
587 'is_firefox' => true,
588 'check_firefox_version' => array(
600 'check_gecko_version' => array(
605 '2006010100' => true,
614 'versionclasses' => array(
620 // SeaMonkey 2.0; Windows.
622 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
625 'check_gecko_version' => array(
631 '2006010100' => true,
634 'versionclasses' => array(
641 // SeaMonkey 2.1; Linux.
643 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
646 'check_gecko_version' => array(
651 '2006010100' => true,
657 'is_firefox' => true,
658 'check_firefox_version' => array(
664 'versionclasses' => array(
671 // SeaMonkey 2.3; FreeBSD.
673 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
676 'check_gecko_version' => array(
681 '2006010100' => true,
687 'is_firefox' => true,
688 'check_firefox_version' => array(
694 'versionclasses' => array(
700 // Windows 7; MS Word 2010.
702 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; ms-office)',
705 'check_ie_version' => array(
713 'iecompatibility' => true,
714 'versionclasses' => array(
721 'supports_svg' => false,
722 'supports_json_contenttype' => false,
726 // Windows 7; MS Outlook 2010.
728 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Microsoft Outlook 14.0.7113; ms-office; MSOffice 14)',
731 'check_ie_version' => array(
739 'iecompatibility' => true,
740 'versionclasses' => array(
745 // Note: Outlook is deliberately not considered to be MS Word.
746 'is_msword' => false,
748 'supports_svg' => false,
749 'supports_json_contenttype' => false,
753 // Mac OS X; MS Word 14.
755 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
757 'versionclasses' => array(
764 // Safari 312; Max OS X.
766 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
769 'check_safari_version' => array(
776 'versionclasses' => array(
782 // Safari 412; Max OS X.
784 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
787 'check_safari_version' => array(
794 'versionclasses' => array(
800 // Safari 2.0; Max OS X.
802 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
805 'check_safari_version' => array(
812 'versionclasses' => array(
818 // iOS Safari 528; iPhone.
820 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; cs-cz) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16',
822 // Note: We do *not* identify mobile Safari as Safari.
823 'is_safari_ios' => true,
824 'check_safari_ios_version' => array(
830 'versionclasses' => array(
835 'devicetype' => 'mobile',
839 // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
841 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_10 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4',
843 // Note: We do *not* identify mobile Safari as Safari.
844 'is_safari_ios' => true,
845 'check_safari_ios_version' => array(
853 'versionclasses' => array(
858 'devicetype' => 'mobile',
862 // iOS Safari 533; iPad.
864 'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5',
866 // Note: We do *not* identify mobile Safari as Safari.
867 'is_safari_ios' => true,
868 'check_safari_ios_version' => array(
874 'versionclasses' => array(
879 'devicetype' => 'tablet',
883 // Android WebKit 525; G1 Phone.
885 'Mozilla/5.0 (Linux; U; Android 1.1; en-gb; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 – G1 Phone',
887 'is_webkit_android' => true,
888 'check_webkit_android_version' => array(
894 'versionclasses' => array(
899 'devicetype' => 'mobile',
901 'supports_svg' => false,
905 // Android WebKit 530; Nexus.
907 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 –Nexus',
909 'is_webkit_android' => true,
910 'check_webkit_android_version' => array(
917 'versionclasses' => array(
922 'devicetype' => 'mobile',
924 'supports_svg' => false,
928 // Android WebKit 537; Samsung GT-9505.
930 'Mozilla/5.0 (Linux; Android 4.3; it-it; SAMSUNG GT-I9505/I9505XXUEMJ7 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36',
932 'is_webkit_android' => true,
933 'check_webkit_android_version' => array(
941 'check_chrome_version' => array(
947 'versionclasses' => array(
952 'devicetype' => 'mobile',
956 // Android WebKit 537; Nexus 5.
958 'Mozilla/5.0 (Linux; Android 5.0; Nexus 5 Build/LPX13D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.102 Mobile Safari/537.36',
960 'is_webkit_android' => true,
961 'check_webkit_android_version' => array(
969 'check_chrome_version' => array(
975 'versionclasses' => array(
980 'devicetype' => 'mobile',
984 // Chrome 8; Mac OS X.
986 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10',
989 'check_chrome_version' => array(
996 'versionclasses' => array(
1002 // Chrome 39; Mac OS X.
1004 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
1006 'is_chrome' => true,
1007 'check_chrome_version' => array(
1014 'is_webkit' => true,
1016 'versionclasses' => array(
1022 // Opera 8.51; Windows XP.
1024 'Opera/8.51 (Windows NT 5.1; U; en)',
1027 'check_opera_version' => array(
1031 'versionclasses' => array(
1035 'supports_svg' => false,
1039 // Opera 9.0; Windows XP.
1041 'Opera/9.0 (Windows NT 5.1; U; en)',
1044 'check_opera_version' => array(
1049 'versionclasses' => array(
1053 'supports_svg' => false,
1057 // Opera 12.15 (Build 1748); Mac OS X.
1059 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
1062 'check_opera_version' => array(
1069 'versionclasses' => array(
1073 'supports_svg' => false,
1077 // Opera 9.0; Debian Linux.
1079 'Opera/9.01 (X11; Linux i686; U; en)',
1082 'check_opera_version' => array(
1087 'versionclasses' => array(
1091 'supports_svg' => false,
1098 * Test instance generation.
1100 public function test_instance() {
1101 $this->assertInstanceOf('core_useragent', core_useragent
::instance());
1102 $this->assertInstanceOf('core_useragent', core_useragent
::instance(true));
1106 * @dataProvider user_agents_providers
1108 public function test_useragent_ie($useragent, $tests) {
1109 // Setup the core_useragent instance.
1110 core_useragent
::instance(true, $useragent);
1113 if (isset($tests['is_ie']) && $tests['is_ie']) {
1114 $this->assertTrue(core_useragent
::is_ie());
1116 $this->assertFalse(core_useragent
::is_ie());
1120 // New versions of should be added here.
1135 if (isset($tests['check_ie_version'])) {
1136 // The test provider has overwritten some of the above checks.
1137 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1138 $versions = $tests['check_ie_version'] +
$versions;
1141 foreach ($versions as $version => $result) {
1142 $this->assertEquals($result, core_useragent
::check_ie_version($version),
1143 "Version incorrectly determined for IE version '{$version}'");
1146 // IE Compatibility mode.
1147 if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1148 $this->assertTrue(core_useragent
::check_ie_compatibility_view(), "IE Compability false negative");
1150 $this->assertFalse(core_useragent
::check_ie_compatibility_view(), "IE Compability false positive");
1156 * @dataProvider user_agents_providers
1158 public function test_useragent_msword($useragent, $tests) {
1159 // Setup the core_useragent instance.
1160 core_useragent
::instance(true, $useragent);
1163 if (isset($tests['is_msword']) && $tests['is_msword']) {
1164 $this->assertTrue(core_useragent
::is_msword());
1166 $this->assertFalse(core_useragent
::is_msword());
1172 * @dataProvider user_agents_providers
1174 public function test_useragent_supports($useragent, $tests) {
1175 // Setup the core_useragent instance.
1176 core_useragent
::instance(true, $useragent);
1179 if (!isset($tests['supports_svg']) ||
$tests['supports_svg']) {
1180 $this->assertTrue(core_useragent
::supports_svg(),
1181 "SVG Support was not reported (and should have been)");
1183 $this->assertFalse(core_useragent
::supports_svg(),
1184 "SVG Support was reported (and should not have been)");
1187 // Supports JSON ContentType.
1188 if (!isset($tests['supports_json_contenttype']) ||
$tests['supports_json_contenttype']) {
1189 $this->assertTrue(core_useragent
::supports_json_contenttype(),
1190 "JSON ContentType Support was not reported (and should have been)");
1192 $this->assertFalse(core_useragent
::supports_json_contenttype(),
1193 "JSON ContentType Support was reported (and should not have been)");
1198 * @dataProvider user_agents_providers
1200 public function test_useragent_webkit($useragent, $tests) {
1201 // Setup the core_useragent instance.
1202 core_useragent
::instance(true, $useragent);
1204 if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1205 $this->assertTrue(core_useragent
::is_webkit(),
1206 "Browser was not identified as a webkit browser");
1207 $this->assertTrue(core_useragent
::check_webkit_version());
1209 $this->assertFalse(core_useragent
::is_webkit(),
1210 "Browser was incorrectly identified as a webkit browser");
1211 $this->assertFalse(core_useragent
::check_webkit_version());
1215 // New versions should be added here.
1218 if (isset($tests['check_webkit_version'])) {
1219 // The test provider has overwritten some of the above checks.
1220 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1221 $versions = $tests['check_webkit_version'] +
$versions;
1224 foreach ($versions as $version => $result) {
1225 $this->assertEquals($result, core_useragent
::check_webkit_version($version),
1226 "Version incorrectly determined for Webkit version '{$version}'");
1231 * @dataProvider user_agents_providers
1233 public function test_useragent_webkit_android($useragent, $tests) {
1234 // Setup the core_useragent instance.
1235 core_useragent
::instance(true, $useragent);
1237 if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1238 $this->assertTrue(core_useragent
::is_webkit_android(),
1239 "Browser was not identified as an Android webkit browser");
1240 $this->assertTrue(core_useragent
::check_webkit_android_version());
1242 $this->assertFalse(core_useragent
::is_webkit_android(),
1243 "Browser was incorrectly identified as an Android webkit browser");
1244 $this->assertFalse(core_useragent
::check_webkit_android_version());
1248 // New versions should be added here.
1254 if (isset($tests['check_webkit_android_version'])) {
1255 // The test provider has overwritten some of the above checks.
1256 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1257 $versions = $tests['check_webkit_android_version'] +
$versions;
1260 foreach ($versions as $version => $result) {
1261 $this->assertEquals($result, core_useragent
::check_webkit_android_version($version),
1262 "Version incorrectly determined for Android webkit version '{$version}'");
1267 * @dataProvider user_agents_providers
1269 public function test_useragent_chrome($useragent, $tests) {
1270 // Setup the core_useragent instance.
1271 core_useragent
::instance(true, $useragent);
1273 if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1274 $this->assertTrue(core_useragent
::is_chrome(),
1275 "Browser was not identified as a chrome browser");
1276 $this->assertTrue(core_useragent
::check_chrome_version());
1278 $this->assertFalse(core_useragent
::is_chrome(),
1279 "Browser was incorrectly identified as a chrome browser");
1280 $this->assertFalse(core_useragent
::check_chrome_version());
1284 // New versions should be added here.
1291 if (isset($tests['check_chrome_version'])) {
1292 // The test provider has overwritten some of the above checks.
1293 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1294 $versions = $tests['check_chrome_version'] +
$versions;
1297 foreach ($versions as $version => $result) {
1298 $this->assertEquals($result, core_useragent
::check_chrome_version($version),
1299 "Version incorrectly determined for Chrome version '{$version}'");
1304 * @dataProvider user_agents_providers
1306 public function test_useragent_safari($useragent, $tests) {
1307 // Setup the core_useragent instance.
1308 core_useragent
::instance(true, $useragent);
1310 if (isset($tests['is_safari']) && $tests['is_safari']) {
1311 $this->assertTrue(core_useragent
::is_safari(),
1312 "Browser was not identified as a safari browser");
1313 $this->assertTrue(core_useragent
::check_safari_version());
1315 $this->assertFalse(core_useragent
::is_safari(),
1316 "Browser was incorrectly identified as a safari browser");
1317 $this->assertFalse(core_useragent
::check_safari_version());
1320 // Check Safari (generic).
1322 // New versions should be added here.
1328 if (isset($tests['check_safari_version'])) {
1329 // The test provider has overwritten some of the above checks.
1330 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1331 $versions = $tests['check_safari_version'] +
$versions;
1334 foreach ($versions as $version => $result) {
1335 $this->assertEquals($result, core_useragent
::check_safari_version($version),
1336 "Version incorrectly determined for Safari (generic) version '{$version}'");
1341 * @dataProvider user_agents_providers
1343 public function test_useragent_ios_safari($useragent, $tests) {
1344 // Setup the core_useragent instance.
1345 core_useragent
::instance(true, $useragent);
1347 if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1348 $this->assertTrue(core_useragent
::is_safari_ios(),
1349 "Browser was not identified as an iOS safari browser");
1350 $this->assertTrue(core_useragent
::check_safari_ios_version());
1352 $this->assertFalse(core_useragent
::is_safari_ios(),
1353 "Browser was incorrectly identified as an iOS safari browser");
1354 $this->assertFalse(core_useragent
::check_safari_ios_version());
1357 // Check iOS Safari.
1359 // New versions should be added here.
1365 if (isset($tests['check_safari_ios_version'])) {
1366 // The test provider has overwritten some of the above checks.
1367 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1368 $versions = $tests['check_safari_ios_version'] +
$versions;
1371 foreach ($versions as $version => $result) {
1372 $this->assertEquals($result, core_useragent
::check_safari_ios_version($version),
1373 "Version incorrectly determined for iOS Safari version '{$version}'");
1378 * @dataProvider user_agents_providers
1380 public function test_useragent_gecko($useragent, $tests) {
1381 // Setup the core_useragent instance.
1382 core_useragent
::instance(true, $useragent);
1384 if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1385 $this->assertTrue(core_useragent
::is_gecko(),
1386 "Browser was not identified as a gecko browser");
1387 $this->assertTrue(core_useragent
::check_gecko_version());
1389 $this->assertFalse(core_useragent
::is_gecko(),
1390 "Browser was incorrectly identified as a gecko browser");
1391 $this->assertFalse(core_useragent
::check_gecko_version());
1395 // New versions should be added here.
1400 '20030516' => false,
1401 '20051116' => false,
1402 '2006010100' => false,
1403 '20100101' => false,
1409 if (isset($tests['check_gecko_version'])) {
1410 // The test provider has overwritten some of the above checks.
1411 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1412 $versions = $tests['check_gecko_version'] +
$versions;
1415 foreach ($versions as $version => $result) {
1416 $this->assertEquals($result, core_useragent
::check_gecko_version($version),
1417 "Version incorrectly determined for Gecko version '{$version}'");
1422 * @dataProvider user_agents_providers
1424 public function test_useragent_firefox($useragent, $tests) {
1425 // Setup the core_useragent instance.
1426 core_useragent
::instance(true, $useragent);
1428 if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1429 $this->assertTrue(core_useragent
::is_firefox(),
1430 "Browser was not identified as a firefox browser");
1431 $this->assertTrue(core_useragent
::check_firefox_version());
1433 $this->assertFalse(core_useragent
::is_firefox(),
1434 "Browser was incorrectly identified as a firefox browser");
1435 $this->assertFalse(core_useragent
::check_firefox_version());
1439 // New versions should be added here.
1450 if (isset($tests['check_firefox_version'])) {
1451 // The test provider has overwritten some of the above checks.
1452 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1453 $versions = $tests['check_firefox_version'] +
$versions;
1456 foreach ($versions as $version => $result) {
1457 $this->assertEquals($result, core_useragent
::check_firefox_version($version),
1458 "Version incorrectly determined for Firefox version '{$version}'");
1463 * @dataProvider user_agents_providers
1465 public function test_useragent_opera($useragent, $tests) {
1466 // Setup the core_useragent instance.
1467 core_useragent
::instance(true, $useragent);
1469 if (isset($tests['is_opera']) && $tests['is_opera']) {
1470 $this->assertTrue(core_useragent
::is_opera(),
1471 "Browser was not identified as a opera browser");
1472 $this->assertTrue(core_useragent
::check_opera_version());
1474 $this->assertFalse(core_useragent
::is_opera(),
1475 "Browser was incorrectly identified as a opera browser");
1476 $this->assertFalse(core_useragent
::check_opera_version());
1480 // New versions should be added here.
1487 if (isset($tests['check_opera_version'])) {
1488 // The test provider has overwritten some of the above checks.
1489 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1490 $versions = $tests['check_opera_version'] +
$versions;
1493 foreach ($versions as $version => $result) {
1494 $this->assertEquals($result, core_useragent
::check_opera_version($version),
1495 "Version incorrectly determined for Opera version '{$version}'");
1500 * @dataProvider user_agents_providers
1502 public function test_get_device_type($useragent, $tests) {
1503 // Setup the core_useragent instance.
1504 core_useragent
::instance(true, $useragent);
1506 $expected = 'default';
1507 if (isset($tests['devicetype'])) {
1508 $expected = $tests['devicetype'];
1511 $this->assertEquals($expected, core_useragent
::get_device_type(),
1512 "Device Type was not correctly identified");
1516 * @dataProvider user_agents_providers
1518 public function test_get_browser_version_classes($useragent, $tests) {
1519 // Setup the core_useragent instance.
1520 core_useragent
::instance(true, $useragent);
1522 $actual = core_useragent
::get_browser_version_classes();
1523 foreach ($tests['versionclasses'] as $expectedclass) {
1524 $this->assertContains($expectedclass, $actual);
1526 $this->assertCount(count($tests['versionclasses']), $actual);