MDL-48685 tests: Rewrite useragent tests
[moodle.git] / lib / tests / useragent_test.php
CommitLineData
c3d2fbf9
SH
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
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/>.
16
17/**
18 * Tests the user agent class.
19 *
20 * @package core
21 * @copyright 2013 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25/**
26 * User agent test suite.
27 *
28 * @package core
29 * @copyright 2013 Sam Hemelryk
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 */
32class core_useragent_testcase extends basic_testcase {
33
7c10ad33
AN
34 public function user_agents_providers() {
35 return array(
36 // Windows 98; Internet Explorer 5.0.
37 array(
38 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
39 array(
40 // MSIE 5.0 is not considered a browser at all: known false results.
41 'is_ie' => false,
42 'check_ie_version' => array(
43 '0' => true,
44 '5.0' => true,
45 ),
46 'versionclasses' => array(
47 // IE 5.0 is not considered a browser.
48 ),
49
50 // IE 5.0 is a legacy browser.
51 // TODO Why is this not legacy!?
52 //'devicetype' => 'legacy',
53
54 'supports_svg' => false,
55 ),
c3d2fbf9 56 ),
7c10ad33
AN
57
58 // Windows 2000; Internet Explorer 5.5.
59 array(
60 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
61 array(
62 'is_ie' => true,
63 'check_ie_version' => array(
64 '0' => true,
65 '5.0' => true,
66 '5.5' => true,
67 ),
68 'versionclasses' => array(
69 'ie',
70 ),
71
72 // IE 6.0 is a legacy browser.
73 // TODO Why is this not legacy!?
74 //'devicetype' => 'legacy',
75
76 'supports_svg' => false,
77 ),
c3d2fbf9 78 ),
7c10ad33
AN
79
80 // Windows XP SP2; Internet Explorer 6.0.
81 array(
82 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
83 array(
84 'is_ie' => true,
85 'check_ie_version' => array(
86 '0' => true,
87 '5.0' => true,
88 '5.5' => true,
89 '6.0' => true,
90 ),
91 'versionclasses' => array(
92 'ie',
93 'ie6',
94 ),
95
96 // IE 7.0 is a legacy browser.
97 'devicetype' => 'legacy',
98
99 'supports_svg' => false,
100 ),
c3d2fbf9 101 ),
7c10ad33
AN
102
103 // Windows XP SP2; Internet Explorer 7.0.
104 array(
105 '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)',
106 array(
107 'is_ie' => true,
108 'check_ie_version' => array(
109 '0' => true,
110 '5.0' => true,
111 '5.5' => true,
112 '6.0' => true,
113 '7.0' => true,
114 ),
115 'versionclasses' => array(
116 'ie',
117 'ie7',
118 ),
119
120 'supports_svg' => false,
121 ),
c3d2fbf9 122 ),
7c10ad33
AN
123
124 // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
125 array(
126 '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)',
127 array(
128 'is_ie' => true,
129 'check_ie_version' => array(
130 '0' => true,
131 '5.0' => true,
132 '5.5' => true,
133 '6.0' => true,
134 '7.0' => true,
135 ),
136 'versionclasses' => array(
137 'ie',
138 'ie7',
139 ),
140
141 'supports_svg' => false,
142 ),
d2fdad7c 143 ),
7c10ad33
AN
144
145 // Windows Vista; Internet Explorer 8.0.
146 array(
147 '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)',
148 array(
149 'is_ie' => true,
150 'check_ie_version' => array(
151 '0' => true,
152 '5.0' => true,
153 '5.5' => true,
154 '6.0' => true,
155 '7.0' => true,
156 '8.0' => true,
157 ),
158 'iecompatibility' => false,
159 'versionclasses' => array(
160 'ie',
161 'ie8',
162 ),
163
164 'supports_svg' => false,
165 ),
c3d2fbf9 166 ),
7c10ad33
AN
167
168 // Windows 7; Internet Explorer 9.0.
169 array(
170 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
171 array(
172 'is_ie' => true,
173 'check_ie_version' => array(
174 '0' => true,
175 '5.0' => true,
176 '5.5' => true,
177 '6.0' => true,
178 '7.0' => true,
179 '8.0' => true,
180 '9.0' => true,
181 ),
182 'versionclasses' => array(
183 'ie',
184 'ie9',
185 ),
186 ),
c3d2fbf9 187 ),
7c10ad33
AN
188
189 // Windows 7; Internet Explorer 9.0i.
190 array(
191 '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)',
192 array(
193 'is_ie' => true,
194 'check_ie_version' => array(
195 '0' => true,
196 '5.0' => true,
197 '5.5' => true,
198 '6.0' => true,
199 '7.0' => true,
200 '8.0' => true,
201 '9.0' => true,
202 ),
203 'versionclasses' => array(
204 'ie',
205 'ie9',
206 ),
207 'iecompatibility' => true,
208
209 // IE 9 in Compatiblity mode does not support SVG.
210 'supports_svg' => false,
211 ),
c3d2fbf9 212 ),
7c10ad33
AN
213
214 // Windows 8; Internet Explorer 10.0.
215 array(
216 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
217 array(
218 'is_ie' => true,
219 'check_ie_version' => array(
220 '0' => true,
221 '5.0' => true,
222 '5.5' => true,
223 '6.0' => true,
224 '7.0' => true,
225 '8.0' => true,
226 '9.0' => true,
227 '10' => true,
228 ),
229 'versionclasses' => array(
230 'ie',
231 'ie10',
232 ),
233 ),
c3d2fbf9 234 ),
c3d2fbf9 235
7c10ad33
AN
236 // Windows 8; Internet Explorer 10.0i.
237 array(
238 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
239 array(
240 'is_ie' => true,
241 'check_ie_version' => array(
242 '0' => true,
243 '5.0' => true,
244 '5.5' => true,
245 '6.0' => true,
246 '7.0' => true,
247 '8.0' => true,
248 '9.0' => true,
249 '10' => true,
250 ),
251 'iecompatibility' => true,
252 'versionclasses' => array(
253 'ie',
254 'ie10',
255 ),
256 ),
257 ),
c3d2fbf9 258
7c10ad33
AN
259 // Windows 8.1; Internet Explorer 11.0.
260 array(
261 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
262 array(
263 'is_ie' => true,
264 'check_ie_version' => array(
265 '0' => true,
266 '5.0' => true,
267 '5.5' => true,
268 '6.0' => true,
269 '7.0' => true,
270 '8.0' => true,
271 '9.0' => true,
272 '10' => true,
273 '11' => true,
274 ),
275 'versionclasses' => array(
276 'ie',
277 'ie11',
278 ),
279 ),
280 ),
c3d2fbf9 281
7c10ad33
AN
282 // Windows 8.1; Internet Explorer 11.0i.
283 array(
284 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
285 array(
286 'is_ie' => true,
287 'check_ie_version' => array(
288 '0' => true,
289 '5.0' => true,
290 '5.5' => true,
291 '6.0' => true,
292 '7.0' => true,
293 '8.0' => true,
294 '9.0' => true,
295 '10' => true,
296 '11' => true,
297 ),
298 'iecompatibility' => true,
299 'versionclasses' => array(
300 'ie',
301 'ie11',
302 ),
303 ),
304 ),
305
306 // Windows XP; Firefox 1.0.6.
307 array(
308 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
309 array(
310 'is_firefox' => true,
311
312 'is_gecko' => true,
313 'check_gecko_version' => array(
314 '1' => true,
315 ),
316
317 'versionclasses' => array(
318 'gecko',
319 'gecko17',
320 ),
321 ),
322 ),
323
324 // Windows XP; Firefox 1.0.6.
325 array(
326 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
327 array(
328 'is_firefox' => true,
329 'check_firefox_version' => array(
330 '1.5' => true,
331 ),
332
333 'is_gecko' => true,
334 'check_gecko_version' => array(
335 '1' => true,
336 '20030516' => true,
337 '20051116' => true,
338 ),
339
340 'versionclasses' => array(
341 'gecko',
342 'gecko18',
343 ),
344 ),
345 ),
346
347 // Windows XP; Firefox 1.5.0.1.
348 array(
349 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
350 array(
351 'is_firefox' => true,
352 'check_firefox_version' => array(
353 '1.5' => true,
354 ),
355
356 'is_gecko' => true,
357 'check_gecko_version' => array(
358 '1' => true,
359 '20030516' => true,
360 '20051116' => true,
361 ),
362
363 'versionclasses' => array(
364 'gecko',
365 'gecko18',
366 ),
367 ),
368 ),
369
370 // Windows XP; Firefox 2.0.
371 array(
372 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
373 array(
374 'is_firefox' => true,
375 'check_firefox_version' => array(
376 '1.5' => true,
377 ),
378
379 'is_gecko' => true,
380 'check_gecko_version' => array(
381 '1' => true,
382 '2' => true,
383 '20030516' => true,
384 '20051116' => true,
385 '2006010100' => true,
386 ),
387
388 'versionclasses' => array(
389 'gecko',
390 'gecko18',
391 ),
392 ),
393 ),
394
395 // Ubuntu Linux amd64; Firefox 2.0.
396 array(
397 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
398 array(
399 'is_firefox' => true,
400 'check_firefox_version' => array(
401 '1.5' => true,
402 ),
403
404 'is_gecko' => true,
405 'check_gecko_version' => array(
406 '1' => true,
407 '2' => true,
408 '20030516' => true,
409 '20051116' => true,
410 '2006010100' => true,
411 ),
412
413 'versionclasses' => array(
414 'gecko',
415 'gecko18',
416 ),
417 ),
418 ),
419
420 // SUSE; Firefox 3.0.6.
421 array(
422 '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',
423 array(
424 'is_firefox' => true,
425 'check_firefox_version' => array(
426 '1.5' => true,
427 '3.0' => true,
428 ),
429
430 'is_gecko' => true,
431 'check_gecko_version' => array(
432 '1' => true,
433 '2' => true,
434 '20030516' => true,
435 '20051116' => true,
436 '2006010100' => true,
437 ),
438
439 'versionclasses' => array(
440 'gecko',
441 'gecko19',
442 ),
443 ),
444 ),
445
446 // Linux i686; Firefox 3.6.
447 array(
448 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
449 array(
450 'is_firefox' => true,
451 'check_firefox_version' => array(
452 '1.5' => true,
453 '3.0' => true,
454 ),
455
456 'is_gecko' => true,
457 'check_gecko_version' => array(
458 '1' => true,
459 '2' => true,
460 '20030516' => true,
461 '20051116' => true,
462 '2006010100' => true,
463 '3.6' => true,
464 ),
465
466 'versionclasses' => array(
467 'gecko',
468 'gecko20',
469 ),
470 ),
471 ),
472
473 // Windows; Firefox 11.0.
474 array(
475 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
476 array(
477 'is_firefox' => true,
478 'check_firefox_version' => array(
479 '1.5' => true,
480 '3.0' => true,
481 '4' => true,
482 '10' => true,
483 ),
484
485 'is_gecko' => true,
486 'check_gecko_version' => array(
487 '1' => true,
488 '2' => true,
489 '20030516' => true,
490 '20051116' => true,
491 '2006010100' => true,
492 '3.6' => true,
493 '4.0' => true,
494 ),
495
496 'versionclasses' => array(
497 'gecko',
498 ),
499 ),
500 ),
501
502 // Windows; Firefox 15.0a2.
503 array(
504 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
505 array(
506 'is_firefox' => true,
507 'check_firefox_version' => array(
508 '1.5' => true,
509 '3.0' => true,
510 '4' => true,
511 '10' => true,
512 '15' => true,
513 ),
514
515 'is_gecko' => true,
516 'check_gecko_version' => array(
517 '1' => true,
518 '2' => true,
519 '20030516' => true,
520 '20051116' => true,
521 '2006010100' => true,
522 '3.6' => true,
523 '4.0' => true,
524 '15.0' => true,
525 ),
526
527 'versionclasses' => array(
528 'gecko',
529 ),
530 ),
531 ),
532
533 // Firefox 18; Mac OS X 10.
534 array(
535 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
536 array(
537 'is_firefox' => true,
538 'check_firefox_version' => array(
539 '1.5' => true,
540 '3.0' => true,
541 '4' => true,
542 '10' => true,
543 '15' => true,
544 '18' => true,
545 ),
546
547 'is_gecko' => true,
548 'check_gecko_version' => array(
549 '1' => true,
550 '2' => true,
551 '20030516' => true,
552 '20051116' => true,
553 '2006010100' => true,
554 '3.6' => true,
555 '4.0' => true,
556 '15.0' => true,
557 '18.0' => true,
558 ),
559
560 'versionclasses' => array(
561 'gecko',
562 ),
563 ),
564 ),
565
566 // SeaMonkey 2.0; Windows.
567 array(
568 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
569 array(
570 'is_gecko' => true,
571 'check_gecko_version' => array(
572 '1' => true,
573 '2' => true,
574 '20030516' => true,
575 '20051106' => true,
576 '20051116' => true,
577 '2006010100' => true,
578 ),
579
580 'versionclasses' => array(
581 'gecko',
582 'gecko19',
583 ),
584 ),
585 ),
586
587 // SeaMonkey 2.1; Linux.
588 array(
589 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
590 array(
591 'is_gecko' => true,
592 'check_gecko_version' => array(
593 '1' => true,
594 '2' => true,
595 '20030516' => true,
596 '20051116' => true,
597 '2006010100' => true,
598 '3.6' => true,
599 '4.0' => true,
600 ),
601
602 'is_firefox' => true,
603 'check_firefox_version' => array(
604 '1.5' => true,
605 '3.0' => true,
606 '4' => true,
607 ),
608
609 'versionclasses' => array(
610 'gecko',
611 'gecko20',
612 ),
613 ),
614 ),
615
616 // SeaMonkey 2.3; FreeBSD.
617 array(
618 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
619 array(
620 'is_gecko' => true,
621 'check_gecko_version' => array(
622 '1' => true,
623 '2' => true,
624 '20030516' => true,
625 '20051116' => true,
626 '2006010100' => true,
627 '3.6' => true,
628 '4.0' => true,
629 ),
630
631 'is_firefox' => true,
632 'check_firefox_version' => array(
633 '1.5' => true,
634 '3.0' => true,
635 '4' => true,
636 ),
637
638 'versionclasses' => array(
639 'gecko',
640 ),
641 ),
642 ),
643
644 // Windows 7; MS Word 2010.
645 array(
646 '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)',
647 array(
648 'is_ie' => true,
649 'check_ie_version' => array(
650 '0' => true,
651 '5.0' => true,
652 '5.5' => true,
653 '6.0' => true,
654 '7.0' => true,
655 '8.0' => true,
656 ),
657 'iecompatibility' => true,
658 'versionclasses' => array(
659 'ie',
660 'ie8',
661 ),
662
663 'is_msword' => true,
664
665 'supports_svg' => false,
666 ),
667 ),
668
669 // Windows 7; MS Outlook 2010.
670 array(
671 '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)',
672 array(
673 'is_ie' => true,
674 'check_ie_version' => array(
675 '0' => true,
676 '5.0' => true,
677 '5.5' => true,
678 '6.0' => true,
679 '7.0' => true,
680 '8.0' => true,
681 ),
682 'iecompatibility' => true,
683 'versionclasses' => array(
684 'ie',
685 'ie8',
686 ),
687
688 // Note: Outlook is deliberately not considered to be MS Word.
689 'is_msword' => false,
690
691 'supports_svg' => false,
692 ),
693 ),
694
695 // Mac OS X; MS Word 14.
696 array(
697 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
698 array(
699 'versionclasses' => array(
700 ),
701
702 'is_msword' => true,
703 ),
704 ),
705
706 // Safari 312; Max OS X.
707 array(
708 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
709 array(
710 'is_safari' => true,
711 'check_safari_version' => array(
712 '1' => true,
713 '312' => true,
714 ),
715
716 'is_webkit' => true,
717
718 'versionclasses' => array(
719 'safari',
720 ),
721 ),
722 ),
723
724 // Safari 412; Max OS X.
725 array(
726 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
727 array(
728 'is_safari' => true,
729 'check_safari_version' => array(
730 '1' => true,
731 '312' => true,
732 ),
733
734 'is_webkit' => true,
735
736 'versionclasses' => array(
737 'safari',
738 ),
739 ),
740 ),
657a94fc 741
7c10ad33
AN
742 // Safari 2.0; Max OS X.
743 array(
744 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
745 array(
746 'is_safari' => true,
747 'check_safari_version' => array(
748 '1' => true,
749 '312' => true,
750 ),
751
752 'is_webkit' => true,
753
754 'versionclasses' => array(
755 'safari',
756 ),
757 ),
758 ),
657a94fc 759
7c10ad33
AN
760 // iOS Safari 528; iPhone.
761 array(
762 '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',
763 array(
764 // Note: We do *not* identify mobile Safari as Safari.
765 'is_safari_ios' => true,
766 'check_safari_ios_version' => array(
767 '527' => true,
768 ),
769
770 'is_webkit' => true,
771
772 'versionclasses' => array(
773 'safari',
774 'ios',
775 ),
776
777 'devicetype' => 'mobile',
778 ),
779 ),
657a94fc 780
7c10ad33
AN
781 // iOS Safari 533; iPad.
782 array(
783 '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',
784 array(
785 // Note: We do *not* identify mobile Safari as Safari.
786 'is_safari_ios' => true,
787 'check_safari_ios_version' => array(
788 '527' => true,
789 ),
790
791 'is_webkit' => true,
792
793 'versionclasses' => array(
794 'safari',
795 'ios',
796 ),
797
798 'devicetype' => 'tablet',
799 ),
800 ),
657a94fc 801
7c10ad33
AN
802 // Android WebKit 525; G1 Phone.
803 array(
804 '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',
805 array(
806 'is_webkit_android' => true,
807 'check_webkit_android_version' => array(
808 '525' => true,
809 ),
657a94fc 810
7c10ad33 811 'is_webkit' => true,
657a94fc 812
7c10ad33
AN
813 'versionclasses' => array(
814 'android',
815 'safari',
816 ),
657a94fc 817
7c10ad33 818 'devicetype' => 'mobile',
657a94fc 819
7c10ad33
AN
820 'supports_svg' => false,
821 ),
822 ),
657a94fc 823
7c10ad33
AN
824 // Android WebKit 530; Nexus.
825 array(
826 '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',
827 array(
828 'is_webkit_android' => true,
829 'check_webkit_android_version' => array(
830 '525' => true,
831 '527' => true,
832 ),
657a94fc 833
7c10ad33 834 'is_webkit' => true,
657a94fc 835
7c10ad33
AN
836 'versionclasses' => array(
837 'android',
838 'safari',
839 ),
657a94fc 840
7c10ad33 841 'devicetype' => 'mobile',
657a94fc 842
7c10ad33
AN
843 'supports_svg' => false,
844 ),
845 ),
657a94fc 846
7c10ad33
AN
847 // Android WebKit 537; Samsung GT-9505.
848 array(
849 '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',
850 array(
851 'is_webkit_android' => true,
852 'check_webkit_android_version' => array(
853 '525' => true,
854 '527' => true,
855 ),
856
857 'is_webkit' => true,
858
859 'is_chrome' => true,
860 'check_chrome_version' => array(
861 '7' => true,
862 '8' => true,
863 '10' => true,
864 ),
865
866 'versionclasses' => array(
867 'safari',
868 'android',
869 ),
870
871 'devicetype' => 'mobile',
872 ),
873 ),
874
875 // Android WebKit 537; Nexus 5.
876 array(
877 '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',
878 array(
879 'is_webkit_android' => true,
880 'check_webkit_android_version' => array(
881 '525' => true,
882 '527' => true,
883 ),
884
885 'is_webkit' => true,
886
887 'is_chrome' => true,
888 'check_chrome_version' => array(
889 '7' => true,
890 '8' => true,
891 '10' => true,
892 ),
893
894 'versionclasses' => array(
895 'safari',
896 'android',
897 ),
898
899 'devicetype' => 'mobile',
900 ),
901 ),
902
903 // Chrome 8; Mac OS X.
904 array(
905 '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',
906 array(
907 'is_chrome' => true,
908 'check_chrome_version' => array(
909 '7' => true,
910 '8' => true,
911 ),
912
913 'is_webkit' => true,
914
915 'versionclasses' => array(
916 'safari',
917 ),
918 ),
919 ),
920
921 // Opera 8.51; Windows XP.
922 array(
923 'Opera/8.51 (Windows NT 5.1; U; en)',
924 array(
925 'is_opera' => true,
926 'check_opera_version' => array(
927 '8.0' => true,
928 ),
929
930 'versionclasses' => array(
931 'opera',
932 ),
933
934 'supports_svg' => false,
935 ),
936 ),
657a94fc 937
7c10ad33
AN
938 // Opera 9.0; Windows XP.
939 array(
940 'Opera/9.0 (Windows NT 5.1; U; en)',
941 array(
942 'is_opera' => true,
943 'check_opera_version' => array(
944 '8.0' => true,
945 ),
946
947 'versionclasses' => array(
948 'opera',
949 ),
950
951 'supports_svg' => false,
952 ),
953 ),
657a94fc 954
7c10ad33
AN
955 // Opera 9.0; Debian Linux.
956 array(
957 'Opera/9.01 (X11; Linux i686; U; en)',
958 array(
959 'is_opera' => true,
960 'check_opera_version' => array(
961 '8.0' => true,
962 ),
963
964 'versionclasses' => array(
965 'opera',
966 ),
967
968 'supports_svg' => false,
969 ),
970 ),
971 );
657a94fc
MS
972 }
973
c3d2fbf9 974 /**
7c10ad33 975 * Test instance generation.
c3d2fbf9 976 */
7c10ad33
AN
977 public function test_instance() {
978 $this->assertInstanceOf('core_useragent', core_useragent::instance());
979 $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
980 }
c3d2fbf9 981
7c10ad33
AN
982 /**
983 * @dataProvider user_agents_providers
984 */
985 public function test_useragent_ie($useragent, $tests) {
986 // Setup the core_useragent instance.
987 core_useragent::instance(true, $useragent);
988
989 // IE Tests.
990 if (isset($tests['is_ie']) && $tests['is_ie']) {
991 $this->assertTrue(core_useragent::is_ie());
992 } else {
993 $this->assertFalse(core_useragent::is_ie());
994 }
995
996 $versions = array(
997 // New versions of should be added here.
998 '0' => false,
999 '5.0' => false,
1000 '5.5' => false,
1001 '6.0' => false,
1002 '7.0' => false,
1003 '8.0' => false,
1004 '9.0' => false,
1005 '10' => false,
1006 '11' => false,
1007 '12' => false,
1008 '13' => false,
1009 '14' => false,
1010 );
1011
1012 if (isset($tests['check_ie_version'])) {
1013 // The test provider has overwritten some of the above checks.
1014 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1015 $versions = $tests['check_ie_version'] + $versions;
1016 }
1017
1018 foreach ($versions as $version => $result) {
1019 $this->assertEquals($result, core_useragent::check_ie_version($version),
1020 "Version incorrectly determined for IE version '{$version}'");
1021 }
1022
1023 // IE Compatibility mode.
1024 if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1025 $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1026 } else {
1027 $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1028 }
c3d2fbf9 1029
7c10ad33 1030 }
c3d2fbf9 1031
7c10ad33
AN
1032 /**
1033 * @dataProvider user_agents_providers
1034 */
1035 public function test_useragent_msword($useragent, $tests) {
1036 // Setup the core_useragent instance.
1037 core_useragent::instance(true, $useragent);
1038
1039 // MSWord Tests.
1040 if (isset($tests['is_msword']) && $tests['is_msword']) {
1041 $this->assertTrue(core_useragent::is_msword());
1042 } else {
1043 $this->assertFalse(core_useragent::is_msword());
1044 }
1045 }
c3d2fbf9 1046
c3d2fbf9 1047
7c10ad33
AN
1048 /**
1049 * @dataProvider user_agents_providers
1050 */
1051 public function test_useragent_supports($useragent, $tests) {
1052 // Setup the core_useragent instance.
1053 core_useragent::instance(true, $useragent);
1054
1055 // Supports SVG.
1056 if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1057 $this->assertTrue(core_useragent::supports_svg(),
1058 "SVG Support was not reported (and should have been)");
1059 } else {
1060 $this->assertFalse(core_useragent::supports_svg(),
1061 "SVG Support was reported (and should not have been)");
1062 }
1063 }
c3d2fbf9 1064
7c10ad33
AN
1065 /**
1066 * @dataProvider user_agents_providers
1067 */
1068 public function test_useragent_webkit($useragent, $tests) {
1069 // Setup the core_useragent instance.
1070 core_useragent::instance(true, $useragent);
1071
1072 if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1073 $this->assertTrue(core_useragent::is_webkit(),
1074 "Browser was not identified as a webkit browser");
1075 $this->assertTrue(core_useragent::check_webkit_version());
1076 } else {
1077 $this->assertFalse(core_useragent::is_webkit(),
1078 "Browser was incorrectly identified as a webkit browser");
1079 $this->assertFalse(core_useragent::check_webkit_version());
1080 }
1081
1082 $versions = array(
1083 // New versions should be added here.
1084 );
1085
1086 if (isset($tests['check_webkit_version'])) {
1087 // The test provider has overwritten some of the above checks.
1088 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1089 $versions = $tests['check_webkit_version'] + $versions;
1090 }
1091
1092 foreach ($versions as $version => $result) {
1093 $this->assertEquals($result, core_useragent::check_webkit_version($version),
1094 "Version incorrectly determined for Webkit version '{$version}'");
1095 }
1096 }
c3d2fbf9 1097
7c10ad33
AN
1098 /**
1099 * @dataProvider user_agents_providers
1100 */
1101 public function test_useragent_webkit_android($useragent, $tests) {
1102 // Setup the core_useragent instance.
1103 core_useragent::instance(true, $useragent);
1104
1105 if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1106 $this->assertTrue(core_useragent::is_webkit_android(),
1107 "Browser was not identified as an Android webkit browser");
1108 $this->assertTrue(core_useragent::check_webkit_android_version());
1109 } else {
1110 $this->assertFalse(core_useragent::is_webkit_android(),
1111 "Browser was incorrectly identified as an Android webkit browser");
1112 $this->assertFalse(core_useragent::check_webkit_android_version());
1113 }
1114
1115 $versions = array(
1116 // New versions should be added here.
1117 '525' => false,
1118 '527' => false,
1119 '590' => false,
1120 );
1121
1122 if (isset($tests['check_webkit_android_version'])) {
1123 // The test provider has overwritten some of the above checks.
1124 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1125 $versions = $tests['check_webkit_android_version'] + $versions;
1126 }
1127
1128 foreach ($versions as $version => $result) {
1129 $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1130 "Version incorrectly determined for Android webkit version '{$version}'");
1131 }
1132 }
c3d2fbf9 1133
7c10ad33
AN
1134 /**
1135 * @dataProvider user_agents_providers
1136 */
1137 public function test_useragent_chrome($useragent, $tests) {
1138 // Setup the core_useragent instance.
1139 core_useragent::instance(true, $useragent);
1140
1141 if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1142 $this->assertTrue(core_useragent::is_chrome(),
1143 "Browser was not identified as a chrome browser");
1144 $this->assertTrue(core_useragent::check_chrome_version());
1145 } else {
1146 $this->assertFalse(core_useragent::is_chrome(),
1147 "Browser was incorrectly identified as a chrome browser");
1148 $this->assertFalse(core_useragent::check_chrome_version());
1149 }
1150
1151 $versions = array(
1152 // New versions should be added here.
1153 '7' => false,
1154 '8' => false,
1155 '10' => false,
1156 );
1157
1158 if (isset($tests['check_chrome_version'])) {
1159 // The test provider has overwritten some of the above checks.
1160 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1161 $versions = $tests['check_chrome_version'] + $versions;
1162 }
1163
1164 foreach ($versions as $version => $result) {
1165 $this->assertEquals($result, core_useragent::check_chrome_version($version),
1166 "Version incorrectly determined for Chrome version '{$version}'");
1167 }
1168 }
c3d2fbf9 1169
7c10ad33
AN
1170 /**
1171 * @dataProvider user_agents_providers
1172 */
1173 public function test_useragent_safari($useragent, $tests) {
1174 // Setup the core_useragent instance.
1175 core_useragent::instance(true, $useragent);
1176
1177 if (isset($tests['is_safari']) && $tests['is_safari']) {
1178 $this->assertTrue(core_useragent::is_safari(),
1179 "Browser was not identified as a safari browser");
1180 $this->assertTrue(core_useragent::check_safari_version());
1181 } else {
1182 $this->assertFalse(core_useragent::is_safari(),
1183 "Browser was incorrectly identified as a safari browser");
1184 $this->assertFalse(core_useragent::check_safari_version());
1185 }
1186
1187 // Check Safari (generic).
1188 $versions = array(
1189 // New versions should be added here.
1190 '1' => false,
1191 '312' => false,
1192 '500' => false,
1193 );
1194
1195 if (isset($tests['check_safari_version'])) {
1196 // The test provider has overwritten some of the above checks.
1197 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1198 $versions = $tests['check_safari_version'] + $versions;
1199 }
1200
1201 foreach ($versions as $version => $result) {
1202 $this->assertEquals($result, core_useragent::check_safari_version($version),
1203 "Version incorrectly determined for Safari (generic) version '{$version}'");
1204 }
1205 }
c3d2fbf9 1206
7c10ad33
AN
1207 /**
1208 * @dataProvider user_agents_providers
1209 */
1210 public function test_useragent_ios_safari($useragent, $tests) {
1211 // Setup the core_useragent instance.
1212 core_useragent::instance(true, $useragent);
1213
1214 if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1215 $this->assertTrue(core_useragent::is_safari_ios(),
1216 "Browser was not identified as an iOS safari browser");
1217 $this->assertTrue(core_useragent::check_safari_ios_version());
1218 } else {
1219 $this->assertFalse(core_useragent::is_safari_ios(),
1220 "Browser was incorrectly identified as an iOS safari browser");
1221 $this->assertFalse(core_useragent::check_safari_ios_version());
1222 }
1223
1224 // Check iOS Safari.
1225 $versions = array(
1226 // New versions should be added here.
1227 '527' => false,
1228 '590' => false,
1229 );
1230
1231 if (isset($tests['check_safari_ios_version'])) {
1232 // The test provider has overwritten some of the above checks.
1233 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1234 $versions = $tests['check_safari_ios_version'] + $versions;
1235 }
1236
1237 foreach ($versions as $version => $result) {
1238 $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1239 "Version incorrectly determined for iOS Safari version '{$version}'");
1240 }
1241 }
1242
1243 /**
1244 * @dataProvider user_agents_providers
1245 */
1246 public function test_useragent_gecko($useragent, $tests) {
1247 // Setup the core_useragent instance.
1248 core_useragent::instance(true, $useragent);
1249
1250 if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1251 $this->assertTrue(core_useragent::is_gecko(),
1252 "Browser was not identified as a gecko browser");
1253 $this->assertTrue(core_useragent::check_gecko_version());
1254 } else {
1255 $this->assertFalse(core_useragent::is_gecko(),
1256 "Browser was incorrectly identified as a gecko browser");
1257 $this->assertFalse(core_useragent::check_gecko_version());
1258 }
1259
1260 $versions = array(
1261 // New versions should be added here.
1262 '1' => false,
1263 '2' => false,
1264 '3.6' => false,
1265 '4.0' => false,
1266 '20030516' => false,
1267 '20051116' => false,
1268 '2006010100' => false,
1269 '15.0' => false,
1270 '18.0' => false,
1271 '19.0' => false,
1272 );
1273
1274 if (isset($tests['check_gecko_version'])) {
1275 // The test provider has overwritten some of the above checks.
1276 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1277 $versions = $tests['check_gecko_version'] + $versions;
1278 }
1279
1280 foreach ($versions as $version => $result) {
1281 $this->assertEquals($result, core_useragent::check_gecko_version($version),
1282 "Version incorrectly determined for Gecko version '{$version}'");
1283 }
1284 }
1285
1286 /**
1287 * @dataProvider user_agents_providers
1288 */
1289 public function test_useragent_firefox($useragent, $tests) {
1290 // Setup the core_useragent instance.
1291 core_useragent::instance(true, $useragent);
1292
1293 if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1294 $this->assertTrue(core_useragent::is_firefox(),
1295 "Browser was not identified as a firefox browser");
1296 $this->assertTrue(core_useragent::check_firefox_version());
1297 } else {
1298 $this->assertFalse(core_useragent::is_firefox(),
1299 "Browser was incorrectly identified as a firefox browser");
1300 $this->assertFalse(core_useragent::check_firefox_version());
1301 }
1302
1303 $versions = array(
1304 // New versions should be added here.
1305 '1.5' => false,
1306 '3.0' => false,
1307 '4' => false,
1308 '10' => false,
1309 '15' => false,
1310 '18' => false,
1311 '19' => false,
1312 );
1313
1314 if (isset($tests['check_firefox_version'])) {
1315 // The test provider has overwritten some of the above checks.
1316 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1317 $versions = $tests['check_firefox_version'] + $versions;
1318 }
1319
1320 foreach ($versions as $version => $result) {
1321 $this->assertEquals($result, core_useragent::check_firefox_version($version),
1322 "Version incorrectly determined for Firefox version '{$version}'");
1323 }
1324 }
c3d2fbf9 1325
7c10ad33
AN
1326 /**
1327 * @dataProvider user_agents_providers
1328 */
1329 public function test_useragent_opera($useragent, $tests) {
1330 // Setup the core_useragent instance.
1331 core_useragent::instance(true, $useragent);
1332
1333 if (isset($tests['is_opera']) && $tests['is_opera']) {
1334 $this->assertTrue(core_useragent::is_opera(),
1335 "Browser was not identified as a opera browser");
1336 $this->assertTrue(core_useragent::check_opera_version());
1337 } else {
1338 $this->assertFalse(core_useragent::is_opera(),
1339 "Browser was incorrectly identified as a opera browser");
1340 $this->assertFalse(core_useragent::check_opera_version());
1341 }
1342
1343 $versions = array(
1344 // New versions should be added here.
1345 '8.0' => false,
1346 '10.0' => false,
1347 );
1348
1349 if (isset($tests['check_opera_version'])) {
1350 // The test provider has overwritten some of the above checks.
1351 // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1352 $versions = $tests['check_opera_version'] + $versions;
1353 }
1354
1355 foreach ($versions as $version => $result) {
1356 $this->assertEquals($result, core_useragent::check_opera_version($version),
1357 "Version incorrectly determined for Opera version '{$version}'");
1358 }
1359 }
c3d2fbf9 1360
7c10ad33
AN
1361 /**
1362 * @dataProvider user_agents_providers
1363 */
1364 public function test_get_device_type($useragent, $tests) {
1365 // Setup the core_useragent instance.
1366 core_useragent::instance(true, $useragent);
c3d2fbf9 1367
7c10ad33
AN
1368 $expected = 'default';
1369 if (isset($tests['devicetype'])) {
1370 $expected = $tests['devicetype'];
1371 }
c3d2fbf9 1372
7c10ad33
AN
1373 $this->assertEquals($expected, core_useragent::get_device_type(),
1374 "Device Type was not correctly identified");
c3d2fbf9
SH
1375 }
1376
1377 /**
7c10ad33 1378 * @dataProvider user_agents_providers
c3d2fbf9 1379 */
7c10ad33
AN
1380 public function test_get_browser_version_classes($useragent, $tests) {
1381 // Setup the core_useragent instance.
1382 core_useragent::instance(true, $useragent);
1383
1384 $actual = core_useragent::get_browser_version_classes();
1385 foreach ($tests['versionclasses'] as $expectedclass) {
1386 $this->assertContains($expectedclass, $actual);
1387 }
1388 $this->assertCount(count($tests['versionclasses']), $actual);
c3d2fbf9 1389 }
378b3eac 1390}