DeviceAtlasTest.php 3.1 KB

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