DeviceAtlasTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once dirname(__FILE__) . '/../../../../../TestHelper.php';
  22. require_once 'Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Http_UserAgent
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Http_UserAgent_Features_Adapter_DeviceAtlasTest extends PHPUnit_Framework_TestCase
  31. {
  32. public function setUp()
  33. {
  34. if (!constant('TESTS_ZEND_HTTP_USERAGENT_DEVICEATLAS_LIB_DIR')
  35. || !constant('TESTS_ZEND_HTTP_USERAGENT_DEVICEATLAS_DATA_FILE')
  36. ) {
  37. $this->markTestSkipped('Requires Device Atlas library');
  38. }
  39. $this->config['deviceatlas']['deviceatlas_lib_dir'] = constant('TESTS_ZEND_HTTP_USERAGENT_DEVICEATLAS_LIB_DIR');
  40. $this->config['deviceatlas']['deviceatlas_data'] = constant('TESTS_ZEND_HTTP_USERAGENT_DEVICEATLAS_DATA_FILE');
  41. $this->config['mobile']['features']['path'] = 'Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php';
  42. $this->config['mobile']['features']['classname'] = 'Zend_Http_UserAgent_Features_Adapter_DeviceAtlas';
  43. }
  44. public function testGetFromRequest()
  45. {
  46. $request['http_user_agent'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleW1ebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419.3';
  47. $deviceAtlas = Zend_Http_UserAgent_Features_Adapter_DeviceAtlas::getFromRequest($request, $this->config);
  48. $this->assertEquals(1, $deviceAtlas['touchScreen']);
  49. $this->assertEquals(1, $deviceAtlas['markup.xhtmlBasic10']);
  50. $this->assertEquals('iPhone', $deviceAtlas['model']);
  51. $this->assertEquals('Mozilla/5.0 (iPhone; U; C', $deviceAtlas['_matched']);
  52. $this->assertEquals('Apple', $deviceAtlas['vendor']);
  53. $request['http_user_agent'] = 'SonyEricssonK700i/R2AC SEMC-Browser/4.0.2 Profile/MIDP-2.0 Configuration/CLDC-1.1';
  54. $deviceAtlas = Zend_Http_UserAgent_Features_Adapter_DeviceAtlas::getFromRequest($request, $this->config);
  55. $this->assertEquals(20000, $deviceAtlas['memoryLimitMarkup']);
  56. $this->assertEquals('K700i', $deviceAtlas['model']);
  57. $this->assertEquals('SonyEricssonK700i', $deviceAtlas['_matched']);
  58. $this->assertEquals('Sony Ericsson', $deviceAtlas['vendor']);
  59. }
  60. }