2
0

FormResetTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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-2010 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 dirname(__FILE__) . '/../../../TestHelper.php';
  27. require_once 'Zend/View/Helper/FormReset.php';
  28. require_once 'Zend/View.php';
  29. require_once 'Zend/Registry.php';
  30. /**
  31. * Test class for Zend_View_Helper_FormReset.
  32. *
  33. * @category Zend
  34. * @package Zend_View
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2010 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_FormResetTest 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_FormResetTest");
  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_FormReset();
  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 testShouldRenderResetInput()
  80. {
  81. $html = $this->helper->formReset(array(
  82. 'name' => 'foo',
  83. 'value' => 'Reset',
  84. ));
  85. $this->assertRegexp('/<input[^>]*?(type="reset")/', $html);
  86. }
  87. /**
  88. * @see ZF-2845
  89. */
  90. public function testShouldAllowDisabling()
  91. {
  92. $html = $this->helper->formReset(array(
  93. 'name' => 'foo',
  94. 'value' => 'Reset',
  95. 'attribs' => array('disable' => true)
  96. ));
  97. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  98. }
  99. public function testShouldRenderAsHtmlByDefault()
  100. {
  101. $test = $this->helper->formReset('foo', 'bar');
  102. $this->assertNotContains(' />', $test);
  103. }
  104. public function testShouldAllowRenderingAsXHtml()
  105. {
  106. $this->view->doctype('XHTML1_STRICT');
  107. $test = $this->helper->formReset('foo', 'bar');
  108. $this->assertContains(' />', $test);
  109. }
  110. }
  111. // Call Zend_View_Helper_FormResetTest::main() if this source file is executed directly.
  112. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormResetTest::main") {
  113. Zend_View_Helper_FormResetTest::main();
  114. }