2
0

FormTextTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_FormTextTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormTextTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  27. require_once 'Zend/View.php';
  28. require_once 'Zend/View/Helper/FormText.php';
  29. require_once 'Zend/Registry.php';
  30. /**
  31. * Zend_View_Helper_FormTextTest
  32. *
  33. * Tests formText helper, including some common functionality of all form helpers
  34. * @category Zend
  35. * @package Zend_View
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_View
  40. * @group Zend_View_Helper
  41. */
  42. class Zend_View_Helper_FormTextTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @access public
  48. * @static
  49. */
  50. public static function main()
  51. {
  52. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormTextTest");
  53. $result = PHPUnit_TextUI_TestRunner::run($suite);
  54. }
  55. /**
  56. * Sets up the fixture, for example, open a network connection.
  57. * This method is called before a test is executed.
  58. *
  59. * @access protected
  60. */
  61. protected function setUp()
  62. {
  63. if (Zend_Registry::isRegistered('Zend_View_Helper_Doctype')) {
  64. $registry = Zend_Registry::getInstance();
  65. unset($registry['Zend_View_Helper_Doctype']);
  66. }
  67. $this->view = new Zend_View();
  68. $this->helper = new Zend_View_Helper_FormText();
  69. $this->helper->setView($this->view);
  70. }
  71. public function testIdSetFromName()
  72. {
  73. $element = $this->helper->formText('foo');
  74. $this->assertContains('name="foo"', $element);
  75. $this->assertContains('id="foo"', $element);
  76. }
  77. public function testSetIdFromAttribs()
  78. {
  79. $element = $this->helper->formText('foo', null, array('id' => 'bar'));
  80. $this->assertContains('name="foo"', $element);
  81. $this->assertContains('id="bar"', $element);
  82. }
  83. public function testSetValue()
  84. {
  85. $element = $this->helper->formText('foo', 'bar');
  86. $this->assertContains('name="foo"', $element);
  87. $this->assertContains('value="bar"', $element);
  88. }
  89. public function testReadOnlyAttribute()
  90. {
  91. $element = $this->helper->formText('foo', null, array('readonly' => 'readonly'));
  92. $this->assertContains('readonly="readonly"', $element);
  93. }
  94. /**
  95. * ZF-1666
  96. */
  97. public function testCanDisableElement()
  98. {
  99. $html = $this->helper->formText(array(
  100. 'name' => 'foo',
  101. 'value' => 'bar',
  102. 'attribs' => array('disable' => true)
  103. ));
  104. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  105. }
  106. /**
  107. * ZF-1666
  108. */
  109. public function testDisablingElementDoesNotRenderHiddenElements()
  110. {
  111. $html = $this->helper->formText(array(
  112. 'name' => 'foo',
  113. 'value' => 'bar',
  114. 'attribs' => array('disable' => true)
  115. ));
  116. $this->assertNotRegexp('/<input[^>]*?(type="hidden")/', $html);
  117. }
  118. public function testRendersAsHtmlByDefault()
  119. {
  120. $test = $this->helper->formText('foo', 'bar');
  121. $this->assertNotContains(' />', $test);
  122. }
  123. public function testCanRendersAsXHtml()
  124. {
  125. $this->view->doctype('XHTML1_STRICT');
  126. $test = $this->helper->formText('foo', 'bar');
  127. $this->assertContains(' />', $test);
  128. }
  129. }
  130. // Call Zend_View_Helper_FormTextTest::main() if this source file is executed directly.
  131. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormTextTest::main") {
  132. Zend_View_Helper_FormTextTest::main();
  133. }