Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * User agent test suite.
19
 *
20
 * @package    core
21
 * @copyright  2013 Sam Hemelryk
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @covers \core_useragent
24
 */
1441 ariadna 25
final class useragent_test extends advanced_testcase {
1 efrain 26
 
27
    /**
28
     * Restores the user agent to the default one.
29
     */
30
    public function tearDown(): void {
31
        core_useragent::instance(true);
1441 ariadna 32
        parent::tearDown();
1 efrain 33
    }
34
 
35
    /**
36
     * Data provider for known user agents.
37
     *
38
     * @return array
39
     */
1441 ariadna 40
    public static function user_agents_providers(): array {
1 efrain 41
        // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list.
42
        // This ensures that regression tests are applied to all known user agents.
43
        return array(
44
            'Microsoft Edge for Windows 10 Desktop' => array(
45
                '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',
46
                array(
47
                    'is_edge'                       => true,
48
                    'check_edge_version'            => array(
49
                        '12'                        => true,
50
                    ),
51
 
52
                    // Edge pretends to be WebKit.
53
                    'is_webkit'                     => true,
54
 
55
                    // Edge pretends to be Chrome.
56
                    // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
57
                    'is_chrome'                     => true,
58
                    'check_chrome_version'          => array(
59
                        '7'                         => true,
60
                        '8'                         => true,
61
                        '10'                        => true,
62
                        '39'                        => true,
63
                    ),
64
 
65
                    'versionclasses'                => array(
66
                        'edge',
67
                    ),
68
                ),
69
            ),
70
            'Microsoft Edge for Windows 10 Mobile' => array(
71
                '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',
72
                array(
73
                    'is_edge'                       => true,
74
                    'check_edge_version'              => array(
75
                        '12'                        => true,
76
                    ),
77
 
78
                    // Edge pretends to be WebKit.
79
                    'is_webkit'                     => true,
80
 
81
                    // Mobile Edge pretends to be Android.
82
                    'is_webkit_android'             => true,
83
                    'check_webkit_android_version'  => array(
84
                        '525'                       => true,
85
                        '527'                       => true,
86
                    ),
87
 
88
                    // Edge pretends to be Chrome.
89
                    // Note: Because Edge pretends to be Chrome, it will not be picked up as a Safari browser.
90
                    'is_chrome'                     => true,
91
                    'check_chrome_version'          => array(
92
                        '7'                         => true,
93
                        '8'                         => true,
94
                        '10'                        => true,
95
                        '39'                        => true,
96
                    ),
97
 
98
                    'versionclasses'                => array(
99
                        'edge'
100
                    ),
101
 
102
                    'devicetype'                    => 'mobile',
103
                ),
104
            ),
105
 
106
            // Windows XP; Firefox 1.0.6.
107
            array(
108
                'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6',
109
                array(
110
                    'is_firefox'                    => true,
111
 
112
                    'is_gecko'                      => true,
113
                    'check_gecko_version'           => array(
114
                        '1'                         => true,
115
                    ),
116
 
117
                    'versionclasses'                => array(
118
                        'gecko',
119
                        'gecko17',
120
                    ),
121
                ),
122
            ),
123
 
124
            // Windows XP; Firefox 1.0.6.
125
            array(
126
                'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5',
127
                array(
128
                    'is_firefox'                    => true,
129
                    'check_firefox_version'         => array(
130
                        '1.5'                       => true,
131
                    ),
132
 
133
                    'is_gecko'                      => true,
134
                    'check_gecko_version'           => array(
135
                        '1'                         => true,
136
                        '20030516'                  => true,
137
                        '20051116'                  => true,
138
                    ),
139
 
140
                    'versionclasses'                => array(
141
                        'gecko',
142
                        'gecko18',
143
                    ),
144
                ),
145
            ),
146
 
147
            // Windows XP; Firefox 1.5.0.1.
148
            array(
149
                'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
150
                array(
151
                    'is_firefox'                    => true,
152
                    'check_firefox_version'         => array(
153
                        '1.5'                       => true,
154
                    ),
155
 
156
                    'is_gecko'                      => true,
157
                    'check_gecko_version'           => array(
158
                        '1'                         => true,
159
                        '20030516'                  => true,
160
                        '20051116'                  => true,
161
                    ),
162
 
163
                    'versionclasses'                => array(
164
                        'gecko',
165
                        'gecko18',
166
                    ),
167
                ),
168
            ),
169
 
170
            // Windows XP; Firefox 2.0.
171
            array(
172
                'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
173
                array(
174
                    'is_firefox'                    => true,
175
                    'check_firefox_version'         => array(
176
                        '1.5'                       => true,
177
                    ),
178
 
179
                    'is_gecko'                      => true,
180
                    'check_gecko_version'           => array(
181
                        '1'                         => true,
182
                        '2'                         => true,
183
                        '20030516'                  => true,
184
                        '20051116'                  => true,
185
                        '2006010100'                => true,
186
                    ),
187
 
188
                    'versionclasses'                => array(
189
                        'gecko',
190
                        'gecko18',
191
                    ),
192
                ),
193
            ),
194
 
195
            // Ubuntu Linux amd64; Firefox 2.0.
196
            array(
197
                'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)',
198
                array(
199
                    'is_firefox'                    => true,
200
                    'check_firefox_version'         => array(
201
                        '1.5'                       => true,
202
                    ),
203
 
204
                    'is_gecko'                      => true,
205
                    'check_gecko_version'           => array(
206
                        '1'                         => true,
207
                        '2'                         => true,
208
                        '20030516'                  => true,
209
                        '20051116'                  => true,
210
                        '2006010100'                => true,
211
                    ),
212
 
213
                    'versionclasses'                => array(
214
                        'gecko',
215
                        'gecko18',
216
                    ),
217
                ),
218
            ),
219
 
220
            // SUSE; Firefox 3.0.6.
221
            array(
222
                'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.4 Firefox/3.0.6',
223
                array(
224
                    'is_firefox'                    => true,
225
                    'check_firefox_version'         => array(
226
                        '1.5'                       => true,
227
                        '3.0'                       => true,
228
                    ),
229
 
230
                    'is_gecko'                      => true,
231
                    'check_gecko_version'           => array(
232
                        '1'                         => true,
233
                        '2'                         => true,
234
                        '20030516'                  => true,
235
                        '20051116'                  => true,
236
                        '2006010100'                => true,
237
                    ),
238
 
239
                    'versionclasses'                => array(
240
                        'gecko',
241
                        'gecko19',
242
                    ),
243
                ),
244
            ),
245
 
246
            // Linux i686; Firefox 3.6.
247
            array(
248
                'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6',
249
                array(
250
                    'is_firefox'                    => true,
251
                    'check_firefox_version'         => array(
252
                        '1.5'                       => true,
253
                        '3.0'                       => true,
254
                    ),
255
 
256
                    'is_gecko'                      => true,
257
                    'check_gecko_version'           => array(
258
                        '1'                         => true,
259
                        '2'                         => true,
260
                        '20030516'                  => true,
261
                        '20051116'                  => true,
262
                        '2006010100'                => true,
263
                        '3.6'                       => true,
264
                        '20100101'                  => true,
265
                    ),
266
 
267
                    'versionclasses'                => array(
268
                        'gecko',
269
                        'gecko20',
270
                    ),
271
                ),
272
            ),
273
 
274
            // Windows; Firefox 11.0.
275
            array(
276
                'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0',
277
                array(
278
                    'is_firefox'                    => true,
279
                    'check_firefox_version'         => array(
280
                        '1.5'                       => true,
281
                        '3.0'                       => true,
282
                        '4'                         => true,
283
                        '10'                        => true,
284
                    ),
285
 
286
                    'is_gecko'                      => true,
287
                    'check_gecko_version'           => array(
288
                        '1'                         => true,
289
                        '2'                         => true,
290
                        '20030516'                  => true,
291
                        '20051116'                  => true,
292
                        '2006010100'                => true,
293
                        '20100101'                  => true,
294
                        '3.6'                       => true,
295
                        '4.0'                       => true,
296
                    ),
297
 
298
                    'versionclasses'                => array(
299
                        'gecko',
300
                    ),
301
                ),
302
            ),
303
 
304
            // Windows; Firefox 15.0a2.
305
            array(
306
                'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
307
                array(
308
                    'is_firefox'                    => true,
309
                    'check_firefox_version'         => array(
310
                        '1.5'                       => true,
311
                        '3.0'                       => true,
312
                        '4'                         => true,
313
                        '10'                        => true,
314
                        '15'                        => true,
315
                    ),
316
 
317
                    'is_gecko'                      => true,
318
                    'check_gecko_version'           => array(
319
                        '1'                         => true,
320
                        '2'                         => true,
321
                        '20030516'                  => true,
322
                        '20051116'                  => true,
323
                        '2006010100'                => true,
324
                        '20100101'                  => true,
325
                        '3.6'                       => true,
326
                        '4.0'                       => true,
327
                        '15.0'                      => true,
328
                    ),
329
 
330
                    'versionclasses'                => array(
331
                        'gecko',
332
                    ),
333
                ),
334
            ),
335
 
336
            // Firefox 18; Mac OS X 10.
337
            array(
338
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
339
                array(
340
                    'is_firefox'                    => true,
341
                    'check_firefox_version'         => array(
342
                        '1.5'                       => true,
343
                        '3.0'                       => true,
344
                        '4'                         => true,
345
                        '10'                        => true,
346
                        '15'                        => true,
347
                        '18'                        => true,
348
                    ),
349
 
350
                    'is_gecko'                      => true,
351
                    'check_gecko_version'           => array(
352
                        '1'                         => true,
353
                        '2'                         => true,
354
                        '20030516'                  => true,
355
                        '20051116'                  => true,
356
                        '2006010100'                => true,
357
                        '3.6'                       => true,
358
                        '4.0'                       => true,
359
                        '15.0'                      => true,
360
                        '18.0'                      => true,
361
                        '20100101'                  => true,
362
                    ),
363
 
364
                    'versionclasses'                => array(
365
                        'gecko',
366
                    ),
367
                ),
368
            ),
369
 
370
            // Firefox 33; Mac OS X 10.10.
371
            array(
372
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0',
373
                array(
374
                    'is_firefox'                    => true,
375
                    'check_firefox_version'         => array(
376
                        '1.5'                       => true,
377
                        '3.0'                       => true,
378
                        '4'                         => true,
379
                        '10'                        => true,
380
                        '15'                        => true,
381
                        '18'                        => true,
382
                        '19'                        => true,
383
                        '33'                        => true,
384
                    ),
385
 
386
                    'is_gecko'                      => true,
387
                    'check_gecko_version'           => array(
388
                        '1'                         => true,
389
                        '2'                         => true,
390
                        '20030516'                  => true,
391
                        '20051116'                  => true,
392
                        '2006010100'                => true,
393
                        '3.6'                       => true,
394
                        '4.0'                       => true,
395
                        '15.0'                      => true,
396
                        '18.0'                      => true,
397
                        '19.0'                      => true,
398
                        '20100101'                  => true,
399
                    ),
400
 
401
                    'versionclasses'                => array(
402
                        'gecko',
403
                    ),
404
                ),
405
            ),
406
 
407
            // SeaMonkey 2.0; Windows.
408
            array(
409
                'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0',
410
                array(
411
                    'is_gecko'                      => true,
412
                    'check_gecko_version'           => array(
413
                        '1'                         => true,
414
                        '2'                         => true,
415
                        '20030516'                  => true,
416
                        '20051106'                  => true,
417
                        '20051116'                  => true,
418
                        '2006010100'                => true,
419
                    ),
420
 
421
                    'versionclasses'                => array(
422
                        'gecko',
423
                        'gecko19',
424
                    ),
425
                ),
426
            ),
427
 
428
            // SeaMonkey 2.1; Linux.
429
            array(
430
                'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1',
431
                array(
432
                    'is_gecko'                      => true,
433
                    'check_gecko_version'           => array(
434
                        '1'                         => true,
435
                        '2'                         => true,
436
                        '20030516'                  => true,
437
                        '20051116'                  => true,
438
                        '2006010100'                => true,
439
                        '20100101'                  => true,
440
                        '3.6'                       => true,
441
                        '4.0'                       => true,
442
                    ),
443
 
444
                    'is_firefox'                    => true,
445
                    'check_firefox_version'         => array(
446
                        '1.5'                       => true,
447
                        '3.0'                       => true,
448
                        '4'                         => true,
449
                    ),
450
 
451
                    'versionclasses'                => array(
452
                        'gecko',
453
                        'gecko20',
454
                    ),
455
                ),
456
            ),
457
 
458
            // SeaMonkey 2.3; FreeBSD.
459
            array(
460
                'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3',
461
                array(
462
                    'is_gecko'                      => true,
463
                    'check_gecko_version'           => array(
464
                        '1'                         => true,
465
                        '2'                         => true,
466
                        '20030516'                  => true,
467
                        '20051116'                  => true,
468
                        '2006010100'                => true,
469
                        '20100101'                  => true,
470
                        '3.6'                       => true,
471
                        '4.0'                       => true,
472
                    ),
473
 
474
                    'is_firefox'                    => true,
475
                    'check_firefox_version'         => array(
476
                        '1.5'                       => true,
477
                        '3.0'                       => true,
478
                        '4'                         => true,
479
                    ),
480
 
481
                    'versionclasses'                => array(
482
                        'gecko',
483
                    ),
484
                ),
485
            ),
486
 
487
            // Mac OS X; MS Word 14.
488
            array(
489
                'Mozilla/5.0 (Macintosh; Intel Mac OS X) Word/14.38.0',
490
                array(
491
                    'versionclasses'                => array(
492
                    ),
493
 
494
                    'is_msword'                     => true,
495
                ),
496
            ),
497
 
498
            // Safari 312; Max OS X.
499
            array(
500
                'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
501
                array(
502
                    'is_safari'                     => true,
503
                    'check_safari_version'          => array(
504
                        '1'                         => true,
505
                        '312'                       => true,
506
                    ),
507
 
508
                    'is_webkit'                     => true,
509
 
510
                    'versionclasses'                => array(
511
                        'safari',
512
                    ),
513
                ),
514
            ),
515
 
516
            // Safari 412; Max OS X.
517
            array(
518
                'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
519
                array(
520
                    'is_safari'                     => true,
521
                    'check_safari_version'          => array(
522
                        '1'                         => true,
523
                        '312'                       => true,
524
                    ),
525
 
526
                    'is_webkit'                     => true,
527
 
528
                    'versionclasses'                => array(
529
                        'safari',
530
                    ),
531
                ),
532
            ),
533
 
534
            // Safari 2.0; Max OS X.
535
            array(
536
                'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
537
                array(
538
                    'is_safari'                     => true,
539
                    'check_safari_version'          => array(
540
                        '1'                         => true,
541
                        '312'                       => true,
542
                    ),
543
 
544
                    'is_webkit'                     => true,
545
 
546
                    'versionclasses'                => array(
547
                        'safari',
548
                    ),
549
                ),
550
            ),
551
 
552
            // iOS Safari 528; iPhone.
553
            array(
554
                'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; cs-cz) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16',
555
                array(
556
                    // Note: We do *not* identify mobile Safari as Safari.
557
                    'is_safari_ios'                 => true,
558
                    'is_ios'                        => true,
559
                    'check_safari_ios_version'      => array(
560
                        '527'                       => true,
561
                    ),
562
 
563
                    'is_webkit'                     => true,
564
 
565
                    'versionclasses'                => array(
566
                        'ios'
567
                    ),
568
 
569
                    'devicetype'                    => 'mobile',
570
               ),
571
            ),
572
 
573
            // Safari; iPhone 6 Plus; iOS 8.1; Build 12B411.
574
            array(
575
                'Mozilla/5.0 (iPhone; CPU iPhone OS 10_10 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4',
576
                array(
577
                    // Note: We do *not* identify mobile Safari as Safari.
578
                    'is_safari_ios'                 => true,
579
                    'is_ios'                        => true,
580
                    'check_safari_ios_version'      => array(
581
                        '527'                       => true,
582
                        '590'                       => true,
583
                        '600'                       => true,
584
                    ),
585
 
586
                    'is_webkit'                     => true,
587
 
588
                    'versionclasses'                => array(
589
                        'ios',
590
                    ),
591
 
592
                    'devicetype'                    => 'mobile',
593
               ),
594
            ),
595
 
596
            // iOS Safari 533; iPad.
597
            array(
598
                'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5',
599
                array(
600
                    // Note: We do *not* identify mobile Safari as Safari.
601
                    'is_safari_ios'                 => true,
602
                    'is_ios'                        => true,
603
                    'check_safari_ios_version'      => array(
604
                        '527'                       => true,
605
                    ),
606
 
607
                    'is_webkit'                     => true,
608
 
609
                    'versionclasses'                => array(
610
                        'ios',
611
                    ),
612
 
613
                    'devicetype'                    => 'tablet',
614
               ),
615
            ),
616
 
617
            // Android WebKit 525; G1 Phone.
618
            'Android WebKit 525; G1 Phone' => array(
619
                'Mozilla/5.0 (Linux; U; Android 1.1; en-gb; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 – G1 Phone',
620
                array(
621
                    'is_webkit_android'             => true,
622
                    'check_webkit_android_version'  => array(
623
                        '525'                       => true,
624
                    ),
625
 
626
                    'is_webkit'                     => true,
627
 
628
                    'versionclasses'                => array(
629
                        'android',
630
                    ),
631
 
632
                    'devicetype'                    => 'mobile',
633
 
634
                    'supports_svg'                  => false,
635
               ),
636
            ),
637
 
638
            // Android WebKit 530; Nexus.
639
            'Android WebKit 530; Nexus' => array(
640
                'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 –Nexus',
641
                array(
642
                    'is_webkit_android'             => true,
643
                    'check_webkit_android_version'  => array(
644
                        '525'                       => true,
645
                        '527'                       => true,
646
                    ),
647
 
648
                    'is_webkit'                     => true,
649
 
650
                    'versionclasses'                => array(
651
                        'android',
652
                    ),
653
 
654
                    'devicetype'                    => 'mobile',
655
 
656
                    'supports_svg'                  => false,
657
               ),
658
            ),
659
 
660
            // Android WebKit 537; Samsung GT-9505.
661
            array(
662
                'Mozilla/5.0 (Linux; Android 4.3; it-it; SAMSUNG GT-I9505/I9505XXUEMJ7 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36',
663
                array(
664
                    'is_webkit_android'             => true,
665
                    'check_webkit_android_version'  => array(
666
                        '525'                       => true,
667
                        '527'                       => true,
668
                    ),
669
 
670
                    'is_webkit'                     => true,
671
 
672
                    'is_chrome'                     => true,
673
                    'check_chrome_version'          => array(
674
                        '7'                         => true,
675
                        '8'                         => true,
676
                        '10'                        => true,
677
                    ),
678
 
679
                    'versionclasses'                => array(
680
                        'chrome',
681
                        'android',
682
                    ),
683
 
684
                    'devicetype'                    => 'mobile',
685
                ),
686
            ),
687
 
688
            // Android WebKit 537; Nexus 5.
689
            array(
690
                'Mozilla/5.0 (Linux; Android 5.0; Nexus 5 Build/LPX13D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.102 Mobile Safari/537.36',
691
                array(
692
                    'is_webkit_android'             => true,
693
                    'check_webkit_android_version'  => array(
694
                        '525'                       => true,
695
                        '527'                       => true,
696
                    ),
697
 
698
                    'is_webkit'                     => true,
699
 
700
                    'is_chrome'                     => true,
701
                    'check_chrome_version'          => array(
702
                        '7'                         => true,
703
                        '8'                         => true,
704
                        '10'                        => true,
705
                    ),
706
 
707
                    'versionclasses'                => array(
708
                        'chrome',
709
                        'android',
710
                    ),
711
 
712
                    'devicetype'                    => 'mobile',
713
                ),
714
            ),
715
 
716
            // Chrome 8; Mac OS X.
717
            array(
718
                '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',
719
                array(
720
                    'is_chrome'                     => true,
721
                    'check_chrome_version'          => array(
722
                        '7'                         => true,
723
                        '8'                         => true,
724
                    ),
725
 
726
                    'is_webkit'                     => true,
727
 
728
                    'versionclasses'                => array(
729
                        'chrome',
730
                    ),
731
                ),
732
            ),
733
 
734
            // Chrome 39; Mac OS X.
735
            array(
736
                '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',
737
                array(
738
                    'is_chrome'                     => true,
739
                    'check_chrome_version'          => array(
740
                        '7'                         => true,
741
                        '8'                         => true,
742
                        '10'                        => true,
743
                        '39'                        => true,
744
                    ),
745
 
746
                    'is_webkit'                     => true,
747
 
748
                    'versionclasses'                => array(
749
                        'chrome',
750
                    ),
751
                ),
752
            ),
753
 
754
            // Opera 12.15 (Build 1748); Mac OS X.
755
            array(
756
                'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.0; Edition MAS) Presto/2.12.388 Version/12.15',
757
                array(
758
                    'is_opera'                      => true,
759
                    'check_opera_version'           => array(
760
                        '8.0'                       => true,
761
                        '9.0'                       => true,
762
                        '10.0'                      => true,
763
                        '12.15'                     => true,
764
                    ),
765
 
766
                    'versionclasses'                => array(
767
                        'opera',
768
                    ),
769
               ),
770
            ),
771
 
772
            // Google web crawlers.
773
            array(
774
                'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
775
                array(
776
                    'is_web_crawler'                => true,
777
                    'versionclasses'                => array(
778
                    ),
779
               ),
780
            ),
781
            array(
782
                'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
783
                array(
784
                    'is_web_crawler'                => true,
785
                    'versionclasses'                => array(
786
                    ),
787
               ),
788
            ),
789
            array(
790
                'Googlebot-Image/1.0',
791
                array(
792
                    'is_web_crawler'                => true,
793
                    'versionclasses'                => array(
794
                    ),
795
               ),
796
            ),
797
 
798
            // Yahoo crawlers.
799
            // See https://help.yahoo.com/kb/slurp-crawling-page-sln22600.html.
800
            array(
801
                'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
802
                array(
803
                    'is_web_crawler'                => true,
804
                    'versionclasses'                => array(
805
                    ),
806
               ),
807
            ),
808
 
809
            // Bing / MSN / AdIdx crawlers.
810
            // See http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0.
811
            array(
812
                'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
813
                array(
814
                    'is_web_crawler'                => true,
815
                    'versionclasses'                => array(
816
                    ),
817
               ),
818
            ),
819
            array(
820
                'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
821
                array(
822
                    'is_web_crawler'                => true,
823
                    'versionclasses'                => array(
824
                    ),
825
               ),
826
            ),
827
            array(
828
                'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
829
                array(
830
                    'is_web_crawler'                => true,
831
                    'is_webkit'                     => true,
832
                    'is_safari_ios'                 => true,
833
                    'is_ios'                        => true,
834
                    'check_safari_ios_version'      => array(
835
                        '527'                       => true,
836
                    ),
837
 
838
                    'versionclasses'                => array(
839
                        'ios',
840
                    ),
841
 
842
                    'devicetype'                    => 'mobile',
843
               ),
844
            ),
845
            array(
846
                'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
847
                array(
848
                    'is_web_crawler'                => true,
849
                    'is_ie'                         => true,
850
                    'check_ie_version'              => array(
851
                        '0'                         => true,
852
                        '5.0'                       => true,
853
                        '5.5'                       => true,
854
                        '6.0'                       => true,
855
                        '7.0'                       => true,
856
                        '8.0'                       => true,
857
                        '9.0'                       => true,
858
                        '10'                        => true,
859
                        '11'                        => true,
860
                    ),
861
                    'versionclasses'                => array(
862
                        'ie',
863
                        'ie11',
864
                    ),
865
                    'devicetype'                    => 'mobile',
866
               ),
867
            ),
868
 
869
            array(
870
                'msnbot/2.0b (+http://search.msn.com/msnbot.htm)',
871
                array(
872
                    'is_web_crawler'                => true,
873
                    'versionclasses'                => array(
874
                    ),
875
               ),
876
            ),
877
            array(
878
                'msnbot/2.1',
879
                array(
880
                    'is_web_crawler'                => true,
881
                    'versionclasses'                => array(
882
                    ),
883
               ),
884
            ),
885
            array(
886
                'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)',
887
                array(
888
                    'is_web_crawler'                => true,
889
                    'versionclasses'                => array(
890
                    ),
891
               ),
892
            ),
893
            array(
894
                'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
895
                array(
896
                    'is_web_crawler'                => true,
897
                    'is_webkit'                     => true,
898
                    'is_safari'                     => true,
899
                    'check_safari_version'          => array(
900
                        '1'                         => true,
901
                        '312'                       => true,
902
                        '500'                       => true,
903
                    ),
904
 
905
                    'versionclasses'                => array(
906
                        'safari',
907
                    ),
908
               ),
909
            ),
910
            array(
911
                'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko BingPreview/1.0b',
912
                array(
913
                    'is_web_crawler'                => true,
914
                    'is_ie'                         => true,
915
                    'check_ie_version'              => array(
916
                        '0'                         => true,
917
                        '5.0'                       => true,
918
                        '5.5'                       => true,
919
                        '6.0'                       => true,
920
                        '7.0'                       => true,
921
                        '8.0'                       => true,
922
                        '9.0'                       => true,
923
                        '10'                        => true,
924
                        '11'                        => true,
925
                    ),
926
                    'versionclasses'                => array(
927
                        'ie',
928
                        'ie11',
929
                    ),
930
                    'devicetype'                    => 'mobile',
931
               ),
932
            ),
933
 
934
            // Yandex.
935
            // See http://help.yandex.com/search/robots/agent.xml.
936
            array(
937
                'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
938
                array(
939
                    'is_web_crawler'                => true,
940
                    'versionclasses'                => array(
941
                    ),
942
               ),
943
            ),
944
            array(
945
                'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
946
                array(
947
                    'is_web_crawler'                => true,
948
                    'versionclasses'                => array(
949
                    ),
950
               ),
951
            ),
952
 
953
            // AltaVista.
954
            array(
955
                'AltaVista V2.0B crawler@evreka.com',
956
                array(
957
                    'is_web_crawler'                => true,
958
                    'versionclasses'                => array(
959
                    ),
960
               ),
961
            ),
962
 
963
            // ZoomSpider.
964
            array(
965
                'ZoomSpider - wrensoft.com [ZSEBOT]',
966
                array(
967
                    'is_web_crawler'                => true,
968
                    'versionclasses'                => array(
969
                    ),
970
               ),
971
            ),
972
 
973
            // Baidu.
974
            array(
975
                'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
976
                array(
977
                    'is_web_crawler'                => true,
978
                    'versionclasses'                => array(
979
                    ),
980
               ),
981
            ),
982
            array(
983
                'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
984
                array(
985
                    'is_web_crawler'                => true,
986
                    'versionclasses'                => array(
987
                    ),
988
               ),
989
            ),
990
 
991
            // Ask.com.
992
            array(
993
                'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
994
                array(
995
                    'is_web_crawler'                => true,
996
                    'versionclasses'                => array(
997
                    ),
998
               ),
999
            ),
1000
 
1001
            // MoodleBot.
1002
            array(
1003
                'User-Agent: MoodleBot/3.8 (+https://moodle.org)',
1004
                array(
1005
                    'is_web_crawler'                => true,
1006
                    'versionclasses'                => array(
1007
                    ),
1008
               ),
1009
            ),
1010
 
1011
            // Macos Desktop app.
1012
            array(
1013
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) moodlemobile/3.6.0 Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36 MoodleMobile',
1014
                array(
1015
                    'is_moodle_app'                => true,
1016
                    'is_webkit'                    => true,
1017
                    'is_chrome'                    => true,
1018
                    'check_chrome_version'         => array(
1019
                        '7'                        => true,
1020
                        '8'                        => true,
1021
                        '10'                       => true,
1022
                        '39'                       => true,
1023
                    ),
1024
                    'versionclasses'               => array(
1025
                        'chrome',
1026
                    ),
1027
               ),
1028
            ),
1029
 
1030
            // Linux Desktop app.
1031
            array(
1032
                'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) moodledesktop/3.6.0 Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36 MoodleMobile',
1033
                array(
1034
                    'is_moodle_app'                => true,
1035
                    'is_webkit'                    => true,
1036
                    'is_chrome'                    => true,
1037
                    'check_chrome_version'         => array(
1038
                        '7'                        => true,
1039
                        '8'                        => true,
1040
                        '10'                       => true,
1041
                        '39'                       => true,
1042
                    ),
1043
                    'versionclasses'               => array(
1044
                        'chrome',
1045
                    ),
1046
               ),
1047
            ),
1048
 
1049
            // Windows Desktop app.
1050
            array(
1051
                'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) moodledesktop/3.6.0 Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36 MoodleMobile',
1052
                array(
1053
                    'is_moodle_app'                => true,
1054
                    'is_webkit'                    => true,
1055
                    'is_chrome'                    => true,
1056
                    'check_chrome_version'         => array(
1057
                        '7'                        => true,
1058
                        '8'                        => true,
1059
                        '10'                       => true,
1060
                        '39'                       => true,
1061
                    ),
1062
                    'versionclasses'               => array(
1063
                        'chrome',
1064
                    ),
1065
               ),
1066
            ),
1067
 
1068
            // Android app.
1069
            array(
1070
                'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile',
1071
                array(
1072
                    'is_moodle_app'                => true,
1073
                    'is_webkit'                    => true,
1074
                    'is_webkit_android'            => true,
1075
                    'is_chrome'                    => true,
1076
                    'check_chrome_version'         => array(
1077
                        '7'                        => true,
1078
                        '8'                        => true,
1079
                        '10'                       => true,
1080
                        '39'                       => true,
1081
                    ),
1082
                    'devicetype'                   => 'mobile',
1083
                    'check_webkit_android_version' => array(
1084
                        '525'                       => true,
1085
                        '527'                       => true,
1086
                    ),
1087
                    'versionclasses'               => array(
1088
                        'android',
1089
                        'chrome'
1090
                    ),
1091
               ),
1092
            ),
1093
 
1094
            // Android app, user agent lower case.
1095
            array(
1096
                'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 moodlemobile',
1097
                array(
1098
                    'is_moodle_app'                => true,
1099
                    'is_webkit'                    => true,
1100
                    'is_webkit_android'            => true,
1101
                    'is_chrome'                    => true,
1102
                    'check_chrome_version'         => array(
1103
                        '7'                        => true,
1104
                        '8'                        => true,
1105
                        '10'                       => true,
1106
                        '39'                       => true,
1107
                    ),
1108
                    'devicetype'                   => 'mobile',
1109
                    'check_webkit_android_version' => array(
1110
                        '525'                       => true,
1111
                        '527'                       => true,
1112
                    ),
1113
                    'versionclasses'               => array(
1114
                        'android',
1115
                        'chrome'
1116
                    ),
1117
               ),
1118
            ),
1119
 
1120
            // iOS (iPhone) app.
1121
            array(
1122
                'Mozilla/5.0 (iPhone; CPU OS 13_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MoodleMobile',
1123
                array(
1124
                    'is_moodle_app'                => true,
1125
                    'is_ios'                       => true,
1126
                    'is_webkit'                    => true,
1127
                    'devicetype'                   => 'mobile',
1128
                    'versionclasses'               => array(
1129
                    ),
1130
               ),
1131
            ),
1132
 
1133
            // iOS (iPad) app.
1134
            array(
1135
                'Mozilla/5.0 (iPad; CPU OS 12_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D39 MoodleMobile',
1136
                array(
1137
                    'is_moodle_app'                => true,
1138
                    'is_ios'                       => true,
1139
                    'is_webkit'                    => true,
1140
                    'devicetype'                   => 'tablet',
1141
                    'versionclasses'               => array(
1142
                    ),
1143
               ),
1144
            ),
1145
        );
1146
    }
1147
 
1148
    /**
1149
     * Test instance generation.
1150
     */
11 efrain 1151
    public function test_instance(): void {
1 efrain 1152
        $this->assertInstanceOf('core_useragent', core_useragent::instance());
1153
        $this->assertInstanceOf('core_useragent', core_useragent::instance(true));
1154
    }
1155
 
1156
    /**
1157
     * @dataProvider user_agents_providers
1158
     */
11 efrain 1159
    public function test_useragent_edge($useragent, $tests): void {
1 efrain 1160
        // Setup the core_useragent instance.
1161
        core_useragent::instance(true, $useragent);
1162
 
1163
        // Edge Tests.
1164
        if (isset($tests['is_edge']) && $tests['is_edge']) {
1165
            $this->assertTrue(core_useragent::is_edge());
1166
        } else {
1167
            $this->assertFalse(core_useragent::is_edge());
1168
        }
1169
 
1170
        $versions = array(
1171
            // New versions of should be added here.
1172
            '12'   => false,
1173
        );
1174
 
1175
        if (isset($tests['check_edge_version'])) {
1176
            // The test provider has overwritten some of the above checks.
1177
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1178
            $versions = $tests['check_edge_version'] + $versions;
1179
        }
1180
 
1181
        foreach ($versions as $version => $result) {
1182
            $this->assertEquals($result, core_useragent::check_edge_version($version),
1183
                "Version incorrectly determined for Edge version '{$version}'");
1184
        }
1185
    }
1186
 
1187
    /**
1188
     * @dataProvider user_agents_providers
1189
     */
11 efrain 1190
    public function test_useragent_ie($useragent, $tests): void {
1 efrain 1191
        // Setup the core_useragent instance.
1192
        core_useragent::instance(true, $useragent);
1193
 
1194
        // IE Tests.
1195
        if (isset($tests['is_ie']) && $tests['is_ie']) {
1196
            $this->assertTrue(core_useragent::is_ie());
1197
        } else {
1198
            $this->assertFalse(core_useragent::is_ie());
1199
        }
1200
 
1201
        $versions = array(
1202
            // New versions of should be added here.
1203
            '0'    => false,
1204
            '5.0'  => false,
1205
            '5.5'  => false,
1206
            '6.0'  => false,
1207
            '7.0'  => false,
1208
            '8.0'  => false,
1209
            '9.0'  => false,
1210
            '10'   => false,
1211
            '11'   => false,
1212
            '12'   => false,
1213
            '13'   => false,
1214
            '14'   => false,
1215
        );
1216
 
1217
        if (isset($tests['check_ie_version'])) {
1218
            // The test provider has overwritten some of the above checks.
1219
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1220
            $versions = $tests['check_ie_version'] + $versions;
1221
        }
1222
 
1223
        foreach ($versions as $version => $result) {
1224
            $this->assertEquals($result, core_useragent::check_ie_version($version),
1225
                "Version incorrectly determined for IE version '{$version}'");
1226
        }
1227
 
1228
        // IE Compatibility mode.
1229
        if (isset($tests['iecompatibility']) && $tests['iecompatibility']) {
1230
            $this->assertTrue(core_useragent::check_ie_compatibility_view(), "IE Compability false negative");
1231
        } else {
1232
            $this->assertFalse(core_useragent::check_ie_compatibility_view(), "IE Compability false positive");
1233
        }
1234
 
1235
    }
1236
 
1237
    /**
1238
     * @dataProvider user_agents_providers
1239
     */
11 efrain 1240
    public function test_useragent_msword($useragent, $tests): void {
1 efrain 1241
        // Setup the core_useragent instance.
1242
        core_useragent::instance(true, $useragent);
1243
 
1244
        // MSWord Tests.
1245
        if (isset($tests['is_msword']) && $tests['is_msword']) {
1246
            $this->assertTrue(core_useragent::is_msword());
1247
        } else {
1248
            $this->assertFalse(core_useragent::is_msword());
1249
        }
1250
    }
1251
 
1252
    /**
1253
     * @dataProvider user_agents_providers
1254
     */
11 efrain 1255
    public function test_useragent_supports($useragent, $tests): void {
1 efrain 1256
        // Setup the core_useragent instance.
1257
        core_useragent::instance(true, $useragent);
1258
 
1259
        // Supports SVG.
1260
        if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
1261
            $this->assertTrue(core_useragent::supports_svg(),
1262
                "SVG Support was not reported (and should have been)");
1263
        } else {
1264
            $this->assertFalse(core_useragent::supports_svg(),
1265
                "SVG Support was reported (and should not have been)");
1266
        }
1267
 
1268
        // Supports JSON ContentType.
1269
        if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
1270
            $this->assertTrue(core_useragent::supports_json_contenttype(),
1271
                "JSON ContentType Support was not reported (and should have been)");
1272
        } else {
1273
            $this->assertFalse(core_useragent::supports_json_contenttype(),
1274
                "JSON ContentType Support was reported (and should not have been)");
1275
        }
1276
    }
1277
 
1278
    /**
1279
     * @dataProvider user_agents_providers
1280
     */
11 efrain 1281
    public function test_useragent_webkit($useragent, $tests): void {
1 efrain 1282
        // Setup the core_useragent instance.
1283
        core_useragent::instance(true, $useragent);
1284
 
1285
        if (isset($tests['is_webkit']) && $tests['is_webkit']) {
1286
            $this->assertTrue(core_useragent::is_webkit(),
1287
                "Browser was not identified as a webkit browser");
1288
            $this->assertTrue(core_useragent::check_webkit_version());
1289
        } else {
1290
            $this->assertFalse(core_useragent::is_webkit(),
1291
                "Browser was incorrectly identified as a webkit browser");
1292
            $this->assertFalse(core_useragent::check_webkit_version());
1293
        }
1294
 
1295
        $versions = array(
1296
            // New versions should be added here.
1297
        );
1298
 
1299
        if (isset($tests['check_webkit_version'])) {
1300
            // The test provider has overwritten some of the above checks.
1301
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1302
            $versions = $tests['check_webkit_version'] + $versions;
1303
        }
1304
 
1305
        foreach ($versions as $version => $result) {
1306
            $this->assertEquals($result, core_useragent::check_webkit_version($version),
1307
                "Version incorrectly determined for Webkit version '{$version}'");
1308
        }
1309
    }
1310
 
1311
    /**
1312
     * @dataProvider user_agents_providers
1313
     */
11 efrain 1314
    public function test_useragent_webkit_android($useragent, $tests): void {
1 efrain 1315
        // Setup the core_useragent instance.
1316
        core_useragent::instance(true, $useragent);
1317
 
1318
        if (isset($tests['is_webkit_android']) && $tests['is_webkit_android']) {
1319
            $this->assertTrue(core_useragent::is_webkit_android(),
1320
                "Browser was not identified as an Android webkit browser");
1321
            $this->assertTrue(core_useragent::check_webkit_android_version());
1322
        } else {
1323
            $this->assertFalse(core_useragent::is_webkit_android(),
1324
                "Browser was incorrectly identified as an Android webkit browser");
1325
            $this->assertFalse(core_useragent::check_webkit_android_version());
1326
        }
1327
 
1328
        $versions = array(
1329
            // New versions should be added here.
1330
            '525'       => false,
1331
            '527'       => false,
1332
            '590'       => false,
1333
        );
1334
 
1335
        if (isset($tests['check_webkit_android_version'])) {
1336
            // The test provider has overwritten some of the above checks.
1337
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1338
            $versions = $tests['check_webkit_android_version'] + $versions;
1339
        }
1340
 
1341
        foreach ($versions as $version => $result) {
1342
            $this->assertEquals($result, core_useragent::check_webkit_android_version($version),
1343
                "Version incorrectly determined for Android webkit version '{$version}'");
1344
        }
1345
    }
1346
 
1347
    /**
1348
     * @dataProvider user_agents_providers
1349
     */
11 efrain 1350
    public function test_useragent_chrome($useragent, $tests): void {
1 efrain 1351
        // Setup the core_useragent instance.
1352
        core_useragent::instance(true, $useragent);
1353
 
1354
        if (isset($tests['is_chrome']) && $tests['is_chrome']) {
1355
            $this->assertTrue(core_useragent::is_chrome(),
1356
                "Browser was not identified as a chrome browser");
1357
            $this->assertTrue(core_useragent::check_chrome_version());
1358
        } else {
1359
            $this->assertFalse(core_useragent::is_chrome(),
1360
                "Browser was incorrectly identified as a chrome browser");
1361
            $this->assertFalse(core_useragent::check_chrome_version());
1362
        }
1363
 
1364
        $versions = array(
1365
            // New versions should be added here.
1366
            '7'         => false,
1367
            '8'         => false,
1368
            '10'        => false,
1369
            '39'        => false,
1370
        );
1371
 
1372
        if (isset($tests['check_chrome_version'])) {
1373
            // The test provider has overwritten some of the above checks.
1374
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1375
            $versions = $tests['check_chrome_version'] + $versions;
1376
        }
1377
 
1378
        foreach ($versions as $version => $result) {
1379
            $this->assertEquals($result, core_useragent::check_chrome_version($version),
1380
                "Version incorrectly determined for Chrome version '{$version}'");
1381
        }
1382
    }
1383
 
1384
    /**
1385
     * @dataProvider user_agents_providers
1386
     */
11 efrain 1387
    public function test_useragent_safari($useragent, $tests): void {
1 efrain 1388
        // Setup the core_useragent instance.
1389
        core_useragent::instance(true, $useragent);
1390
 
1391
        if (isset($tests['is_safari']) && $tests['is_safari']) {
1392
            $this->assertTrue(core_useragent::is_safari(),
1393
                "Browser was not identified as a safari browser");
1394
            $this->assertTrue(core_useragent::check_safari_version());
1395
        } else {
1396
            $this->assertFalse(core_useragent::is_safari(),
1397
                "Browser was incorrectly identified as a safari browser");
1398
            $this->assertFalse(core_useragent::check_safari_version());
1399
        }
1400
 
1401
        // Check Safari (generic).
1402
        $versions = array(
1403
            // New versions should be added here.
1404
            '1'         => false,
1405
            '312'       => false,
1406
            '500'       => false,
1407
        );
1408
 
1409
        if (isset($tests['check_safari_version'])) {
1410
            // The test provider has overwritten some of the above checks.
1411
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1412
            $versions = $tests['check_safari_version'] + $versions;
1413
        }
1414
 
1415
        foreach ($versions as $version => $result) {
1416
            $this->assertEquals($result, core_useragent::check_safari_version($version),
1417
                "Version incorrectly determined for Safari (generic) version '{$version}'");
1418
        }
1419
    }
1420
 
1421
    /**
1422
     * @dataProvider user_agents_providers
1423
     */
11 efrain 1424
    public function test_useragent_ios_safari($useragent, $tests): void {
1 efrain 1425
        // Setup the core_useragent instance.
1426
        core_useragent::instance(true, $useragent);
1427
 
1428
        if (isset($tests['is_safari_ios']) && $tests['is_safari_ios']) {
1429
            $this->assertTrue(core_useragent::is_safari_ios(),
1430
                "Browser was not identified as an iOS safari browser");
1431
            $this->assertTrue(core_useragent::check_safari_ios_version());
1432
        } else {
1433
            $this->assertFalse(core_useragent::is_safari_ios(),
1434
                "Browser was incorrectly identified as an iOS safari browser");
1435
            $this->assertFalse(core_useragent::check_safari_ios_version());
1436
        }
1437
 
1438
        // Check iOS Safari.
1439
        $versions = array(
1440
            // New versions should be added here.
1441
            '527'       => false,
1442
            '590'       => false,
1443
            '600'       => false,
1444
        );
1445
 
1446
        if (isset($tests['check_safari_ios_version'])) {
1447
            // The test provider has overwritten some of the above checks.
1448
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1449
            $versions = $tests['check_safari_ios_version'] + $versions;
1450
        }
1451
 
1452
        foreach ($versions as $version => $result) {
1453
            $this->assertEquals($result, core_useragent::check_safari_ios_version($version),
1454
                "Version incorrectly determined for iOS Safari version '{$version}'");
1455
        }
1456
    }
1457
 
1458
    /**
1459
     * @dataProvider user_agents_providers
1460
     */
11 efrain 1461
    public function test_useragent_ios($useragent, $tests): void {
1 efrain 1462
        // Setup the core_useragent instance.
1463
        core_useragent::instance(true, $useragent);
1464
 
1465
        if (isset($tests['is_ios']) && $tests['is_ios']) {
1466
            $this->assertTrue(core_useragent::is_ios(),
1467
                "Browser was not identified as an iOS device browser");
1468
            // The iOS app is not Safari based.
1469
            if (!isset($tests['is_moodle_app']) || !$tests['is_moodle_app']) {
1470
                $this->assertTrue(core_useragent::check_safari_ios_version());
1471
            }
1472
        } else {
1473
            $this->assertFalse(core_useragent::is_ios(),
1474
                "Browser was incorrectly identified as an iOS device browser");
1475
            $this->assertFalse(core_useragent::check_safari_ios_version());
1476
        }
1477
    }
1478
 
1479
    /**
1480
     * @dataProvider user_agents_providers
1481
     */
11 efrain 1482
    public function test_useragent_gecko($useragent, $tests): void {
1 efrain 1483
        // Setup the core_useragent instance.
1484
        core_useragent::instance(true, $useragent);
1485
 
1486
        if (isset($tests['is_gecko']) && $tests['is_gecko']) {
1487
            $this->assertTrue(core_useragent::is_gecko(),
1488
                "Browser was not identified as a gecko browser");
1489
            $this->assertTrue(core_useragent::check_gecko_version());
1490
        } else {
1491
            $this->assertFalse(core_useragent::is_gecko(),
1492
                "Browser was incorrectly identified as a gecko browser");
1493
            $this->assertFalse(core_useragent::check_gecko_version());
1494
        }
1495
 
1496
        $versions = array(
1497
            // New versions should be added here.
1498
            '1'             => false,
1499
            '2'             => false,
1500
            '3.6'           => false,
1501
            '4.0'           => false,
1502
            '20030516'      => false,
1503
            '20051116'      => false,
1504
            '2006010100'    => false,
1505
            '20100101'      => false,
1506
            '15.0'          => false,
1507
            '18.0'          => false,
1508
            '19.0'          => false,
1509
        );
1510
 
1511
        if (isset($tests['check_gecko_version'])) {
1512
            // The test provider has overwritten some of the above checks.
1513
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1514
            $versions = $tests['check_gecko_version'] + $versions;
1515
        }
1516
 
1517
        foreach ($versions as $version => $result) {
1518
            $this->assertEquals($result, core_useragent::check_gecko_version($version),
1519
                "Version incorrectly determined for Gecko version '{$version}'");
1520
        }
1521
    }
1522
 
1523
    /**
1524
     * @dataProvider user_agents_providers
1525
     */
11 efrain 1526
    public function test_useragent_firefox($useragent, $tests): void {
1 efrain 1527
        // Setup the core_useragent instance.
1528
        core_useragent::instance(true, $useragent);
1529
 
1530
        if (isset($tests['is_firefox']) && $tests['is_firefox']) {
1531
            $this->assertTrue(core_useragent::is_firefox(),
1532
                "Browser was not identified as a firefox browser");
1533
            $this->assertTrue(core_useragent::check_firefox_version());
1534
        } else {
1535
            $this->assertFalse(core_useragent::is_firefox(),
1536
                "Browser was incorrectly identified as a firefox browser");
1537
            $this->assertFalse(core_useragent::check_firefox_version());
1538
        }
1539
 
1540
        $versions = array(
1541
            // New versions should be added here.
1542
            '1.5'       => false,
1543
            '3.0'       => false,
1544
            '4'         => false,
1545
            '10'        => false,
1546
            '15'        => false,
1547
            '18'        => false,
1548
            '19'        => false,
1549
            '33'        => false,
1550
        );
1551
 
1552
        if (isset($tests['check_firefox_version'])) {
1553
            // The test provider has overwritten some of the above checks.
1554
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1555
            $versions = $tests['check_firefox_version'] + $versions;
1556
        }
1557
 
1558
        foreach ($versions as $version => $result) {
1559
            $this->assertEquals($result, core_useragent::check_firefox_version($version),
1560
                "Version incorrectly determined for Firefox version '{$version}'");
1561
        }
1562
    }
1563
 
1564
    /**
1565
     * @dataProvider user_agents_providers
1566
     */
11 efrain 1567
    public function test_useragent_opera($useragent, $tests): void {
1 efrain 1568
        // Setup the core_useragent instance.
1569
        core_useragent::instance(true, $useragent);
1570
 
1571
        if (isset($tests['is_opera']) && $tests['is_opera']) {
1572
            $this->assertTrue(core_useragent::is_opera(),
1573
                "Browser was not identified as a opera browser");
1574
            $this->assertTrue(core_useragent::check_opera_version());
1575
        } else {
1576
            $this->assertFalse(core_useragent::is_opera(),
1577
                "Browser was incorrectly identified as a opera browser");
1578
            $this->assertFalse(core_useragent::check_opera_version());
1579
        }
1580
 
1581
        $versions = array(
1582
            // New versions should be added here.
1583
            '8.0'       => false,
1584
            '9.0'       => false,
1585
            '10.0'      => false,
1586
            '12.15'     => false,
1587
        );
1588
 
1589
        if (isset($tests['check_opera_version'])) {
1590
            // The test provider has overwritten some of the above checks.
1591
            // Must use the '+' operator, because array_merge will incorrectly rewrite the array keys for integer-based indexes.
1592
            $versions = $tests['check_opera_version'] + $versions;
1593
        }
1594
 
1595
        foreach ($versions as $version => $result) {
1596
            $this->assertEquals($result, core_useragent::check_opera_version($version),
1597
                "Version incorrectly determined for Opera version '{$version}'");
1598
        }
1599
    }
1600
 
1601
    /**
1602
     * @dataProvider user_agents_providers
1603
     */
11 efrain 1604
    public function test_get_device_type($useragent, $tests): void {
1 efrain 1605
        // Setup the core_useragent instance.
1606
        core_useragent::instance(true, $useragent);
1607
 
1608
        $expected = 'default';
1609
        if (isset($tests['devicetype'])) {
1610
            $expected = $tests['devicetype'];
1611
        }
1612
 
1613
        $this->assertEquals($expected, core_useragent::get_device_type(),
1614
            "Device Type was not correctly identified");
1615
    }
1616
 
1617
    /**
1618
     * @dataProvider user_agents_providers
1619
     */
11 efrain 1620
    public function test_get_browser_version_classes($useragent, $tests): void {
1 efrain 1621
        // Setup the core_useragent instance.
1622
        core_useragent::instance(true, $useragent);
1623
 
1624
        $actual = core_useragent::get_browser_version_classes();
1625
        foreach ($tests['versionclasses'] as $expectedclass) {
1626
            $this->assertContains($expectedclass, $actual);
1627
        }
1628
        $this->assertCount(count($tests['versionclasses']), $actual);
1629
    }
1630
 
1631
    /**
1632
     * @dataProvider user_agents_providers
1633
     */
11 efrain 1634
    public function test_useragent_web_crawler($useragent, $tests): void {
1 efrain 1635
        // Setup the core_useragent instance.
1636
        core_useragent::instance(true, $useragent);
1637
 
1638
        $expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
1639
        $this->assertSame($expectation, core_useragent::is_web_crawler());
1640
    }
1641
 
1642
    /**
1643
     * @dataProvider user_agents_providers
1644
     */
11 efrain 1645
    public function test_useragent_moodle_app($useragent, $tests): void {
1 efrain 1646
        // Setup the core_useragent instance.
1647
        core_useragent::instance(true, $useragent);
1648
 
1649
        $expectation = isset($tests['is_moodle_app']) ? $tests['is_moodle_app'] : false;
1650
        $this->assertSame($expectation, core_useragent::is_moodle_app());
1651
    }
1652
}