FormResetTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // Call Zend_View_Helper_FormResetTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormResetTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/View/Helper/FormReset.php';
  8. require_once 'Zend/View.php';
  9. require_once 'Zend/Registry.php';
  10. /**
  11. * Test class for Zend_View_Helper_FormReset.
  12. */
  13. class Zend_View_Helper_FormResetTest extends PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * Runs the test methods of this class.
  17. *
  18. * @return void
  19. */
  20. public static function main()
  21. {
  22. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormResetTest");
  23. $result = PHPUnit_TextUI_TestRunner::run($suite);
  24. }
  25. /**
  26. * Sets up the fixture, for example, open a network connection.
  27. * This method is called before a test is executed.
  28. *
  29. * @return void
  30. */
  31. public function setUp()
  32. {
  33. if (Zend_Registry::isRegistered('Zend_View_Helper_Doctype')) {
  34. $registry = Zend_Registry::getInstance();
  35. unset($registry['Zend_View_Helper_Doctype']);
  36. }
  37. $this->view = new Zend_View();
  38. $this->helper = new Zend_View_Helper_FormReset();
  39. $this->helper->setView($this->view);
  40. }
  41. /**
  42. * Tears down the fixture, for example, close a network connection.
  43. * This method is called after a test is executed.
  44. *
  45. * @return void
  46. */
  47. public function tearDown()
  48. {
  49. unset($this->helper, $this->view);
  50. }
  51. public function testShouldRenderResetInput()
  52. {
  53. $html = $this->helper->formReset(array(
  54. 'name' => 'foo',
  55. 'value' => 'Reset',
  56. ));
  57. $this->assertRegexp('/<input[^>]*?(type="reset")/', $html);
  58. }
  59. /**
  60. * @see ZF-2845
  61. */
  62. public function testShouldAllowDisabling()
  63. {
  64. $html = $this->helper->formReset(array(
  65. 'name' => 'foo',
  66. 'value' => 'Reset',
  67. 'attribs' => array('disable' => true)
  68. ));
  69. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  70. }
  71. public function testShouldRenderAsHtmlByDefault()
  72. {
  73. $test = $this->helper->formReset('foo', 'bar');
  74. $this->assertNotContains(' />', $test);
  75. }
  76. public function testShouldAllowRenderingAsXHtml()
  77. {
  78. $this->view->doctype('XHTML1_STRICT');
  79. $test = $this->helper->formReset('foo', 'bar');
  80. $this->assertContains(' />', $test);
  81. }
  82. }
  83. // Call Zend_View_Helper_FormResetTest::main() if this source file is executed directly.
  84. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormResetTest::main") {
  85. Zend_View_Helper_FormResetTest::main();
  86. }