BrowscapTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Http_UserAgent
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. if (!defined('PHPUnit_MAIN_METHOD')) {
  22. define('PHPUnit_MAIN_METHOD', 'Zend_Http_UserAgent_Features_Adapter_Browscap::main');
  23. }
  24. require_once 'Zend/Http/UserAgent/Features/Adapter/Browscap.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Http_UserAgent
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Http_UserAgent_Features_Adapter_BrowscapTest extends PHPUnit_Framework_TestCase
  33. {
  34. public static function main()
  35. {
  36. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  37. $result = PHPUnit_TextUI_TestRunner::run($suite);
  38. }
  39. public function setUp()
  40. {
  41. $browscap = ini_get('browscap');
  42. if (empty($browscap) || !file_exists($browscap)) {
  43. $this->markTestSkipped('Requires php.ini to provide a valid "browscap" entry');
  44. }
  45. }
  46. public function testGetFromRequest()
  47. {
  48. $request['http_user_agent'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419.3';
  49. $adapter = Zend_Http_UserAgent_Features_Adapter_Browscap::getFromRequest($request, array());
  50. $this->assertEquals(1, $adapter['ismobiledevice']);
  51. $this->assertEquals(1, $adapter['javascript']);
  52. $this->assertEquals(3, $adapter['cssversion']);
  53. $this->assertEquals('iPhone', $adapter['mobile_browser']);
  54. $this->assertContains('^mozilla/.\\..*(iphone;.*cpu', $adapter['browser_name_regex']);
  55. $request['http_user_agent'] = 'SonyEricssonK700i/R2AC SEMC-Browser/4.0.2 Profile/MIDP-2.0 Configuration/CLDC-1.1';
  56. $adapter = Zend_Http_UserAgent_Features_Adapter_Browscap::getFromRequest($request, array());
  57. $this->assertEquals(1, $adapter['ismobiledevice']);
  58. $this->assertEquals(1, $adapter['javascript']);
  59. $this->assertEquals(1, $adapter['cssversion']);
  60. $this->assertEquals('SEMC Browser', $adapter['mobile_browser']);
  61. $this->assertEquals('^.*semc-browser/.*$', $adapter['browser_name_regex']);
  62. }
  63. }
  64. if (PHPUnit_MAIN_METHOD == 'Zend_Http_UserAgent_Features_Adapter_Browscap::main') {
  65. Zend_Http_UserAgent_Features_Adapter_Browscap::main();
  66. }