FormResetTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_View_Helper_FormResetTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormResetTest::main");
  25. }
  26. require_once 'Zend/View/Helper/FormReset.php';
  27. require_once 'Zend/View.php';
  28. require_once 'Zend/Registry.php';
  29. /**
  30. * Test class for Zend_View_Helper_FormReset.
  31. *
  32. * @category Zend
  33. * @package Zend_View
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2015 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_FormResetTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Runs the test methods of this class.
  44. *
  45. * @return void
  46. */
  47. public static function main()
  48. {
  49. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormResetTest");
  50. $result = PHPUnit_TextUI_TestRunner::run($suite);
  51. }
  52. /**
  53. * Sets up the fixture, for example, open a network connection.
  54. * This method is called before a test is executed.
  55. *
  56. * @return void
  57. */
  58. public function setUp()
  59. {
  60. if (Zend_Registry::isRegistered('Zend_View_Helper_Doctype')) {
  61. $registry = Zend_Registry::getInstance();
  62. unset($registry['Zend_View_Helper_Doctype']);
  63. }
  64. $this->view = new Zend_View();
  65. $this->helper = new Zend_View_Helper_FormReset();
  66. $this->helper->setView($this->view);
  67. }
  68. /**
  69. * Tears down the fixture, for example, close a network connection.
  70. * This method is called after a test is executed.
  71. *
  72. * @return void
  73. */
  74. public function tearDown()
  75. {
  76. unset($this->helper, $this->view);
  77. }
  78. public function testShouldRenderResetInput()
  79. {
  80. $html = $this->helper->formReset(array(
  81. 'name' => 'foo',
  82. 'value' => 'Reset',
  83. ));
  84. $this->assertRegexp('/<input[^>]*?(type="reset")/', $html);
  85. }
  86. /**
  87. * @group ZF-2845
  88. */
  89. public function testShouldAllowDisabling()
  90. {
  91. $html = $this->helper->formReset(array(
  92. 'name' => 'foo',
  93. 'value' => 'Reset',
  94. 'attribs' => array('disable' => true)
  95. ));
  96. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  97. }
  98. public function testShouldRenderAsHtmlByDefault()
  99. {
  100. $test = $this->helper->formReset('foo', 'bar');
  101. $this->assertNotContains(' />', $test);
  102. }
  103. public function testShouldAllowRenderingAsXHtml()
  104. {
  105. $this->view->doctype('XHTML1_STRICT');
  106. $test = $this->helper->formReset('foo', 'bar');
  107. $this->assertContains(' />', $test);
  108. }
  109. }
  110. // Call Zend_View_Helper_FormResetTest::main() if this source file is executed directly.
  111. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormResetTest::main") {
  112. Zend_View_Helper_FormResetTest::main();
  113. }