[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/tests/ -> useragent_test.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1