Merge branch 'MDL-17943_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                         'edge',
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                         'edge'
101                     ),
103                     'devicetype'                    => 'mobile',
104                 ),
105             ),
106             // Windows 98; Internet Explorer 5.0.
107             array(
108                 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)',
109                 array(
110                     // MSIE 5.0 is not considered a browser at all: known false results.
111                     'is_ie'                         => false,
112                     'check_ie_version'              => array(
113                         '0'                         => true,
114                         '5.0'                       => true,
115                     ),
116                     'versionclasses'                => array(
117                         // IE 5.0 is not considered a browser.
118                     ),
120                     // IE 5.0 is a legacy browser.
121                     'devicetype'                    => 'legacy',
123                     'supports_svg'                  => false,
124                     'supports_json_contenttype'     => false,
125                 ),
126             ),
128             // Windows 2000; Internet Explorer 5.5.
129             array(
130                 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)',
131                 array(
132                     'is_ie'                         => true,
133                     'check_ie_version'              => array(
134                         '0'                         => true,
135                         '5.0'                       => true,
136                         '5.5'                       => true,
137                     ),
138                     'versionclasses'                => array(
139                         'ie',
140                     ),
142                     // IE 6.0 is a legacy browser.
143                     'devicetype'                    => 'legacy',
145                     'supports_svg'                  => false,
146                     'supports_json_contenttype'     => false,
147                 ),
148             ),
150             // Windows XP SP2; Internet Explorer 6.0.
151             array(
152                 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
153                 array(
154                     'is_ie'                         => true,
155                     'check_ie_version'              => array(
156                         '0'                         => true,
157                         '5.0'                       => true,
158                         '5.5'                       => true,
159                         '6.0'                       => true,
160                     ),
161                     'versionclasses'                => array(
162                         'ie',
163                         'ie6',
164                     ),
166                     // IE 7.0 is a legacy browser.
167                     'devicetype'                    => 'legacy',
169                     'supports_svg'                  => false,
170                     'supports_json_contenttype'     => false,
171                 ),
172             ),
174             // Windows XP SP2; Internet Explorer 7.0.
175             array(
176                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
177                 array(
178                     'is_ie'                         => true,
179                     'check_ie_version'              => array(
180                         '0'                         => true,
181                         '5.0'                       => true,
182                         '5.5'                       => true,
183                         '6.0'                       => true,
184                         '7.0'                       => true,
185                     ),
186                     'versionclasses'                => array(
187                         'ie',
188                         'ie7',
189                     ),
191                     'supports_svg'                  => false,
192                     'supports_json_contenttype'     => false,
193                 ),
194             ),
196             // Windows XP SP2; Internet Explorer 7.0; Meridio extension.
197             array(
198                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Meridio for Excel 5.0.251; Meridio for PowerPoint 5.0.251; Meridio for Word 5.0.251; Meridio Protocol; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)',
199                 array(
200                     'is_ie'                         => true,
201                     'check_ie_version'              => array(
202                         '0'                         => true,
203                         '5.0'                       => true,
204                         '5.5'                       => true,
205                         '6.0'                       => true,
206                         '7.0'                       => true,
207                     ),
208                     'versionclasses'                => array(
209                         'ie',
210                         'ie7',
211                     ),
213                     'supports_svg'                  => false,
214                     'supports_json_contenttype'     => false,
215                 ),
216             ),
218             // Windows Vista; Internet Explorer 8.0.
219             array(
220                 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)',
221                 array(
222                     'is_ie'                         => true,
223                     'check_ie_version'              => array(
224                         '0'                         => true,
225                         '5.0'                       => true,
226                         '5.5'                       => true,
227                         '6.0'                       => true,
228                         '7.0'                       => true,
229                         '8.0'                       => true,
230                     ),
231                     'versionclasses'                => array(
232                         'ie',
233                         'ie8',
234                     ),
236                     'supports_svg'                  => false,
237                 ),
238             ),
240             // Windows 7; Internet Explorer 9.0.
241             array(
242                 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
243                 array(
244                     'is_ie'                         => true,
245                     'check_ie_version'              => array(
246                         '0'                         => true,
247                         '5.0'                       => true,
248                         '5.5'                       => true,
249                         '6.0'                       => true,
250                         '7.0'                       => true,
251                         '8.0'                       => true,
252                         '9.0'                       => true,
253                     ),
254                     'versionclasses'                => array(
255                         'ie',
256                         'ie9',
257                     ),
258                 ),
259             ),
261             // Windows 7; Internet Explorer 9.0i.
262             array(
263                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)',
264                 array(
265                     'is_ie'                         => true,
266                     'check_ie_version'              => array(
267                         '0'                         => true,
268                         '5.0'                       => true,
269                         '5.5'                       => true,
270                         '6.0'                       => true,
271                         '7.0'                       => true,
272                         '8.0'                       => true,
273                         '9.0'                       => true,
274                     ),
275                     'versionclasses'                => array(
276                         'ie',
277                         'ie9',
278                     ),
279                     'iecompatibility'               => true,
281                     // IE 9 in Compatiblity mode does not support SVG.
282                     'supports_svg'                  => false,
284                     // IE in Compatiblity mode does not support JSON ContentType.
285                     'supports_json_contenttype'     => false,
286                 ),
287             ),
289             // Windows 8; Internet Explorer 10.0.
290             array(
291                 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)',
292                 array(
293                     'is_ie'                         => true,
294                     'check_ie_version'              => array(
295                         '0'                         => true,
296                         '5.0'                       => true,
297                         '5.5'                       => true,
298                         '6.0'                       => true,
299                         '7.0'                       => true,
300                         '8.0'                       => true,
301                         '9.0'                       => true,
302                         '10'                        => true,
303                     ),
304                     'versionclasses'                => array(
305                         'ie',
306                         'ie10',
307                     ),
308                 ),
309             ),
311             // Windows 8; Internet Explorer 10.0i.
312             array(
313                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)',
314                 array(
315                     'is_ie'                         => true,
316                     'check_ie_version'              => array(
317                         '0'                         => true,
318                         '5.0'                       => true,
319                         '5.5'                       => true,
320                         '6.0'                       => true,
321                         '7.0'                       => true,
322                         '8.0'                       => true,
323                         '9.0'                       => true,
324                         '10'                        => true,
325                     ),
326                     'iecompatibility'               => true,
327                     'versionclasses'                => array(
328                         'ie',
329                         'ie10',
330                     ),
332                     // IE in Compatiblity mode does not support JSON ContentType.
333                     'supports_json_contenttype'     => false,
334                 ),
335             ),
337             // Windows 8.1; Internet Explorer 11.0.
338             array(
339                 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)',
340                 array(
341                     'is_ie'                         => true,
342                     'check_ie_version'              => array(
343                         '0'                         => true,
344                         '5.0'                       => true,
345                         '5.5'                       => true,
346                         '6.0'                       => true,
347                         '7.0'                       => true,
348                         '8.0'                       => true,
349                         '9.0'                       => true,
350                         '10'                        => true,
351                         '11'                        => true,
352                     ),
353                     'versionclasses'                => array(
354                         'ie',
355                         'ie11',
356                     ),
357                 ),
358             ),
360             // Windows 8.1; Internet Explorer 11.0i.
361             array(
362                 ' Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
363                 array(
364                     'is_ie'                         => true,
365                     'check_ie_version'              => array(
366                         '0'                         => true,
367                         '5.0'                       => true,
368                         '5.5'                       => true,
369                         '6.0'                       => true,
370                         '7.0'                       => true,
371                         '8.0'                       => true,
372                         '9.0'                       => true,
373                         '10'                        => true,
374                         '11'                        => true,
375                     ),
376                     'iecompatibility'               => true,
377                     'versionclasses'                => array(
378                         'ie',
379                         'ie11',
380                     ),
382                     // IE in Compatiblity mode does not support JSON ContentType.
383                     'supports_json_contenttype'     => false,
384                 ),
385             ),
387             // Windows XP; Firefox 1.0.6.
388             array(
389                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
390                 array(
391                     'is_firefox'                    => true,
393                     'is_gecko'                      => true,
394                     'check_gecko_version'           => array(
395                         '1'                         => true,
396                     ),
398                     'versionclasses'                => array(
399                         'gecko',
400                         'gecko17',
401                     ),
402                 ),
403             ),
405             // Windows XP; Firefox 1.0.6.
406             array(
407                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
408                 array(
409                     'is_firefox'                    => true,
410                     'check_firefox_version'         => array(
411                         '1.5'                       => true,
412                     ),
414                     'is_gecko'                      => true,
415                     'check_gecko_version'           => array(
416                         '1'                         => true,
417                         '20030516'                  => true,
418                         '20051116'                  => true,
419                     ),
421                     'versionclasses'                => array(
422                         'gecko',
423                         'gecko18',
424                     ),
425                 ),
426             ),
428             // Windows XP; Firefox 1.5.0.1.
429             array(
430                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
431                 array(
432                     'is_firefox'                    => true,
433                     'check_firefox_version'         => array(
434                         '1.5'                       => true,
435                     ),
437                     'is_gecko'                      => true,
438                     'check_gecko_version'           => array(
439                         '1'                         => true,
440                         '20030516'                  => true,
441                         '20051116'                  => true,
442                     ),
444                     'versionclasses'                => array(
445                         'gecko',
446                         'gecko18',
447                     ),
448                 ),
449             ),
451             // Windows XP; Firefox 2.0.
452             array(
453                 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
454                 array(
455                     'is_firefox'                    => true,
456                     'check_firefox_version'         => array(
457                         '1.5'                       => true,
458                     ),
460                     'is_gecko'                      => true,
461                     'check_gecko_version'           => array(
462                         '1'                         => true,
463                         '2'                         => true,
464                         '20030516'                  => true,
465                         '20051116'                  => true,
466                         '2006010100'                => true,
467                     ),
469                     'versionclasses'                => array(
470                         'gecko',
471                         'gecko18',
472                     ),
473                 ),
474             ),
476             // Ubuntu Linux amd64; Firefox 2.0.
477             array(
478                 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
479                 array(
480                     'is_firefox'                    => true,
481                     'check_firefox_version'         => array(
482                         '1.5'                       => true,
483                     ),
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                     ),
494                     'versionclasses'                => array(
495                         'gecko',
496                         'gecko18',
497                     ),
498                 ),
499             ),
501             // SUSE; Firefox 3.0.6.
502             array(
503                 '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',
504                 array(
505                     'is_firefox'                    => true,
506                     'check_firefox_version'         => array(
507                         '1.5'                       => true,
508                         '3.0'                       => true,
509                     ),
511                     'is_gecko'                      => true,
512                     'check_gecko_version'           => array(
513                         '1'                         => true,
514                         '2'                         => true,
515                         '20030516'                  => true,
516                         '20051116'                  => true,
517                         '2006010100'                => true,
518                     ),
520                     'versionclasses'                => array(
521                         'gecko',
522                         'gecko19',
523                     ),
524                 ),
525             ),
527             // Linux i686; Firefox 3.6.
528             array(
529                 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
530                 array(
531                     'is_firefox'                    => true,
532                     'check_firefox_version'         => array(
533                         '1.5'                       => true,
534                         '3.0'                       => true,
535                     ),
537                     'is_gecko'                      => true,
538                     'check_gecko_version'           => array(
539                         '1'                         => true,
540                         '2'                         => true,
541                         '20030516'                  => true,
542                         '20051116'                  => true,
543                         '2006010100'                => true,
544                         '3.6'                       => true,
545                         '20100101'                  => true,
546                     ),
548                     'versionclasses'                => array(
549                         'gecko',
550                         'gecko20',
551                     ),
552                 ),
553             ),
555             // Windows; Firefox 11.0.
556             array(
557                 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
558                 array(
559                     'is_firefox'                    => true,
560                     'check_firefox_version'         => array(
561                         '1.5'                       => true,
562                         '3.0'                       => true,
563                         '4'                         => true,
564                         '10'                        => true,
565                     ),
567                     'is_gecko'                      => true,
568                     'check_gecko_version'           => array(
569                         '1'                         => true,
570                         '2'                         => true,
571                         '20030516'                  => true,
572                         '20051116'                  => true,
573                         '2006010100'                => true,
574                         '20100101'                  => true,
575                         '3.6'                       => true,
576                         '4.0'                       => true,
577                     ),
579                     'versionclasses'                => array(
580                         'gecko',
581                     ),
582                 ),
583             ),
585             // Windows; Firefox 15.0a2.
586             array(
587                 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
588                 array(
589                     'is_firefox'                    => true,
590                     'check_firefox_version'         => array(
591                         '1.5'                       => true,
592                         '3.0'                       => true,
593                         '4'                         => true,
594                         '10'                        => true,
595                         '15'                        => true,
596                     ),
598                     'is_gecko'                      => true,
599                     'check_gecko_version'           => array(
600                         '1'                         => true,
601                         '2'                         => true,
602                         '20030516'                  => true,
603                         '20051116'                  => true,
604                         '2006010100'                => true,
605                         '20100101'                  => true,
606                         '3.6'                       => true,
607                         '4.0'                       => true,
608                         '15.0'                      => true,
609                     ),
611                     'versionclasses'                => array(
612                         'gecko',
613                     ),
614                 ),
615             ),
617             // Firefox 18; Mac OS X 10.
618             array(
619                 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
620                 array(
621                     'is_firefox'                    => true,
622                     'check_firefox_version'         => array(
623                         '1.5'                       => true,
624                         '3.0'                       => true,
625                         '4'                         => true,
626                         '10'                        => true,
627                         '15'                        => true,
628                         '18'                        => true,
629                     ),
631                     'is_gecko'                      => true,
632                     'check_gecko_version'           => array(
633                         '1'                         => true,
634                         '2'                         => true,
635                         '20030516'                  => true,
636                         '20051116'                  => true,
637                         '2006010100'                => true,
638                         '3.6'                       => true,
639                         '4.0'                       => true,
640                         '15.0'                      => true,
641                         '18.0'                      => true,
642                         '20100101'                  => true,
643                     ),
645                     'versionclasses'                => array(
646                         'gecko',
647                     ),
648                 ),
649             ),
651             // Firefox 33; Mac OS X 10.10.
652             array(
653                 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
654                 array(
655                     'is_firefox'                    => true,
656                     'check_firefox_version'         => array(
657                         '1.5'                       => true,
658                         '3.0'                       => true,
659                         '4'                         => true,
660                         '10'                        => true,
661                         '15'                        => true,
662                         '18'                        => true,
663                         '19'                        => true,
664                         '33'                        => true,
665                     ),
667                     'is_gecko'                      => true,
668                     'check_gecko_version'           => array(
669                         '1'                         => true,
670                         '2'                         => true,
671                         '20030516'                  => true,
672                         '20051116'                  => true,
673                         '2006010100'                => true,
674                         '3.6'                       => true,
675                         '4.0'                       => true,
676                         '15.0'                      => true,
677                         '18.0'                      => true,
678                         '19.0'                      => true,
679                         '20100101'                  => true,
680                     ),
682                     'versionclasses'                => array(
683                         'gecko',
684                     ),
685                 ),
686             ),
688             // SeaMonkey 2.0; Windows.
689             array(
690                 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
691                 array(
692                     'is_gecko'                      => true,
693                     'check_gecko_version'           => array(
694                         '1'                         => true,
695                         '2'                         => true,
696                         '20030516'                  => true,
697                         '20051106'                  => true,
698                         '20051116'                  => true,
699                         '2006010100'                => true,
700                     ),
702                     'versionclasses'                => array(
703                         'gecko',
704                         'gecko19',
705                     ),
706                 ),
707             ),
709             // SeaMonkey 2.1; Linux.
710             array(
711                 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
712                 array(
713                     'is_gecko'                      => true,
714                     'check_gecko_version'           => array(
715                         '1'                         => true,
716                         '2'                         => true,
717                         '20030516'                  => true,
718                         '20051116'                  => true,
719                         '2006010100'                => true,
720                         '20100101'                  => true,
721                         '3.6'                       => true,
722                         '4.0'                       => true,
723                     ),
725                     'is_firefox'                    => true,
726                     'check_firefox_version'         => array(
727                         '1.5'                       => true,
728                         '3.0'                       => true,
729                         '4'                         => true,
730                     ),
732                     'versionclasses'                => array(
733                         'gecko',
734                         'gecko20',
735                     ),
736                 ),
737             ),
739             // SeaMonkey 2.3; FreeBSD.
740             array(
741                 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
742                 array(
743                     'is_gecko'                      => true,
744                     'check_gecko_version'           => array(
745                         '1'                         => true,
746                         '2'                         => true,
747                         '20030516'                  => true,
748                         '20051116'                  => true,
749                         '2006010100'                => true,
750                         '20100101'                  => true,
751                         '3.6'                       => true,
752                         '4.0'                       => true,
753                     ),
755                     'is_firefox'                    => true,
756                     'check_firefox_version'         => array(
757                         '1.5'                       => true,
758                         '3.0'                       => true,
759                         '4'                         => true,
760                     ),
762                     'versionclasses'                => array(
763                         'gecko',
764                     ),
765                 ),
766             ),
768             // Windows 7; MS Word 2010.
769             array(
770                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; ms-office)',
771                 array(
772                     'is_ie'                         => true,
773                     'check_ie_version'              => array(
774                         '0'                         => true,
775                         '5.0'                       => true,
776                         '5.5'                       => true,
777                         '6.0'                       => true,
778                         '7.0'                       => true,
779                         '8.0'                       => true,
780                     ),
781                     'iecompatibility'               => true,
782                     'versionclasses'                => array(
783                         'ie',
784                         'ie8',
785                     ),
787                     'is_msword'                     => true,
789                     'supports_svg'                  => false,
790                     'supports_json_contenttype'     => false,
791                 ),
792             ),
794             // Windows 7; MS Outlook 2010.
795             array(
796                 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Microsoft Outlook 14.0.7113; ms-office; MSOffice 14)',
797                 array(
798                     'is_ie'                         => true,
799                     'check_ie_version'              => array(
800                         '0'                         => true,
801                         '5.0'                       => true,
802                         '5.5'                       => true,
803                         '6.0'                       => true,
804                         '7.0'                       => true,
805                         '8.0'                       => true,
806                     ),
807                     'iecompatibility'               => true,
808                     'versionclasses'                => array(
809                         'ie',
810                         'ie8',
811                     ),
813                     // Note: Outlook is deliberately not considered to be MS Word.
814                     'is_msword'                     => false,
816                     'supports_svg'                  => false,
817                     'supports_json_contenttype'     => false,
818                 ),
819             ),
821             // Mac OS X; MS Word 14.
822             array(
823                 'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
824                 array(
825                     'versionclasses'                => array(
826                     ),
828                     'is_msword'                     => true,
829                 ),
830             ),
832             // Safari 312; Max OS X.
833             array(
834                 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
835                 array(
836                     'is_safari'                     => true,
837                     'check_safari_version'          => array(
838                         '1'                         => true,
839                         '312'                       => true,
840                     ),
842                     'is_webkit'                     => true,
844                     'versionclasses'                => array(
845                         'safari',
846                     ),
847                 ),
848             ),
850             // Safari 412; Max OS X.
851             array(
852                 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
853                 array(
854                     'is_safari'                     => true,
855                     'check_safari_version'          => array(
856                         '1'                         => true,
857                         '312'                       => true,
858                     ),
860                     'is_webkit'                     => true,
862                     'versionclasses'                => array(
863                         'safari',
864                     ),
865                 ),
866             ),
868             // Safari 2.0; Max OS X.
869             array(
870                 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
871                 array(
872                     'is_safari'                     => true,
873                     'check_safari_version'          => array(
874                         '1'                         => true,
875                         '312'                       => true,
876                     ),
878                     'is_webkit'                     => true,
880                     'versionclasses'                => array(
881                         'safari',
882                     ),
883                 ),
884             ),
886             // iOS Safari 528; iPhone.
887             array(
888                 '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',
889                 array(
890                     // Note: We do *not* identify mobile Safari as Safari.
891                     'is_safari_ios'                 => true,
892                     'is_ios'                        => true,
893                     'check_safari_ios_version'      => array(
894                         '527'                       => true,
895                     ),
897                     'is_webkit'                     => true,
899                     'versionclasses'                => array(
900                         'ios'
901                     ),
903                     'devicetype'                    => 'mobile',
904                ),
905             ),
907             // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
908             array(
909                 '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',
910                 array(
911                     // Note: We do *not* identify mobile Safari as Safari.
912                     'is_safari_ios'                 => true,
913                     'is_ios'                        => true,
914                     'check_safari_ios_version'      => array(
915                         '527'                       => true,
916                         '590'                       => true,
917                         '600'                       => true,
918                     ),
920                     'is_webkit'                     => true,
922                     'versionclasses'                => array(
923                         'ios',
924                     ),
926                     'devicetype'                    => 'mobile',
927                ),
928             ),
930             // iOS Safari 533; iPad.
931             array(
932                 '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',
933                 array(
934                     // Note: We do *not* identify mobile Safari as Safari.
935                     'is_safari_ios'                 => true,
936                     'is_ios'                        => true,
937                     'check_safari_ios_version'      => array(
938                         '527'                       => true,
939                     ),
941                     'is_webkit'                     => true,
943                     'versionclasses'                => array(
944                         'ios',
945                     ),
947                     'devicetype'                    => 'tablet',
948                ),
949             ),
951             // Android WebKit 525; G1 Phone.
952             'Android WebKit 525; G1 Phone' => array(
953                 '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',
954                 array(
955                     'is_webkit_android'             => true,
956                     'check_webkit_android_version'  => array(
957                         '525'                       => true,
958                     ),
960                     'is_webkit'                     => true,
962                     'versionclasses'                => array(
963                         'android',
964                     ),
966                     'devicetype'                    => 'mobile',
968                     'supports_svg'                  => false,
969                ),
970             ),
972             // Android WebKit 530; Nexus.
973             'Android WebKit 530; Nexus' => array(
974                 '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',
975                 array(
976                     'is_webkit_android'             => true,
977                     'check_webkit_android_version'  => array(
978                         '525'                       => true,
979                         '527'                       => true,
980                     ),
982                     'is_webkit'                     => true,
984                     'versionclasses'                => array(
985                         'android',
986                     ),
988                     'devicetype'                    => 'mobile',
990                     'supports_svg'                  => false,
991                ),
992             ),
994             // Android WebKit 537; Samsung GT-9505.
995             array(
996                 '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',
997                 array(
998                     'is_webkit_android'             => true,
999                     'check_webkit_android_version'  => array(
1000                         '525'                       => true,
1001                         '527'                       => true,
1002                     ),
1004                     'is_webkit'                     => true,
1006                     'is_chrome'                     => true,
1007                     'check_chrome_version'          => array(
1008                         '7'                         => true,
1009                         '8'                         => true,
1010                         '10'                        => true,
1011                     ),
1013                     'versionclasses'                => array(
1014                         'chrome',
1015                         'android',
1016                     ),
1018                     'devicetype'                    => 'mobile',
1019                 ),
1020             ),
1022             // Android WebKit 537; Nexus 5.
1023             array(
1024                 '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',
1025                 array(
1026                     'is_webkit_android'             => true,
1027                     'check_webkit_android_version'  => array(
1028                         '525'                       => true,
1029                         '527'                       => true,
1030                     ),
1032                     'is_webkit'                     => true,
1034                     'is_chrome'                     => true,
1035                     'check_chrome_version'          => array(
1036                         '7'                         => true,
1037                         '8'                         => true,
1038                         '10'                        => true,
1039                     ),
1041                     'versionclasses'                => array(
1042                         'chrome',
1043                         'android',
1044                     ),
1046                     'devicetype'                    => 'mobile',
1047                 ),
1048             ),
1050             // Chrome 8; Mac OS X.
1051             array(
1052                 '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',
1053                 array(
1054                     'is_chrome'                     => true,
1055                     'check_chrome_version'          => array(
1056                         '7'                         => true,
1057                         '8'                         => true,
1058                     ),
1060                     'is_webkit'                     => true,
1062                     'versionclasses'                => array(
1063                         'chrome',
1064                     ),
1065                 ),
1066             ),
1068             // Chrome 39; Mac OS X.
1069             array(
1070                 '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',
1071                 array(
1072                     'is_chrome'                     => true,
1073                     'check_chrome_version'          => array(
1074                         '7'                         => true,
1075                         '8'                         => true,
1076                         '10'                        => true,
1077                         '39'                        => true,
1078                     ),
1080                     'is_webkit'                     => true,
1082                     'versionclasses'                => array(
1083                         'chrome',
1084                     ),
1085                 ),
1086             ),
1088             // Opera 8.51; Windows XP.
1089             array(
1090                 'Opera/8.51 (Windows NT 5.1; U; en)',
1091                 array(
1092                     'is_opera'                      => true,
1093                     'check_opera_version'           => array(
1094                         '8.0'                       => true,
1095                     ),
1097                     'versionclasses'                => array(
1098                         'opera',
1099                     ),
1101                     'supports_svg'                  => false,
1102                ),
1103             ),
1105             // Opera 9.0; Windows XP.
1106             array(
1107                 'Opera/9.0 (Windows NT 5.1; U; en)',
1108                 array(
1109                     'is_opera'                      => true,
1110                     'check_opera_version'           => array(
1111                         '8.0'                       => true,
1112                         '9.0'                       => true,
1113                     ),
1115                     'versionclasses'                => array(
1116                         'opera',
1117                     ),
1119                     'supports_svg'                  => false,
1120                ),
1121             ),
1123             // Opera 12.15 (Build 1748); Mac OS X.
1124             array(
1125                 'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
1126                 array(
1127                     'is_opera'                      => true,
1128                     'check_opera_version'           => array(
1129                         '8.0'                       => true,
1130                         '9.0'                       => true,
1131                         '10.0'                      => true,
1132                         '12.15'                     => true,
1133                     ),
1135                     'versionclasses'                => array(
1136                         'opera',
1137                     ),
1139                     'supports_svg'                  => false,
1140                ),
1141             ),
1143             // Opera 9.0; Debian Linux.
1144             array(
1145                 'Opera/9.01 (X11; Linux i686; U; en)',
1146                 array(
1147                     'is_opera'                      => true,
1148                     'check_opera_version'           => array(
1149                         '8.0'                       => true,
1150                         '9.0'                       => true,
1151                     ),
1153                     'versionclasses'                => array(
1154                         'opera',
1155                     ),
1157                     'supports_svg'                  => false,
1158                ),
1159             ),
1161             // Google web crawlers.
1162             array(
1163                 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
1164                 array(
1165                     'is_web_crawler'                => true,
1166                     'versionclasses'                => array(
1167                     ),
1168                ),
1169             ),
1170             array(
1171                 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
1172                 array(
1173                     'is_web_crawler'                => true,
1174                     'versionclasses'                => array(
1175                     ),
1176                ),
1177             ),
1178             array(
1179                 'Googlebot-Image/1.0',
1180                 array(
1181                     'is_web_crawler'                => true,
1182                     'versionclasses'                => array(
1183                     ),
1184                ),
1185             ),
1187             // Yahoo crawlers.
1188             // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
1189             array(
1190                 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
1191                 array(
1192                     'is_web_crawler'                => true,
1193                     'versionclasses'                => array(
1194                     ),
1195                ),
1196             ),
1198             // Bing / MSN / AdIdx crawlers.
1199             // See http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0.
1200             array(
1201                 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
1202                 array(
1203                     'is_web_crawler'                => true,
1204                     'versionclasses'                => array(
1205                     ),
1206                ),
1207             ),
1208             array(
1209                 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
1210                 array(
1211                     'is_web_crawler'                => true,
1212                     'versionclasses'                => array(
1213                     ),
1214                ),
1215             ),
1216             array(
1217                 '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)',
1218                 array(
1219                     'is_web_crawler'                => true,
1220                     'is_webkit'                     => true,
1221                     'is_safari_ios'                 => true,
1222                     'is_ios'                        => true,
1223                     'check_safari_ios_version'      => array(
1224                         '527'                       => true,
1225                     ),
1227                     'versionclasses'                => array(
1228                         'ios',
1229                     ),
1231                     'devicetype'                    => 'mobile',
1232                ),
1233             ),
1234             array(
1235                 '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)',
1236                 array(
1237                     'is_web_crawler'                => true,
1238                     'is_ie'                         => true,
1239                     'check_ie_version'              => array(
1240                         '0'                         => true,
1241                         '5.0'                       => true,
1242                         '5.5'                       => true,
1243                         '6.0'                       => true,
1244                         '7.0'                       => true,
1245                         '8.0'                       => true,
1246                         '9.0'                       => true,
1247                         '10'                        => true,
1248                         '11'                        => true,
1249                     ),
1250                     'versionclasses'                => array(
1251                         'ie',
1252                         'ie11',
1253                     ),
1254                     'devicetype'                    => 'mobile',
1255                ),
1256             ),
1258             array(
1259                 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
1260                 array(
1261                     'is_web_crawler'                => true,
1262                     'versionclasses'                => array(
1263                     ),
1264                ),
1265             ),
1266             array(
1267                 'msnbot/2.1',
1268                 array(
1269                     'is_web_crawler'                => true,
1270                     'versionclasses'                => array(
1271                     ),
1272                ),
1273             ),
1274             array(
1275                 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
1276                 array(
1277                     'is_web_crawler'                => true,
1278                     'versionclasses'                => array(
1279                     ),
1280                ),
1281             ),
1282             array(
1283                 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
1284                 array(
1285                     'is_web_crawler'                => true,
1286                     'is_webkit'                     => true,
1287                     'is_safari'                     => true,
1288                     'check_safari_version'          => array(
1289                         '1'                         => true,
1290                         '312'                       => true,
1291                         '500'                       => true,
1292                     ),
1294                     'versionclasses'                => array(
1295                         'safari',
1296                     ),
1297                ),
1298             ),
1299             array(
1300                 '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',
1301                 array(
1302                     'is_web_crawler'                => true,
1303                     'is_ie'                         => true,
1304                     'check_ie_version'              => array(
1305                         '0'                         => true,
1306                         '5.0'                       => true,
1307                         '5.5'                       => true,
1308                         '6.0'                       => true,
1309                         '7.0'                       => true,
1310                         '8.0'                       => true,
1311                         '9.0'                       => true,
1312                         '10'                        => true,
1313                         '11'                        => true,
1314                     ),
1315                     'versionclasses'                => array(
1316                         'ie',
1317                         'ie11',
1318                     ),
1319                     'devicetype'                    => 'mobile',
1320                ),
1321             ),
1323             // Yandex.
1324             // See http://help.yandex.com/search/robots/agent.xml.
1325             array(
1326                 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
1327                 array(
1328                     'is_web_crawler'                => true,
1329                     'versionclasses'                => array(
1330                     ),
1331                ),
1332             ),
1333             array(
1334                 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
1335                 array(
1336                     'is_web_crawler'                => true,
1337                     'versionclasses'                => array(
1338                     ),
1339                ),
1340             ),
1342             // AltaVista.
1343             array(
1344                 'AltaVista V2.0B crawler@evreka.com',
1345                 array(
1346                     'is_web_crawler'                => true,
1347                     'versionclasses'                => array(
1348                     ),
1349                ),
1350             ),
1352             // ZoomSpider.
1353             array(
1354                 'ZoomSpider - wrensoft.com [ZSEBOT]',
1355                 array(
1356                     'is_web_crawler'                => true,
1357                     'versionclasses'                => array(
1358                     ),
1359                ),
1360             ),
1362             // Baidu.
1363             array(
1364                 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
1365                 array(
1366                     'is_web_crawler'                => true,
1367                     'versionclasses'                => array(
1368                     ),
1369                ),
1370             ),
1371             array(
1372                 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
1373                 array(
1374                     'is_web_crawler'                => true,
1375                     'versionclasses'                => array(
1376                     ),
1377                ),
1378             ),
1380             // Ask.com.
1381             array(
1382                 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
1383                 array(
1384                     'is_web_crawler'                => true,
1385                     'versionclasses'                => array(
1386                     ),
1387                ),
1388             ),
1389         );
1390     }
1392     /**
1393      * Test instance generation.
1394      */
1395     public function test_instance() {
1396         $this->assertInstanceOf('core_useragent', core_useragent::instance());
1397         $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
1398     }
1400     /**
1401      * @dataProvider user_agents_providers
1402      */
1403     public function test_useragent_edge($useragent, $tests) {
1404         // Setup the core_useragent instance.
1405         core_useragent::instance(true, $useragent);
1407         // Edge Tests.
1408         if (isset($tests['is_edge']) && $tests['is_edge']) {
1409             $this->assertTrue(core_useragent::is_edge());
1410         } else {
1411             $this->assertFalse(core_useragent::is_edge());
1412         }
1414         $versions = array(
1415             // New versions of should be added here.
1416             '12'   => false,
1417         );
1419         if (isset($tests['check_edge_version'])) {
1420             // The test provider has overwritten some of the above checks.
1421             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1422             $versions = $tests['check_edge_version'] + $versions;
1423         }
1425         foreach ($versions as $version => $result) {
1426             $this->assertEquals($result, core_useragent::check_edge_version($version),
1427                 "Version incorrectly determined for Edge version '{$version}'");
1428         }
1429     }
1431     /**
1432      * @dataProvider user_agents_providers
1433      */
1434     public function test_useragent_ie($useragent, $tests) {
1435         // Setup the core_useragent instance.
1436         core_useragent::instance(true, $useragent);
1438         // IE Tests.
1439         if (isset($tests['is_ie']) && $tests['is_ie']) {
1440             $this->assertTrue(core_useragent::is_ie());
1441         } else {
1442             $this->assertFalse(core_useragent::is_ie());
1443         }
1445         $versions = array(
1446             // New versions of should be added here.
1447             '0'    => false,
1448             '5.0'  => false,
1449             '5.5'  => false,
1450             '6.0'  => false,
1451             '7.0'  => false,
1452             '8.0'  => false,
1453             '9.0'  => false,
1454             '10'   => false,
1455             '11'   => false,
1456             '12'   => false,
1457             '13'   => false,
1458             '14'   => false,
1459         );
1461         if (isset($tests['check_ie_version'])) {
1462             // The test provider has overwritten some of the above checks.
1463             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1464             $versions = $tests['check_ie_version'] + $versions;
1465         }
1467         foreach ($versions as $version => $result) {
1468             $this->assertEquals($result, core_useragent::check_ie_version($version),
1469                 "Version incorrectly determined for IE version '{$version}'");
1470         }
1472         // IE Compatibility mode.
1473         if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1474             $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1475         } else {
1476             $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1477         }
1479     }
1481     /**
1482      * @dataProvider user_agents_providers
1483      */
1484     public function test_useragent_msword($useragent, $tests) {
1485         // Setup the core_useragent instance.
1486         core_useragent::instance(true, $useragent);
1488         // MSWord Tests.
1489         if (isset($tests['is_msword']) && $tests['is_msword']) {
1490             $this->assertTrue(core_useragent::is_msword());
1491         } else {
1492             $this->assertFalse(core_useragent::is_msword());
1493         }
1494     }
1497     /**
1498      * @dataProvider user_agents_providers
1499      */
1500     public function test_useragent_supports($useragent, $tests) {
1501         // Setup the core_useragent instance.
1502         core_useragent::instance(true, $useragent);
1504         // Supports SVG.
1505         if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1506             $this->assertTrue(core_useragent::supports_svg(),
1507                 "SVG Support was not reported (and should have been)");
1508         } else {
1509             $this->assertFalse(core_useragent::supports_svg(),
1510                 "SVG Support was reported (and should not have been)");
1511         }
1513         // Supports JSON ContentType.
1514         if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
1515             $this->assertTrue(core_useragent::supports_json_contenttype(),
1516                 "JSON ContentType Support was not reported (and should have been)");
1517         } else {
1518             $this->assertFalse(core_useragent::supports_json_contenttype(),
1519                 "JSON ContentType Support was reported (and should not have been)");
1520         }
1521     }
1523     /**
1524      * @dataProvider user_agents_providers
1525      */
1526     public function test_useragent_webkit($useragent, $tests) {
1527         // Setup the core_useragent instance.
1528         core_useragent::instance(true, $useragent);
1530         if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1531             $this->assertTrue(core_useragent::is_webkit(),
1532                 "Browser was not identified as a webkit browser");
1533             $this->assertTrue(core_useragent::check_webkit_version());
1534         } else {
1535             $this->assertFalse(core_useragent::is_webkit(),
1536                 "Browser was incorrectly identified as a webkit browser");
1537             $this->assertFalse(core_useragent::check_webkit_version());
1538         }
1540         $versions = array(
1541             // New versions should be added here.
1542         );
1544         if (isset($tests['check_webkit_version'])) {
1545             // The test provider has overwritten some of the above checks.
1546             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1547             $versions = $tests['check_webkit_version'] + $versions;
1548         }
1550         foreach ($versions as $version => $result) {
1551             $this->assertEquals($result, core_useragent::check_webkit_version($version),
1552                 "Version incorrectly determined for Webkit version '{$version}'");
1553         }
1554     }
1556     /**
1557      * @dataProvider user_agents_providers
1558      */
1559     public function test_useragent_webkit_android($useragent, $tests) {
1560         // Setup the core_useragent instance.
1561         core_useragent::instance(true, $useragent);
1563         if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1564             $this->assertTrue(core_useragent::is_webkit_android(),
1565                 "Browser was not identified as an Android webkit browser");
1566             $this->assertTrue(core_useragent::check_webkit_android_version());
1567         } else {
1568             $this->assertFalse(core_useragent::is_webkit_android(),
1569                 "Browser was incorrectly identified as an Android webkit browser");
1570             $this->assertFalse(core_useragent::check_webkit_android_version());
1571         }
1573         $versions = array(
1574             // New versions should be added here.
1575             '525'       => false,
1576             '527'       => false,
1577             '590'       => false,
1578         );
1580         if (isset($tests['check_webkit_android_version'])) {
1581             // The test provider has overwritten some of the above checks.
1582             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1583             $versions = $tests['check_webkit_android_version'] + $versions;
1584         }
1586         foreach ($versions as $version => $result) {
1587             $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1588                 "Version incorrectly determined for Android webkit version '{$version}'");
1589         }
1590     }
1592     /**
1593      * @dataProvider user_agents_providers
1594      */
1595     public function test_useragent_chrome($useragent, $tests) {
1596         // Setup the core_useragent instance.
1597         core_useragent::instance(true, $useragent);
1599         if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1600             $this->assertTrue(core_useragent::is_chrome(),
1601                 "Browser was not identified as a chrome browser");
1602             $this->assertTrue(core_useragent::check_chrome_version());
1603         } else {
1604             $this->assertFalse(core_useragent::is_chrome(),
1605                 "Browser was incorrectly identified as a chrome browser");
1606             $this->assertFalse(core_useragent::check_chrome_version());
1607         }
1609         $versions = array(
1610             // New versions should be added here.
1611             '7'         => false,
1612             '8'         => false,
1613             '10'        => false,
1614             '39'        => false,
1615         );
1617         if (isset($tests['check_chrome_version'])) {
1618             // The test provider has overwritten some of the above checks.
1619             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1620             $versions = $tests['check_chrome_version'] + $versions;
1621         }
1623         foreach ($versions as $version => $result) {
1624             $this->assertEquals($result, core_useragent::check_chrome_version($version),
1625                 "Version incorrectly determined for Chrome version '{$version}'");
1626         }
1627     }
1629     /**
1630      * @dataProvider user_agents_providers
1631      */
1632     public function test_useragent_safari($useragent, $tests) {
1633         // Setup the core_useragent instance.
1634         core_useragent::instance(true, $useragent);
1636         if (isset($tests['is_safari']) && $tests['is_safari']) {
1637             $this->assertTrue(core_useragent::is_safari(),
1638                 "Browser was not identified as a safari browser");
1639             $this->assertTrue(core_useragent::check_safari_version());
1640         } else {
1641             $this->assertFalse(core_useragent::is_safari(),
1642                 "Browser was incorrectly identified as a safari browser");
1643             $this->assertFalse(core_useragent::check_safari_version());
1644         }
1646         // Check Safari (generic).
1647         $versions = array(
1648             // New versions should be added here.
1649             '1'         => false,
1650             '312'       => false,
1651             '500'       => false,
1652         );
1654         if (isset($tests['check_safari_version'])) {
1655             // The test provider has overwritten some of the above checks.
1656             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1657             $versions = $tests['check_safari_version'] + $versions;
1658         }
1660         foreach ($versions as $version => $result) {
1661             $this->assertEquals($result, core_useragent::check_safari_version($version),
1662                 "Version incorrectly determined for Safari (generic) version '{$version}'");
1663         }
1664     }
1666     /**
1667      * @dataProvider user_agents_providers
1668      */
1669     public function test_useragent_ios_safari($useragent, $tests) {
1670         // Setup the core_useragent instance.
1671         core_useragent::instance(true, $useragent);
1673         if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1674             $this->assertTrue(core_useragent::is_safari_ios(),
1675                 "Browser was not identified as an iOS safari browser");
1676             $this->assertTrue(core_useragent::check_safari_ios_version());
1677         } else {
1678             $this->assertFalse(core_useragent::is_safari_ios(),
1679                 "Browser was incorrectly identified as an iOS safari browser");
1680             $this->assertFalse(core_useragent::check_safari_ios_version());
1681         }
1683         // Check iOS Safari.
1684         $versions = array(
1685             // New versions should be added here.
1686             '527'       => false,
1687             '590'       => false,
1688             '600'       => false,
1689         );
1691         if (isset($tests['check_safari_ios_version'])) {
1692             // The test provider has overwritten some of the above checks.
1693             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1694             $versions = $tests['check_safari_ios_version'] + $versions;
1695         }
1697         foreach ($versions as $version => $result) {
1698             $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1699                 "Version incorrectly determined for iOS Safari version '{$version}'");
1700         }
1701     }
1703     /**
1704      * @dataProvider user_agents_providers
1705      */
1706     public function test_useragent_ios($useragent, $tests) {
1707         // Setup the core_useragent instance.
1708         core_useragent::instance(true, $useragent);
1710         if (isset($tests['is_ios']) && $tests['is_ios']) {
1711             $this->assertTrue(core_useragent::is_ios(),
1712                 "Browser was not identified as an iOS device browser");
1713             $this->assertTrue(core_useragent::check_safari_ios_version());
1714         } else {
1715             $this->assertFalse(core_useragent::is_ios(),
1716                 "Browser was incorrectly identified as an iOS device browser");
1717             $this->assertFalse(core_useragent::check_safari_ios_version());
1718         }
1719     }
1721     /**
1722      * @dataProvider user_agents_providers
1723      */
1724     public function test_useragent_gecko($useragent, $tests) {
1725         // Setup the core_useragent instance.
1726         core_useragent::instance(true, $useragent);
1728         if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1729             $this->assertTrue(core_useragent::is_gecko(),
1730                 "Browser was not identified as a gecko browser");
1731             $this->assertTrue(core_useragent::check_gecko_version());
1732         } else {
1733             $this->assertFalse(core_useragent::is_gecko(),
1734                 "Browser was incorrectly identified as a gecko browser");
1735             $this->assertFalse(core_useragent::check_gecko_version());
1736         }
1738         $versions = array(
1739             // New versions should be added here.
1740             '1'             => false,
1741             '2'             => false,
1742             '3.6'           => false,
1743             '4.0'           => false,
1744             '20030516'      => false,
1745             '20051116'      => false,
1746             '2006010100'    => false,
1747             '20100101'      => false,
1748             '15.0'          => false,
1749             '18.0'          => false,
1750             '19.0'          => false,
1751         );
1753         if (isset($tests['check_gecko_version'])) {
1754             // The test provider has overwritten some of the above checks.
1755             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1756             $versions = $tests['check_gecko_version'] + $versions;
1757         }
1759         foreach ($versions as $version => $result) {
1760             $this->assertEquals($result, core_useragent::check_gecko_version($version),
1761                 "Version incorrectly determined for Gecko version '{$version}'");
1762         }
1763     }
1765     /**
1766      * @dataProvider user_agents_providers
1767      */
1768     public function test_useragent_firefox($useragent, $tests) {
1769         // Setup the core_useragent instance.
1770         core_useragent::instance(true, $useragent);
1772         if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1773             $this->assertTrue(core_useragent::is_firefox(),
1774                 "Browser was not identified as a firefox browser");
1775             $this->assertTrue(core_useragent::check_firefox_version());
1776         } else {
1777             $this->assertFalse(core_useragent::is_firefox(),
1778                 "Browser was incorrectly identified as a firefox browser");
1779             $this->assertFalse(core_useragent::check_firefox_version());
1780         }
1782         $versions = array(
1783             // New versions should be added here.
1784             '1.5'       => false,
1785             '3.0'       => false,
1786             '4'         => false,
1787             '10'        => false,
1788             '15'        => false,
1789             '18'        => false,
1790             '19'        => false,
1791             '33'        => false,
1792         );
1794         if (isset($tests['check_firefox_version'])) {
1795             // The test provider has overwritten some of the above checks.
1796             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1797             $versions = $tests['check_firefox_version'] + $versions;
1798         }
1800         foreach ($versions as $version => $result) {
1801             $this->assertEquals($result, core_useragent::check_firefox_version($version),
1802                 "Version incorrectly determined for Firefox version '{$version}'");
1803         }
1804     }
1806     /**
1807      * @dataProvider user_agents_providers
1808      */
1809     public function test_useragent_opera($useragent, $tests) {
1810         // Setup the core_useragent instance.
1811         core_useragent::instance(true, $useragent);
1813         if (isset($tests['is_opera']) && $tests['is_opera']) {
1814             $this->assertTrue(core_useragent::is_opera(),
1815                 "Browser was not identified as a opera browser");
1816             $this->assertTrue(core_useragent::check_opera_version());
1817         } else {
1818             $this->assertFalse(core_useragent::is_opera(),
1819                 "Browser was incorrectly identified as a opera browser");
1820             $this->assertFalse(core_useragent::check_opera_version());
1821         }
1823         $versions = array(
1824             // New versions should be added here.
1825             '8.0'       => false,
1826             '9.0'       => false,
1827             '10.0'      => false,
1828             '12.15'     => false,
1829         );
1831         if (isset($tests['check_opera_version'])) {
1832             // The test provider has overwritten some of the above checks.
1833             // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1834             $versions = $tests['check_opera_version'] + $versions;
1835         }
1837         foreach ($versions as $version => $result) {
1838             $this->assertEquals($result, core_useragent::check_opera_version($version),
1839                 "Version incorrectly determined for Opera version '{$version}'");
1840         }
1841     }
1843     /**
1844      * @dataProvider user_agents_providers
1845      */
1846     public function test_get_device_type($useragent, $tests) {
1847         // Setup the core_useragent instance.
1848         core_useragent::instance(true, $useragent);
1850         $expected = 'default';
1851         if (isset($tests['devicetype'])) {
1852             $expected = $tests['devicetype'];
1853         }
1855         $this->assertEquals($expected, core_useragent::get_device_type(),
1856             "Device Type was not correctly identified");
1857     }
1859     /**
1860      * @dataProvider user_agents_providers
1861      */
1862     public function test_get_browser_version_classes($useragent, $tests) {
1863         // Setup the core_useragent instance.
1864         core_useragent::instance(true, $useragent);
1866         $actual = core_useragent::get_browser_version_classes();
1867         foreach ($tests['versionclasses'] as $expectedclass) {
1868             $this->assertContains($expectedclass, $actual);
1869         }
1870         $this->assertCount(count($tests['versionclasses']), $actual);
1871     }
1873     /**
1874      * @dataProvider user_agents_providers
1875      */
1876     public function test_useragent_web_crawler($useragent, $tests) {
1877         // Setup the core_useragent instance.
1878         core_useragent::instance(true, $useragent);
1880         $expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
1881         $this->assertSame($expectation, core_useragent::is_web_crawler());
1882     }