UserAgentTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_View
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: UserAgentTest.php $
  21. */
  22. // Call Zend_View_Helper_UserAgentTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_UserAgentTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/UserAgent.php';
  28. require_once 'Zend/Http/UserAgent.php';
  29. /**
  30. * Zend_View_Helper_UserAgentTest
  31. *
  32. * @category Zend
  33. * @package Zend_View
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_View
  38. * @group Zend_View_Helper
  39. */
  40. class Zend_View_Helper_UserAgentTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * @var Zend_View_Helper_UserAgent
  44. */
  45. protected $helper;
  46. /**
  47. * @var Zend_Http_UserAgent
  48. */
  49. protected $userAgent;
  50. /**
  51. * Runs the test methods of this class.
  52. */
  53. public static function main()
  54. {
  55. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_UrlTest");
  56. $result = PHPUnit_TextUI_TestRunner::run($suite);
  57. }
  58. /**
  59. * Sets up the fixture, for example, open a network connection.
  60. * This method is called before a test is executed.
  61. */
  62. protected function setUp()
  63. {
  64. $this->helper = new Zend_View_Helper_UserAgent();
  65. $this->userAgent = new Zend_Http_UserAgent();
  66. }
  67. public function testHelperMethod()
  68. {
  69. $this->assertTrue(
  70. $this->helper->userAgent() instanceof Zend_Http_UserAgent
  71. );
  72. $this->helper->userAgent($this->userAgent);
  73. $this->assertEquals(
  74. spl_object_hash($this->userAgent),
  75. spl_object_hash($this->helper->getUserAgent())
  76. );
  77. }
  78. public function testGetUserAgentDefault()
  79. {
  80. $this->assertTrue(
  81. $this->helper->getUserAgent() instanceof Zend_Http_UserAgent
  82. );
  83. }
  84. public function testSetAndGetUserAgent()
  85. {
  86. $this->helper->setUserAgent($this->userAgent);
  87. $this->assertEquals(
  88. spl_object_hash($this->userAgent),
  89. spl_object_hash($this->helper->getUserAgent())
  90. );
  91. }
  92. }
  93. // Call Zend_View_Helper_UrlTest::main() if this source file is executed directly.
  94. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_UserAgentTest::main") {
  95. Zend_View_Helper_UserAgentTest::main();
  96. }