2
0

FormSubmitTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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-2009 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_FormSubmitTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormSubmitTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  27. require_once 'Zend/View/Helper/FormSubmit.php';
  28. require_once 'Zend/View.php';
  29. require_once 'Zend/Registry.php';
  30. /**
  31. * Test class for Zend_View_Helper_FormSubmit.
  32. *
  33. * @category Zend
  34. * @package Zend_View
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_View
  39. * @group Zend_View_Helper
  40. */
  41. class Zend_View_Helper_FormSubmitTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @return void
  47. */
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormSubmitTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. /**
  54. * Sets up the fixture, for example, open a network connection.
  55. * This method is called before a test is executed.
  56. *
  57. * @return void
  58. */
  59. public function setUp()
  60. {
  61. if (Zend_Registry::isRegistered('Zend_View_Helper_Doctype')) {
  62. $registry = Zend_Registry::getInstance();
  63. unset($registry['Zend_View_Helper_Doctype']);
  64. }
  65. $this->view = new Zend_View();
  66. $this->helper = new Zend_View_Helper_FormSubmit();
  67. $this->helper->setView($this->view);
  68. }
  69. /**
  70. * Tears down the fixture, for example, close a network connection.
  71. * This method is called after a test is executed.
  72. *
  73. * @return void
  74. */
  75. public function tearDown()
  76. {
  77. unset($this->helper, $this->view);
  78. }
  79. public function testRendersSubmitInput()
  80. {
  81. $html = $this->helper->formSubmit(array(
  82. 'name' => 'foo',
  83. 'value' => 'Submit!',
  84. ));
  85. $this->assertRegexp('/<input[^>]*?(type="submit")/', $html);
  86. }
  87. /**
  88. * ZF-2254
  89. */
  90. public function testCanDisableSubmitButton()
  91. {
  92. $html = $this->helper->formSubmit(array(
  93. 'name' => 'foo',
  94. 'value' => 'Submit!',
  95. 'attribs' => array('disable' => true)
  96. ));
  97. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  98. }
  99. /**
  100. * ZF-2239
  101. */
  102. public function testValueAttributeIsAlwaysRendered()
  103. {
  104. $html = $this->helper->formSubmit(array(
  105. 'name' => 'foo',
  106. 'value' => '',
  107. ));
  108. $this->assertRegexp('/<input[^>]*?(value="")/', $html);
  109. }
  110. public function testRendersAsHtmlByDefault()
  111. {
  112. $test = $this->helper->formSubmit('foo', 'bar');
  113. $this->assertNotContains(' />', $test);
  114. }
  115. public function testCanRendersAsXHtml()
  116. {
  117. $this->view->doctype('XHTML1_STRICT');
  118. $test = $this->helper->formSubmit('foo', 'bar');
  119. $this->assertContains(' />', $test);
  120. }
  121. }
  122. // Call Zend_View_Helper_FormSubmitTest::main() if this source file is executed directly.
  123. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormSubmitTest::main") {
  124. Zend_View_Helper_FormSubmitTest::main();
  125. }