FormSubmitTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // Call Zend_View_Helper_FormSubmitTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormSubmitTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/View/Helper/FormSubmit.php';
  8. require_once 'Zend/View.php';
  9. require_once 'Zend/Registry.php';
  10. /**
  11. * Test class for Zend_View_Helper_FormSubmit.
  12. */
  13. class Zend_View_Helper_FormSubmitTest 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_FormSubmitTest");
  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_FormSubmit();
  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 testRendersSubmitInput()
  52. {
  53. $html = $this->helper->formSubmit(array(
  54. 'name' => 'foo',
  55. 'value' => 'Submit!',
  56. ));
  57. $this->assertRegexp('/<input[^>]*?(type="submit")/', $html);
  58. }
  59. /**
  60. * ZF-2254
  61. */
  62. public function testCanDisableSubmitButton()
  63. {
  64. $html = $this->helper->formSubmit(array(
  65. 'name' => 'foo',
  66. 'value' => 'Submit!',
  67. 'attribs' => array('disable' => true)
  68. ));
  69. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  70. }
  71. /**
  72. * ZF-2239
  73. */
  74. public function testValueAttributeIsAlwaysRendered()
  75. {
  76. $html = $this->helper->formSubmit(array(
  77. 'name' => 'foo',
  78. 'value' => '',
  79. ));
  80. $this->assertRegexp('/<input[^>]*?(value="")/', $html);
  81. }
  82. public function testRendersAsHtmlByDefault()
  83. {
  84. $test = $this->helper->formSubmit('foo', 'bar');
  85. $this->assertNotContains(' />', $test);
  86. }
  87. public function testCanRendersAsXHtml()
  88. {
  89. $this->view->doctype('XHTML1_STRICT');
  90. $test = $this->helper->formSubmit('foo', 'bar');
  91. $this->assertContains(' />', $test);
  92. }
  93. }
  94. // Call Zend_View_Helper_FormSubmitTest::main() if this source file is executed directly.
  95. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormSubmitTest::main") {
  96. Zend_View_Helper_FormSubmitTest::main();
  97. }