Merge branch 'MDL-62336_master' of git://github.com/markn86/moodle
[moodle.git] / lib / tests / useragent_test.php
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/>.
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  */
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  */
32 class core_useragent_testcase extends advanced_testcase {
34     /**
35      * Restores the user agent to the default one.
36      */
37     public function tearDown() {
38         core_useragent::instance(true);
39     }
41     public function user_agents_providers() {
42         // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list.
43         // This ensures that regression tests are applied to all known user agents.
44         return array(
45             'Microsoft Edge for Windows 10 Desktop' => array(
46                 '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                 array(
48                     'is_edge'                       => true,
49                     'check_edge_version'            => array(
50                         '12'                        => true,
51                     ),
53                     // Edge pretends to be WebKit.
54                     'is_webkit'                     => true,
56                     // Edge pretends to be Chrome.
57                     // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
58                     'is_chrome'                     => true,
59                     'check_chrome_version'          => array(
60                         '7'                         => true,
61                         '8'                         => true,
62                         '10'                        => true,
63                         '39'                        => true,
64                     ),
66                     'versionclasses'                => array(
67                         'safari',
68                     ),
69                 ),
70             ),
71             'Microsoft Edge for Windows 10 Mobile' => array(
72                 '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                 array(
74                     'is_edge'                       => true,
75                     'check_edge_version'              => array(
76                         '12'                        => true,
77                     ),
79                     // Edge pretends to be WebKit.
80                     'is_webkit'                     => true,
82                     // Mobile Edge pretends to be Android.
83                     'is_webkit_android'             => true,
84                     'check_webkit_android_version'  => array(
85                         '525'                       => true,
86                         '527'                       => true,
87                     ),
89                     // Edge pretends to be Chrome.
90                     // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
91                     'is_chrome'                     => true,
92                     'check_chrome_version'          => array(
93                         '7'                         => true,
94                         '8'                         => true,
95                         '10'                        => true,
96                         '39'                        => true,
97                     ),
99                     'versionclasses'                => array(
100                         'safari',
101                         'android',
102                     ),
104                     'devicetype'                    => 'mobile',
105                 ),
106             ),
107             // Windows 98; Internet Explorer 5.0.
108             array(
109                 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
110                 array(
111                     // MSIE 5.0 is not considered a browser at all: known false results.
112                     'is_ie'                         => false,
113                     'check_ie_version'              => array(
114                         '0'                         => true,
115                         '5.0'                       => true,
116                     ),
117                     'versionclasses'                => array(
118                         // IE 5.0 is not considered a browser.
119                     ),
121                     // IE 5.0 is a legacy browser.
122                     'devicetype'                    => 'legacy',
124                     'supports_svg'                  => false,
125                     'supports_json_contenttype'     => false,
126                 ),
127             ),
129             // Windows 2000; Internet Explorer 5.5.
130             array(
131                 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
132                 array(
133                     'is_ie'                         => true,
134                     'check_ie_version'              => array(
135                         '0'                         => true,
136                         '5.0'                       => true,
137                         '5.5'                       => true,
138                     ),
139                     'versionclasses'                => array(
140                         'ie',
141                     ),
143                     // IE 6.0 is a legacy browser.
144                     'devicetype'                    => 'legacy',
146                     'supports_svg'                  => false,
147                     'supports_json_contenttype'     => false,
148                 ),
149             ),
151             // Windows XP SP2; Internet Explorer 6.0.
152             array(
153                 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
154                 array(
155                     'is_ie'                         => true,
156                     'check_ie_version'              => array(
157                         '0'                         => true,
158                         '5.0'                       => true,
159                         '5.5'                       => true,
160                         '6.0'                       => true,
161                     ),
162                     'versionclasses'                => array(
163                         'ie',
164                         'ie6',
165                     ),
167                     // IE 7.0 is a legacy browser.
168                     'devicetype'                    => 'legacy',
170                     'supports_svg'                  => false,
171                     'supports_json_contenttype'     => false,
172                 ),
173             ),
175             // Windows XP SP2; Internet Explorer 7.0.
176             array(
177                 '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)',
178                 array(
179                     'is_ie'                         => true,
180                     'check_ie_version'              => array(
181                         '0'                         => true,
182                         '5.0'                       => true,
183                         '5.5'                       => true,
184                         '6.0'                       => true,
185                         '7.0'                       => true,
186                     ),
187                     'versionclasses'                => array(
188                         'ie',
189                         'ie7',
190                     ),
192                     'supports_svg'                  => false,
193                     'supports_json_contenttype'     => false,
194                 ),
195             ),
197             // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
198             array(
199                 '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)',
200                 array(
201                     'is_ie'                         => true,
202                     'check_ie_version'              => array(
203                         '0'                         => true,
204                         '5.0'                       => true,
205                         '5.5'                       => true,
206                         '6.0'                       => true,
207                         '7.0'                       => true,
208                     ),
209                     'versionclasses'                => array(
210                         'ie',
211                         'ie7',
212                     ),
214                     'supports_svg'                  => false,
215                     'supports_json_contenttype'     => false,
216                 ),
217             ),
219             // Windows Vista; Internet Explorer 8.0.
220             array(
221                 '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)',
222                 array(
223                     'is_ie'                         => true,
224                     'check_ie_version'              => array(
225                         '0'                         => true,
226                         '5.0'                       => true,
227                         '5.5'                       => true,
228                         '6.0'                       => true,
229                         '7.0'                       => true,
230                         '8.0'                       => true,
231                     ),
232                     'versionclasses'                => array(
233                         'ie',
234                         'ie8',
235                     ),
237                     'supports_svg'                  => false,
238                 ),
239             ),
241             // Windows 7; Internet Explorer 9.0.
242             array(
243                 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
244                 array(
245                     'is_ie'                         => true,
246                     'check_ie_version'              => array(
247                         '0'                         => true,
248                         '5.0'                       => true,
249                         '5.5'                       => true,
250                         '6.0'                       => true,
251                         '7.0'                       => true,
252                         '8.0'                       => true,
253                         '9.0'                       => true,
254                     ),
255                     'versionclasses'                => array(
256                         'ie',
257                         'ie9',
258                     ),
259                 ),
260             ),
262             // Windows 7; Internet Explorer 9.0i.
263             array(
264                 '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)',
265                 array(
266                     'is_ie'                         => true,
267                     'check_ie_version'              => array(
268                         '0'                         => true,
269                         '5.0'                       => true,
270                         '5.5'                       => true,
271                         '6.0'                       => true,
272                         '7.0'                       => true,
273                         '8.0'                       => true,
274                         '9.0'                       => true,
275                     ),
276                     'versionclasses'                => array(
277                         'ie',
278                         'ie9',
279                     ),
280                     'iecompatibility'               => true,
282                     // IE 9 in Compatiblity mode does not support SVG.
283                     'supports_svg'                  => false,
285                     // IE in Compatiblity mode does not support JSON ContentType.
286                     'supports_json_contenttype'     => false,
287                 ),
288             ),
290             // Windows 8; Internet Explorer 10.0.
291             array(
292                 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
293                 array(
294                     'is_ie'                         => true,
295                     'check_ie_version'              => array(
296                         '0'                         => true,
297                         '5.0'                       => true,
298                         '5.5'                       => true,
299                         '6.0'                       => true,
300                         '7.0'                       => true,
301                         '8.0'                       => true,
302                         '9.0'                       => true,
303                         '10'                        => true,
304                     ),
305                     'versionclasses'                => array(
306                         'ie',
307                         'ie10',
308                     ),
309                 ),
310             ),
312             // Windows 8; Internet Explorer 10.0i.
313             array(
314                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
315                 array(
316                     'is_ie'                         => true,
317                     'check_ie_version'              => array(
318                         '0'                         => true,
319                         '5.0'                       => true,
320                         '5.5'                       => true,
321                         '6.0'                       => true,
322                         '7.0'                       => true,
323                         '8.0'                       => true,
324                         '9.0'                       => true,
325                         '10'                        => true,
326                     ),
327                     'iecompatibility'               => true,
328                     'versionclasses'                => array(
329                         'ie',
330                         'ie10',
331                     ),
333                     // IE in Compatiblity mode does not support JSON ContentType.
334                     'supports_json_contenttype'     => false,
335                 ),
336             ),
338             // Windows 8.1; Internet Explorer 11.0.
339             array(
340                 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
341                 array(
342                     'is_ie'                         => true,
343                     'check_ie_version'              => array(
344                         '0'                         => true,
345                         '5.0'                       => true,
346                         '5.5'                       => true,
347                         '6.0'                       => true,
348                         '7.0'                       => true,
349                         '8.0'                       => true,
350                         '9.0'                       => true,
351                         '10'                        => true,
352                         '11'                        => true,
353                     ),
354                     'versionclasses'                => array(
355                         'ie',
356                         'ie11',
357                     ),
358                 ),
359             ),
361             // Windows 8.1; Internet Explorer 11.0i.
362             array(
363                 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
364                 array(
365                     'is_ie'                         => true,
366                     'check_ie_version'              => array(
367                         '0'                         => true,
368                         '5.0'                       => true,
369                         '5.5'                       => true,
370                         '6.0'                       => true,
371                         '7.0'                       => true,
372                         '8.0'                       => true,
373                         '9.0'                       => true,
374                         '10'                        => true,
375                         '11'                        => true,
376                     ),
377                     'iecompatibility'               => true,
378                     'versionclasses'                => array(
379                         'ie',
380                         'ie11',
381                     ),
383                     // IE in Compatiblity mode does not support JSON ContentType.
384                     'supports_json_contenttype'     => false,
385                 ),
386             ),
388             // Windows XP; Firefox 1.0.6.
389             array(
390                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
391                 array(
392                     'is_firefox'                    => true,
394                     'is_gecko'                      => true,
395                     'check_gecko_version'           => array(
396                         '1'                         => true,
397                     ),
399                     'versionclasses'                => array(
400                         'gecko',
401                         'gecko17',
402                     ),
403                 ),
404             ),
406             // Windows XP; Firefox 1.0.6.
407             array(
408                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
409                 array(
410                     'is_firefox'                    => true,
411                     'check_firefox_version'         => array(
412                         '1.5'                       => true,
413                     ),
415                     'is_gecko'                      => true,
416                     'check_gecko_version'           => array(
417                         '1'                         => true,
418                         '20030516'                  => true,
419                         '20051116'                  => true,
420                     ),
422                     'versionclasses'                => array(
423                         'gecko',
424                         'gecko18',
425                     ),
426                 ),
427             ),
429             // Windows XP; Firefox 1.5.0.1.
430             array(
431                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
432                 array(
433                     'is_firefox'                    => true,
434                     'check_firefox_version'         => array(
435                         '1.5'                       => true,
436                     ),
438                     'is_gecko'                      => true,
439                     'check_gecko_version'           => array(
440                         '1'                         => true,
441                         '20030516'                  => true,
442                         '20051116'                  => true,
443                     ),
445                     'versionclasses'                => array(
446                         'gecko',
447                         'gecko18',
448                     ),
449                 ),
450             ),
452             // Windows XP; Firefox 2.0.
453             array(
454                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
455                 array(
456                     'is_firefox'                    => true,
457                     'check_firefox_version'         => array(
458                         '1.5'                       => true,
459                     ),
461                     'is_gecko'                      => true,
462                     'check_gecko_version'           => array(
463                         '1'                         => true,
464                         '2'                         => true,
465                         '20030516'                  => true,
466                         '20051116'                  => true,
467                         '2006010100'                => true,
468                     ),
470                     'versionclasses'                => array(
471                         'gecko',
472                         'gecko18',
473                     ),
474                 ),
475             ),
477             // Ubuntu Linux amd64; Firefox 2.0.
478             array(
479                 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
480                 array(
481                     'is_firefox'                    => true,
482                     'check_firefox_version'         => array(
483                         '1.5'                       => true,
484                     ),
486                     'is_gecko'                      => true,
487                     'check_gecko_version'           => array(
488                         '1'                         => true,
489                         '2'                         => true,
490                         '20030516'                  => true,
491                         '20051116'                  => true,
492                         '2006010100'                => true,
493                     ),
495                     'versionclasses'                => array(
496                         'gecko',
497                         'gecko18',
498                     ),
499                 ),
500             ),
502             // SUSE; Firefox 3.0.6.
503             array(
504                 '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',
505                 array(
506                     'is_firefox'                    => true,
507                     'check_firefox_version'         => array(
508                         '1.5'                       => true,
509                         '3.0'                       => true,
510                     ),
512                     'is_gecko'                      => true,
513                     'check_gecko_version'           => array(
514                         '1'                         => true,
515                         '2'                         => true,
516                         '20030516'                  => true,
517                         '20051116'                  => true,
518                         '2006010100'                => true,
519                     ),
521                     'versionclasses'                => array(
522                         'gecko',
523                         'gecko19',
524                     ),
525                 ),
526             ),
528             // Linux i686; Firefox 3.6.
529             array(
530                 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
531                 array(
532                     'is_firefox'                    => true,
533                     'check_firefox_version'         => array(
534                         '1.5'                       => true,
535                         '3.0'                       => true,
536                     ),
538                     'is_gecko'                      => true,
539                     'check_gecko_version'           => array(
540                         '1'                         => true,
541                         '2'                         => true,
542                         '20030516'                  => true,
543                         '20051116'                  => true,
544                         '2006010100'                => true,
545                         '3.6'                       => true,
546                         '20100101'                  => true,
547                     ),
549                     'versionclasses'                => array(
550                         'gecko',
551                         'gecko20',
552                     ),
553                 ),
554             ),
556             // Windows; Firefox 11.0.
557             array(
558                 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
559                 array(
560                     'is_firefox'                    => true,
561                     'check_firefox_version'         => array(
562                         '1.5'                       => true,
563                         '3.0'                       => true,
564                         '4'                         => true,
565                         '10'                        => true,
566                     ),
568                     'is_gecko'                      => true,
569                     'check_gecko_version'           => array(
570                         '1'                         => true,
571                         '2'                         => true,
572                         '20030516'                  => true,
573                         '20051116'                  => true,
574                         '2006010100'                => true,
575                         '20100101'                  => true,
576                         '3.6'                       => true,
577                         '4.0'                       => true,
578                     ),
580                     'versionclasses'                => array(
581                         'gecko',
582                     ),
583                 ),
584             ),
586             // Windows; Firefox 15.0a2.
587             array(
588                 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
589                 array(
590                     'is_firefox'                    => true,
591                     'check_firefox_version'         => array(
592                         '1.5'                       => true,
593                         '3.0'                       => true,
594                         '4'                         => true,
595                         '10'                        => true,
596                         '15'                        => true,
597                     ),
599                     'is_gecko'                      => true,
600                     'check_gecko_version'           => array(
601                         '1'                         => true,
602                         '2'                         => true,
603                         '20030516'                  => true,
604                         '20051116'                  => true,
605                         '2006010100'                => true,
606                         '20100101'                  => true,
607                         '3.6'                       => true,
608                         '4.0'                       => true,
609                         '15.0'                      => true,
610                     ),
612                     'versionclasses'                => array(
613                         'gecko',
614                     ),
615                 ),
616             ),
618             // Firefox 18; Mac OS X 10.
619             array(
620                 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
621                 array(
622                     'is_firefox'                    => true,
623                     'check_firefox_version'         => array(
624                         '1.5'                       => true,
625                         '3.0'                       => true,
626                         '4'                         => true,
627                         '10'                        => true,
628                         '15'                        => true,
629                         '18'                        => true,
630                     ),
632                     'is_gecko'                      => true,
633                     'check_gecko_version'           => array(
634                         '1'                         => true,
635                         '2'                         => true,
636                         '20030516'                  => true,
637                         '20051116'                  => true,
638                         '2006010100'                => true,
639                         '3.6'                       => true,
640                         '4.0'                       => true,
641                         '15.0'                      => true,
642                         '18.0'                      => true,
643                         '20100101'                  => true,
644                     ),
646                     'versionclasses'                => array(
647                         'gecko',
648                     ),
649                 ),
650             ),
652             // Firefox 33; Mac OS X 10.10.
653             array(
654                 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
655                 array(
656                     'is_firefox'                    => true,
657                     'check_firefox_version'         => array(
658                         '1.5'                       => true,
659                         '3.0'                       => true,
660                         '4'                         => true,
661                         '10'                        => true,
662                         '15'                        => true,
663                         '18'                        => true,
664                         '19'                        => true,
665                         '33'                        => true,
666                     ),
668                     'is_gecko'                      => true,
669                     'check_gecko_version'           => array(
670                         '1'                         => true,
671                         '2'                         => true,
672                         '20030516'                  => true,
673                         '20051116'                  => true,
674                         '2006010100'                => true,
675                         '3.6'                       => true,
676                         '4.0'                       => true,
677                         '15.0'                      => true,
678                         '18.0'                      => true,
679                         '19.0'                      => true,
680                         '20100101'                  => true,
681                     ),
683                     'versionclasses'                => array(
684                         'gecko',
685                     ),
686                 ),
687             ),
689             // SeaMonkey 2.0; Windows.
690             array(
691                 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
692                 array(
693                     'is_gecko'                      => true,
694                     'check_gecko_version'           => array(
695                         '1'                         => true,
696                         '2'                         => true,
697                         '20030516'                  => true,
698                         '20051106'                  => true,
699                         '20051116'                  => true,
700                         '2006010100'                => true,
701                     ),
703                     'versionclasses'                => array(
704                         'gecko',
705                         'gecko19',
706                     ),
707                 ),
708             ),
710             // SeaMonkey 2.1; Linux.
711             array(
712                 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
713                 array(
714                     'is_gecko'                      => true,
715                     'check_gecko_version'           => array(
716                         '1'                         => true,
717                         '2'                         => true,
718                         '20030516'                  => true,
719                         '20051116'                  => true,
720                         '2006010100'                => true,
721                         '20100101'                  => true,
722                         '3.6'                       => true,
723                         '4.0'                       => true,
724                     ),
726                     'is_firefox'                    => true,
727                     'check_firefox_version'         => array(
728                         '1.5'                       => true,
729                         '3.0'                       => true,
730                         '4'                         => true,
731                     ),
733                     'versionclasses'                => array(
734                         'gecko',
735                         'gecko20',
736                     ),
737                 ),
738             ),
740             // SeaMonkey 2.3; FreeBSD.
741             array(
742                 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
743                 array(
744                     'is_gecko'                      => true,
745                     'check_gecko_version'           => array(
746                         '1'                         => true,
747                         '2'                         => true,
748                         '20030516'                  => true,
749                         '20051116'                  => true,
750                         '2006010100'                => true,
751                         '20100101'                  => true,
752                         '3.6'                       => true,
753                         '4.0'                       => true,
754                     ),
756                     'is_firefox'                    => true,
757                     'check_firefox_version'         => array(
758                         '1.5'                       => true,
759                         '3.0'                       => true,
760                         '4'                         => true,
761                     ),
763                     'versionclasses'                => array(
764                         'gecko',
765                     ),
766                 ),
767             ),
769             // Windows 7; MS Word 2010.
770             array(
771                 '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)',
772                 array(
773                     'is_ie'                         => true,
774                     'check_ie_version'              => array(
775                         '0'                         => true,
776                         '5.0'                       => true,
777                         '5.5'                       => true,
778                         '6.0'                       => true,
779                         '7.0'                       => true,
780                         '8.0'                       => true,
781                     ),
782                     'iecompatibility'               => true,
783                     'versionclasses'                => array(
784                         'ie',
785                         'ie8',
786                     ),
788                     'is_msword'                     => true,
790                     'supports_svg'                  => false,
791                     'supports_json_contenttype'     => false,
792                 ),
793             ),
795             // Windows 7; MS Outlook 2010.
796             array(
797                 '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)',
798                 array(
799                     'is_ie'                         => true,
800                     'check_ie_version'              => array(
801                         '0'                         => true,
802                         '5.0'                       => true,
803                         '5.5'                       => true,
804                         '6.0'                       => true,
805                         '7.0'                       => true,
806                         '8.0'                       => true,
807                     ),
808                     'iecompatibility'               => true,
809                     'versionclasses'                => array(
810                         'ie',
811                         'ie8',
812                     ),
814                     // Note: Outlook is deliberately not considered to be MS Word.
815                     'is_msword'                     => false,
817                     'supports_svg'                  => false,
818                     'supports_json_contenttype'     => false,
819                 ),
820             ),
822             // Mac OS X; MS Word 14.
823             array(
824                 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
825                 array(
826                     'versionclasses'                => array(
827                     ),
829                     'is_msword'                     => true,
830                 ),
831             ),
833             // Safari 312; Max OS X.
834             array(
835                 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
836                 array(
837                     'is_safari'                     => true,
838                     'check_safari_version'          => array(
839                         '1'                         => true,
840                         '312'                       => true,
841                     ),
843                     'is_webkit'                     => true,
845                     'versionclasses'                => array(
846                         'safari',
847                     ),
848                 ),
849             ),
851             // Safari 412; Max OS X.
852             array(
853                 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
854                 array(
855                     'is_safari'                     => true,
856                     'check_safari_version'          => array(
857                         '1'                         => true,
858                         '312'                       => true,
859                     ),
861                     'is_webkit'                     => true,
863                     'versionclasses'                => array(
864                         'safari',
865                     ),
866                 ),
867             ),
869             // Safari 2.0; Max OS X.
870             array(
871                 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
872                 array(
873                     'is_safari'                     => true,
874                     'check_safari_version'          => array(
875                         '1'                         => true,
876                         '312'                       => true,
877                     ),
879                     'is_webkit'                     => true,
881                     'versionclasses'                => array(
882                         'safari',
883                     ),
884                 ),
885             ),
887             // iOS Safari 528; iPhone.
888             array(
889                 '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',
890                 array(
891                     // Note: We do *not* identify mobile Safari as Safari.
892                     'is_safari_ios'                 => true,
893                     'is_ios'                        => true,
894                     'check_safari_ios_version'      => array(
895                         '527'                       => true,
896                     ),
898                     'is_webkit'                     => true,
900                     'versionclasses'                => array(
901                         'safari',
902                         'ios',
903                     ),
905                     'devicetype'                    => 'mobile',
906                ),
907             ),
909             // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
910             array(
911                 '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',
912                 array(
913                     // Note: We do *not* identify mobile Safari as Safari.
914                     'is_safari_ios'                 => true,
915                     'is_ios'                        => true,
916                     'check_safari_ios_version'      => array(
917                         '527'                       => true,
918                         '590'                       => true,
919                         '600'                       => true,
920                     ),
922                     'is_webkit'                     => true,
924                     'versionclasses'                => array(
925                         'safari',
926                         'ios',
927                     ),
929                     'devicetype'                    => 'mobile',
930                ),
931             ),
933             // iOS Safari 533; iPad.
934             array(
935                 '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',
936                 array(
937                     // Note: We do *not* identify mobile Safari as Safari.
938                     'is_safari_ios'                 => true,
939                     'is_ios'                        => true,
940                     'check_safari_ios_version'      => array(
941                         '527'                       => true,
942                     ),
944                     'is_webkit'                     => true,
946                     'versionclasses'                => array(
947                         'safari',
948                         'ios',
949                     ),
951                     'devicetype'                    => 'tablet',
952                ),
953             ),
955             // Android WebKit 525; G1 Phone.
956             array(
957                 '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',
958                 array(
959                     'is_webkit_android'             => true,
960                     'check_webkit_android_version'  => array(
961                         '525'                       => true,
962                     ),
964                     'is_webkit'                     => true,
966                     'versionclasses'                => array(
967                         'android',
968                         'safari',
969                     ),
971                     'devicetype'                    => 'mobile',
973                     'supports_svg'                  => false,
974                ),
975             ),
977             // Android WebKit 530; Nexus.
978             array(
979                 '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',
980                 array(
981                     'is_webkit_android'             => true,
982                     'check_webkit_android_version'  => array(
983                         '525'                       => true,
984                         '527'                       => true,
985                     ),
987                     'is_webkit'                     => true,
989                     'versionclasses'                => array(
990                         'android',
991                         'safari',
992                     ),
994                     'devicetype'                    => 'mobile',
996                     'supports_svg'                  => false,
997                ),
998             ),
1000             // Android WebKit 537; Samsung GT-9505.
1001             array(
1002                 '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',
1003                 array(
1004                     'is_webkit_android'             => true,
1005                     'check_webkit_android_version'  => array(
1006                         '525'                       => true,
1007                         '527'                       => true,
1008                     ),
1010                     'is_webkit'                     => true,
1012                     'is_chrome'                     => true,
1013                     'check_chrome_version'          => array(
1014                         '7'                         => true,
1015                         '8'                         => true,
1016                         '10'                        => true,
1017                     ),
1019                     'versionclasses'                => array(
1020                         'safari',
1021                         'android',
1022                     ),
1024                     'devicetype'                    => 'mobile',
1025                 ),
1026             ),
1028             // Android WebKit 537; Nexus 5.
1029             array(
1030                 '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',
1031                 array(
1032                     'is_webkit_android'             => true,
1033                     'check_webkit_android_version'  => array(
1034                         '525'                       => true,
1035                         '527'                       => true,
1036                     ),
1038                     'is_webkit'                     => true,
1040                     'is_chrome'                     => true,
1041                     'check_chrome_version'          => array(
1042                         '7'                         => true,
1043                         '8'                         => true,
1044                         '10'                        => true,
1045                     ),
1047                     'versionclasses'                => array(
1048                         'safari',
1049                         'android',
1050                     ),
1052                     'devicetype'                    => 'mobile',
1053                 ),
1054             ),
1056             // Chrome 8; Mac OS X.
1057             array(
1058                 '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',
1059                 array(
1060                     'is_chrome'                     => true,
1061                     'check_chrome_version'          => array(
1062                         '7'                         => true,
1063                         '8'                         => true,
1064                     ),
1066                     'is_webkit'                     => true,
1068                     'versionclasses'                => array(
1069                         'safari',
1070                     ),
1071                 ),
1072             ),
1074             // Chrome 39; Mac OS X.
1075             array(
1076                 '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',
1077                 array(
1078                     'is_chrome'                     => true,
1079                     'check_chrome_version'          => array(
1080                         '7'                         => true,
1081                         '8'                         => true,
1082                         '10'                        => true,
1083                         '39'                        => true,
1084                     ),
1086                     'is_webkit'                     => true,
1088                     'versionclasses'                => array(
1089                         'safari',
1090                     ),
1091                 ),
1092             ),
1094             // Opera 8.51; Windows XP.
1095             array(
1096                 'Opera/8.51 (Windows NT 5.1; U; en)',
1097                 array(
1098                     'is_opera'                      => true,
1099                     'check_opera_version'           => array(
1100                         '8.0'                       => true,
1101                     ),
1103                     'versionclasses'                => array(
1104                         'opera',
1105                     ),
1107                     'supports_svg'                  => false,
1108                ),
1109             ),
1111             // Opera 9.0; Windows XP.
1112             array(
1113                 'Opera/9.0 (Windows NT 5.1; U; en)',
1114                 array(
1115                     'is_opera'                      => true,
1116                     'check_opera_version'           => array(
1117                         '8.0'                       => true,
1118                         '9.0'                       => true,
1119                     ),
1121                     'versionclasses'                => array(
1122                         'opera',
1123                     ),
1125                     'supports_svg'                  => false,
1126                ),
1127             ),
1129             // Opera 12.15 (Build 1748); Mac OS X.
1130             array(
1131                 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
1132                 array(
1133                     'is_opera'                      => true,
1134                     'check_opera_version'           => array(
1135                         '8.0'                       => true,
1136                         '9.0'                       => true,
1137                         '10.0'                      => true,
1138                         '12.15'                     => true,
1139                     ),
1141                     'versionclasses'                => array(
1142                         'opera',
1143                     ),
1145                     'supports_svg'                  => false,
1146                ),
1147             ),
1149             // Opera 9.0; Debian Linux.
1150             array(
1151                 'Opera/9.01 (X11; Linux i686; U; en)',
1152                 array(
1153                     'is_opera'                      => true,
1154                     'check_opera_version'           => array(
1155                         '8.0'                       => true,
1156                         '9.0'                       => true,
1157                     ),
1159                     'versionclasses'                => array(
1160                         'opera',
1161                     ),
1163                     'supports_svg'                  => false,
1164                ),
1165             ),
1167             // Google web crawlers.
1168             array(
1169                 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
1170                 array(
1171                     'is_web_crawler'                => true,
1172                     'versionclasses'                => array(
1173                     ),
1174                ),
1175             ),
1176             array(
1177                 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
1178                 array(
1179                     'is_web_crawler'                => true,
1180                     'versionclasses'                => array(
1181                     ),
1182                ),
1183             ),
1184             array(
1185                 'Googlebot-Image/1.0',
1186                 array(
1187                     'is_web_crawler'                => true,
1188                     'versionclasses'                => array(
1189                     ),
1190                ),
1191             ),
1193             // Yahoo crawlers.
1194             // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
1195             array(
1196                 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
1197                 array(
1198                     'is_web_crawler'                => true,
1199                     'versionclasses'                => array(
1200                     ),
1201                ),
1202             ),
1204             // Bing / MSN / AdIdx crawlers.
1205             // See http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0.
1206             array(
1207                 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
1208                 array(
1209                     'is_web_crawler'                => true,
1210                     'versionclasses'                => array(
1211                     ),
1212                ),
1213             ),
1214             array(
1215                 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
1216                 array(
1217                     'is_web_crawler'                => true,
1218                     'versionclasses'                => array(
1219                     ),
1220                ),
1221             ),
1222             array(
1223                 '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)',
1224                 array(
1225                     'is_web_crawler'                => true,
1226                     'is_webkit'                     => true,
1227                     'is_safari_ios'                 => true,
1228                     'is_ios'                        => true,
1229                     'check_safari_ios_version'      => array(
1230                         '527'                       => true,
1231                     ),
1233                     'versionclasses'                => array(
1234                         'safari',
1235                         'ios',
1236                     ),
1238                     'devicetype'                    => 'mobile',
1239                ),
1240             ),
1241             array(
1242                 '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)',
1243                 array(
1244                     'is_web_crawler'                => true,
1245                     'is_ie'                         => true,
1246                     'check_ie_version'              => array(
1247                         '0'                         => true,
1248                         '5.0'                       => true,
1249                         '5.5'                       => true,
1250                         '6.0'                       => true,
1251                         '7.0'                       => true,
1252                         '8.0'                       => true,
1253                         '9.0'                       => true,
1254                         '10'                        => true,
1255                         '11'                        => true,
1256                     ),
1257                     'versionclasses'                => array(
1258                         'ie',
1259                         'ie11',
1260                     ),
1261                     'devicetype'                    => 'mobile',
1262                ),
1263             ),
1265             array(
1266                 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
1267                 array(
1268                     'is_web_crawler'                => true,
1269                     'versionclasses'                => array(
1270                     ),
1271                ),
1272             ),
1273             array(
1274                 'msnbot/2.1',
1275                 array(
1276                     'is_web_crawler'                => true,
1277                     'versionclasses'                => array(
1278                     ),
1279                ),
1280             ),
1281             array(
1282                 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
1283                 array(
1284                     'is_web_crawler'                => true,
1285                     'versionclasses'                => array(
1286                     ),
1287                ),
1288             ),
1289             array(
1290                 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
1291                 array(
1292                     'is_web_crawler'                => true,
1293                     'is_webkit'                     => true,
1294                     'is_safari'                     => true,
1295                     'check_safari_version'          => array(
1296                         '1'                         => true,
1297                         '312'                       => true,
1298                         '500'                       => true,
1299                     ),
1301                     'versionclasses'                => array(
1302                         'safari',
1303                     ),
1304                ),
1305             ),
1306             array(
1307                 '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',
1308                 array(
1309                     'is_web_crawler'                => true,
1310                     'is_ie'                         => true,
1311                     'check_ie_version'              => array(
1312                         '0'                         => true,
1313                         '5.0'                       => true,
1314                         '5.5'                       => true,
1315                         '6.0'                       => true,
1316                         '7.0'                       => true,
1317                         '8.0'                       => true,
1318                         '9.0'                       => true,
1319                         '10'                        => true,
1320                         '11'                        => true,
1321                     ),
1322                     'versionclasses'                => array(
1323                         'ie',
1324                         'ie11',
1325                     ),
1326                     'devicetype'                    => 'mobile',
1327                ),
1328             ),
1330             // Yandex.
1331             // See http://help.yandex.com/search/robots/agent.xml.
1332             array(
1333                 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
1334                 array(
1335                     'is_web_crawler'                => true,
1336                     'versionclasses'                => array(
1337                     ),
1338                ),
1339             ),
1340             array(
1341                 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
1342                 array(
1343                     'is_web_crawler'                => true,
1344                     'versionclasses'                => array(
1345                     ),
1346                ),
1347             ),
1349             // AltaVista.
1350             array(
1351                 'AltaVista V2.0B crawler@evreka.com',
1352                 array(
1353                     'is_web_crawler'                => true,
1354                     'versionclasses'                => array(
1355                     ),
1356                ),
1357             ),
1359             // ZoomSpider.
1360             array(
1361                 'ZoomSpider - wrensoft.com [ZSEBOT]',
1362                 array(
1363                     'is_web_crawler'                => true,
1364                     'versionclasses'                => array(
1365                     ),
1366                ),
1367             ),
1369             // Baidu.
1370             array(
1371                 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
1372                 array(
1373                     'is_web_crawler'                => true,
1374                     'versionclasses'                => array(
1375                     ),
1376                ),
1377             ),
1378             array(
1379                 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
1380                 array(
1381                     'is_web_crawler'                => true,
1382                     'versionclasses'                => array(
1383                     ),
1384                ),
1385             ),
1387             // Ask.com.
1388             array(
1389                 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
1390                 array(
1391                     'is_web_crawler'                => true,
1392                     'versionclasses'                => array(
1393                     ),
1394                ),
1395             ),
1396         );
1397     }
1399     /**
1400      * Test instance generation.
1401      */
1402     public function test_instance() {
1403         $this->assertInstanceOf('core_useragent', core_useragent::instance());
1404         $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
1405     }
1407     /**
1408      * @dataProvider user_agents_providers
1409      */
1410     public function test_useragent_edge($useragent, $tests) {
1411         // Setup the core_useragent instance.
1412         core_useragent::instance(true, $useragent);
1414         // Edge Tests.
1415         if (isset($tests['is_edge']) && $tests['is_edge']) {
1416             $this->assertTrue(core_useragent::is_edge());
1417         } else {
1418             $this->assertFalse(core_useragent::is_edge());
1419         }
1421         $versions = array(
1422             // New versions of should be added here.
1423             '12'   => false,
1424         );
1426         if (isset($tests['check_edge_version'])) {
1427             // The test provider has overwritten some of the above checks.
1428             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1429             $versions = $tests['check_edge_version'] + $versions;
1430         }
1432         foreach ($versions as $version => $result) {
1433             $this->assertEquals($result, core_useragent::check_edge_version($version),
1434                 "Version incorrectly determined for Edge version '{$version}'");
1435         }
1436     }
1438     /**
1439      * @dataProvider user_agents_providers
1440      */
1441     public function test_useragent_ie($useragent, $tests) {
1442         // Setup the core_useragent instance.
1443         core_useragent::instance(true, $useragent);
1445         // IE Tests.
1446         if (isset($tests['is_ie']) && $tests['is_ie']) {
1447             $this->assertTrue(core_useragent::is_ie());
1448         } else {
1449             $this->assertFalse(core_useragent::is_ie());
1450         }
1452         $versions = array(
1453             // New versions of should be added here.
1454             '0'    => false,
1455             '5.0'  => false,
1456             '5.5'  => false,
1457             '6.0'  => false,
1458             '7.0'  => false,
1459             '8.0'  => false,
1460             '9.0'  => false,
1461             '10'   => false,
1462             '11'   => false,
1463             '12'   => false,
1464             '13'   => false,
1465             '14'   => false,
1466         );
1468         if (isset($tests['check_ie_version'])) {
1469             // The test provider has overwritten some of the above checks.
1470             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1471             $versions = $tests['check_ie_version'] + $versions;
1472         }
1474         foreach ($versions as $version => $result) {
1475             $this->assertEquals($result, core_useragent::check_ie_version($version),
1476                 "Version incorrectly determined for IE version '{$version}'");
1477         }
1479         // IE Compatibility mode.
1480         if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1481             $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1482         } else {
1483             $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1484         }
1486     }
1488     /**
1489      * @dataProvider user_agents_providers
1490      */
1491     public function test_useragent_msword($useragent, $tests) {
1492         // Setup the core_useragent instance.
1493         core_useragent::instance(true, $useragent);
1495         // MSWord Tests.
1496         if (isset($tests['is_msword']) && $tests['is_msword']) {
1497             $this->assertTrue(core_useragent::is_msword());
1498         } else {
1499             $this->assertFalse(core_useragent::is_msword());
1500         }
1501     }
1504     /**
1505      * @dataProvider user_agents_providers
1506      */
1507     public function test_useragent_supports($useragent, $tests) {
1508         // Setup the core_useragent instance.
1509         core_useragent::instance(true, $useragent);
1511         // Supports SVG.
1512         if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1513             $this->assertTrue(core_useragent::supports_svg(),
1514                 "SVG Support was not reported (and should have been)");
1515         } else {
1516             $this->assertFalse(core_useragent::supports_svg(),
1517                 "SVG Support was reported (and should not have been)");
1518         }
1520         // Supports JSON ContentType.
1521         if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
1522             $this->assertTrue(core_useragent::supports_json_contenttype(),
1523                 "JSON ContentType Support was not reported (and should have been)");
1524         } else {
1525             $this->assertFalse(core_useragent::supports_json_contenttype(),
1526                 "JSON ContentType Support was reported (and should not have been)");
1527         }
1528     }
1530     /**
1531      * @dataProvider user_agents_providers
1532      */
1533     public function test_useragent_webkit($useragent, $tests) {
1534         // Setup the core_useragent instance.
1535         core_useragent::instance(true, $useragent);
1537         if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1538             $this->assertTrue(core_useragent::is_webkit(),
1539                 "Browser was not identified as a webkit browser");
1540             $this->assertTrue(core_useragent::check_webkit_version());
1541         } else {
1542             $this->assertFalse(core_useragent::is_webkit(),
1543                 "Browser was incorrectly identified as a webkit browser");
1544             $this->assertFalse(core_useragent::check_webkit_version());
1545         }
1547         $versions = array(
1548             // New versions should be added here.
1549         );
1551         if (isset($tests['check_webkit_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_webkit_version'] + $versions;
1555         }
1557         foreach ($versions as $version => $result) {
1558             $this->assertEquals($result, core_useragent::check_webkit_version($version),
1559                 "Version incorrectly determined for Webkit version '{$version}'");
1560         }
1561     }
1563     /**
1564      * @dataProvider user_agents_providers
1565      */
1566     public function test_useragent_webkit_android($useragent, $tests) {
1567         // Setup the core_useragent instance.
1568         core_useragent::instance(true, $useragent);
1570         if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1571             $this->assertTrue(core_useragent::is_webkit_android(),
1572                 "Browser was not identified as an Android webkit browser");
1573             $this->assertTrue(core_useragent::check_webkit_android_version());
1574         } else {
1575             $this->assertFalse(core_useragent::is_webkit_android(),
1576                 "Browser was incorrectly identified as an Android webkit browser");
1577             $this->assertFalse(core_useragent::check_webkit_android_version());
1578         }
1580         $versions = array(
1581             // New versions should be added here.
1582             '525'       => false,
1583             '527'       => false,
1584             '590'       => false,
1585         );
1587         if (isset($tests['check_webkit_android_version'])) {
1588             // The test provider has overwritten some of the above checks.
1589             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1590             $versions = $tests['check_webkit_android_version'] + $versions;
1591         }
1593         foreach ($versions as $version => $result) {
1594             $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1595                 "Version incorrectly determined for Android webkit version '{$version}'");
1596         }
1597     }
1599     /**
1600      * @dataProvider user_agents_providers
1601      */
1602     public function test_useragent_chrome($useragent, $tests) {
1603         // Setup the core_useragent instance.
1604         core_useragent::instance(true, $useragent);
1606         if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1607             $this->assertTrue(core_useragent::is_chrome(),
1608                 "Browser was not identified as a chrome browser");
1609             $this->assertTrue(core_useragent::check_chrome_version());
1610         } else {
1611             $this->assertFalse(core_useragent::is_chrome(),
1612                 "Browser was incorrectly identified as a chrome browser");
1613             $this->assertFalse(core_useragent::check_chrome_version());
1614         }
1616         $versions = array(
1617             // New versions should be added here.
1618             '7'         => false,
1619             '8'         => false,
1620             '10'        => false,
1621             '39'        => false,
1622         );
1624         if (isset($tests['check_chrome_version'])) {
1625             // The test provider has overwritten some of the above checks.
1626             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1627             $versions = $tests['check_chrome_version'] + $versions;
1628         }
1630         foreach ($versions as $version => $result) {
1631             $this->assertEquals($result, core_useragent::check_chrome_version($version),
1632                 "Version incorrectly determined for Chrome version '{$version}'");
1633         }
1634     }
1636     /**
1637      * @dataProvider user_agents_providers
1638      */
1639     public function test_useragent_safari($useragent, $tests) {
1640         // Setup the core_useragent instance.
1641         core_useragent::instance(true, $useragent);
1643         if (isset($tests['is_safari']) && $tests['is_safari']) {
1644             $this->assertTrue(core_useragent::is_safari(),
1645                 "Browser was not identified as a safari browser");
1646             $this->assertTrue(core_useragent::check_safari_version());
1647         } else {
1648             $this->assertFalse(core_useragent::is_safari(),
1649                 "Browser was incorrectly identified as a safari browser");
1650             $this->assertFalse(core_useragent::check_safari_version());
1651         }
1653         // Check Safari (generic).
1654         $versions = array(
1655             // New versions should be added here.
1656             '1'         => false,
1657             '312'       => false,
1658             '500'       => false,
1659         );
1661         if (isset($tests['check_safari_version'])) {
1662             // The test provider has overwritten some of the above checks.
1663             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1664             $versions = $tests['check_safari_version'] + $versions;
1665         }
1667         foreach ($versions as $version => $result) {
1668             $this->assertEquals($result, core_useragent::check_safari_version($version),
1669                 "Version incorrectly determined for Safari (generic) version '{$version}'");
1670         }
1671     }
1673     /**
1674      * @dataProvider user_agents_providers
1675      */
1676     public function test_useragent_ios_safari($useragent, $tests) {
1677         // Setup the core_useragent instance.
1678         core_useragent::instance(true, $useragent);
1680         if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1681             $this->assertTrue(core_useragent::is_safari_ios(),
1682                 "Browser was not identified as an iOS safari browser");
1683             $this->assertTrue(core_useragent::check_safari_ios_version());
1684         } else {
1685             $this->assertFalse(core_useragent::is_safari_ios(),
1686                 "Browser was incorrectly identified as an iOS safari browser");
1687             $this->assertFalse(core_useragent::check_safari_ios_version());
1688         }
1690         // Check iOS Safari.
1691         $versions = array(
1692             // New versions should be added here.
1693             '527'       => false,
1694             '590'       => false,
1695             '600'       => false,
1696         );
1698         if (isset($tests['check_safari_ios_version'])) {
1699             // The test provider has overwritten some of the above checks.
1700             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1701             $versions = $tests['check_safari_ios_version'] + $versions;
1702         }
1704         foreach ($versions as $version => $result) {
1705             $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1706                 "Version incorrectly determined for iOS Safari version '{$version}'");
1707         }
1708     }
1710     /**
1711      * @dataProvider user_agents_providers
1712      */
1713     public function test_useragent_ios($useragent, $tests) {
1714         // Setup the core_useragent instance.
1715         core_useragent::instance(true, $useragent);
1717         if (isset($tests['is_ios']) && $tests['is_ios']) {
1718             $this->assertTrue(core_useragent::is_ios(),
1719                 "Browser was not identified as an iOS device browser");
1720             $this->assertTrue(core_useragent::check_safari_ios_version());
1721         } else {
1722             $this->assertFalse(core_useragent::is_ios(),
1723                 "Browser was incorrectly identified as an iOS device browser");
1724             $this->assertFalse(core_useragent::check_safari_ios_version());
1725         }
1726     }
1728     /**
1729      * @dataProvider user_agents_providers
1730      */
1731     public function test_useragent_gecko($useragent, $tests) {
1732         // Setup the core_useragent instance.
1733         core_useragent::instance(true, $useragent);
1735         if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1736             $this->assertTrue(core_useragent::is_gecko(),
1737                 "Browser was not identified as a gecko browser");
1738             $this->assertTrue(core_useragent::check_gecko_version());
1739         } else {
1740             $this->assertFalse(core_useragent::is_gecko(),
1741                 "Browser was incorrectly identified as a gecko browser");
1742             $this->assertFalse(core_useragent::check_gecko_version());
1743         }
1745         $versions = array(
1746             // New versions should be added here.
1747             '1'             => false,
1748             '2'             => false,
1749             '3.6'           => false,
1750             '4.0'           => false,
1751             '20030516'      => false,
1752             '20051116'      => false,
1753             '2006010100'    => false,
1754             '20100101'      => false,
1755             '15.0'          => false,
1756             '18.0'          => false,
1757             '19.0'          => false,
1758         );
1760         if (isset($tests['check_gecko_version'])) {
1761             // The test provider has overwritten some of the above checks.
1762             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1763             $versions = $tests['check_gecko_version'] + $versions;
1764         }
1766         foreach ($versions as $version => $result) {
1767             $this->assertEquals($result, core_useragent::check_gecko_version($version),
1768                 "Version incorrectly determined for Gecko version '{$version}'");
1769         }
1770     }
1772     /**
1773      * @dataProvider user_agents_providers
1774      */
1775     public function test_useragent_firefox($useragent, $tests) {
1776         // Setup the core_useragent instance.
1777         core_useragent::instance(true, $useragent);
1779         if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1780             $this->assertTrue(core_useragent::is_firefox(),
1781                 "Browser was not identified as a firefox browser");
1782             $this->assertTrue(core_useragent::check_firefox_version());
1783         } else {
1784             $this->assertFalse(core_useragent::is_firefox(),
1785                 "Browser was incorrectly identified as a firefox browser");
1786             $this->assertFalse(core_useragent::check_firefox_version());
1787         }
1789         $versions = array(
1790             // New versions should be added here.
1791             '1.5'       => false,
1792             '3.0'       => false,
1793             '4'         => false,
1794             '10'        => false,
1795             '15'        => false,
1796             '18'        => false,
1797             '19'        => false,
1798             '33'        => false,
1799         );
1801         if (isset($tests['check_firefox_version'])) {
1802             // The test provider has overwritten some of the above checks.
1803             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1804             $versions = $tests['check_firefox_version'] + $versions;
1805         }
1807         foreach ($versions as $version => $result) {
1808             $this->assertEquals($result, core_useragent::check_firefox_version($version),
1809                 "Version incorrectly determined for Firefox version '{$version}'");
1810         }
1811     }
1813     /**
1814      * @dataProvider user_agents_providers
1815      */
1816     public function test_useragent_opera($useragent, $tests) {
1817         // Setup the core_useragent instance.
1818         core_useragent::instance(true, $useragent);
1820         if (isset($tests['is_opera']) && $tests['is_opera']) {
1821             $this->assertTrue(core_useragent::is_opera(),
1822                 "Browser was not identified as a opera browser");
1823             $this->assertTrue(core_useragent::check_opera_version());
1824         } else {
1825             $this->assertFalse(core_useragent::is_opera(),
1826                 "Browser was incorrectly identified as a opera browser");
1827             $this->assertFalse(core_useragent::check_opera_version());
1828         }
1830         $versions = array(
1831             // New versions should be added here.
1832             '8.0'       => false,
1833             '9.0'       => false,
1834             '10.0'      => false,
1835             '12.15'     => false,
1836         );
1838         if (isset($tests['check_opera_version'])) {
1839             // The test provider has overwritten some of the above checks.
1840             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1841             $versions = $tests['check_opera_version'] + $versions;
1842         }
1844         foreach ($versions as $version => $result) {
1845             $this->assertEquals($result, core_useragent::check_opera_version($version),
1846                 "Version incorrectly determined for Opera version '{$version}'");
1847         }
1848     }
1850     /**
1851      * @dataProvider user_agents_providers
1852      */
1853     public function test_get_device_type($useragent, $tests) {
1854         // Setup the core_useragent instance.
1855         core_useragent::instance(true, $useragent);
1857         $expected = 'default';
1858         if (isset($tests['devicetype'])) {
1859             $expected = $tests['devicetype'];
1860         }
1862         $this->assertEquals($expected, core_useragent::get_device_type(),
1863             "Device Type was not correctly identified");
1864     }
1866     /**
1867      * @dataProvider user_agents_providers
1868      */
1869     public function test_get_browser_version_classes($useragent, $tests) {
1870         // Setup the core_useragent instance.
1871         core_useragent::instance(true, $useragent);
1873         $actual = core_useragent::get_browser_version_classes();
1874         foreach ($tests['versionclasses'] as $expectedclass) {
1875             $this->assertContains($expectedclass, $actual);
1876         }
1877         $this->assertCount(count($tests['versionclasses']), $actual);
1878     }
1880     /**
1881      * @dataProvider user_agents_providers
1882      */
1883     public function test_useragent_web_crawler($useragent, $tests) {
1884         // Setup the core_useragent instance.
1885         core_useragent::instance(true, $useragent);
1887         $expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
1888         $this->assertSame($expectation, core_useragent::is_web_crawler());
1889     }