2
0

FormTextTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // Call Zend_View_Helper_FormTextTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormTextTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/View.php';
  8. require_once 'Zend/View/Helper/FormText.php';
  9. require_once 'Zend/Registry.php';
  10. /**
  11. * Zend_View_Helper_FormTextTest
  12. *
  13. * Tests formText helper, including some common functionality of all form helpers
  14. *
  15. * @uses PHPUnit_Framework_TestCase
  16. * @version $Id$
  17. */
  18. class Zend_View_Helper_FormTextTest extends PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * Runs the test methods of this class.
  22. *
  23. * @access public
  24. * @static
  25. */
  26. public static function main()
  27. {
  28. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormTextTest");
  29. $result = PHPUnit_TextUI_TestRunner::run($suite);
  30. }
  31. /**
  32. * Sets up the fixture, for example, open a network connection.
  33. * This method is called before a test is executed.
  34. *
  35. * @access protected
  36. */
  37. protected function setUp()
  38. {
  39. if (Zend_Registry::isRegistered('Zend_View_Helper_Doctype')) {
  40. $registry = Zend_Registry::getInstance();
  41. unset($registry['Zend_View_Helper_Doctype']);
  42. }
  43. $this->view = new Zend_View();
  44. $this->helper = new Zend_View_Helper_FormText();
  45. $this->helper->setView($this->view);
  46. }
  47. public function testIdSetFromName()
  48. {
  49. $element = $this->helper->formText('foo');
  50. $this->assertContains('name="foo"', $element);
  51. $this->assertContains('id="foo"', $element);
  52. }
  53. public function testSetIdFromAttribs()
  54. {
  55. $element = $this->helper->formText('foo', null, array('id' => 'bar'));
  56. $this->assertContains('name="foo"', $element);
  57. $this->assertContains('id="bar"', $element);
  58. }
  59. public function testSetValue()
  60. {
  61. $element = $this->helper->formText('foo', 'bar');
  62. $this->assertContains('name="foo"', $element);
  63. $this->assertContains('value="bar"', $element);
  64. }
  65. public function testReadOnlyAttribute()
  66. {
  67. $element = $this->helper->formText('foo', null, array('readonly' => 'readonly'));
  68. $this->assertContains('readonly="readonly"', $element);
  69. }
  70. /**
  71. * ZF-1666
  72. */
  73. public function testCanDisableElement()
  74. {
  75. $html = $this->helper->formText(array(
  76. 'name' => 'foo',
  77. 'value' => 'bar',
  78. 'attribs' => array('disable' => true)
  79. ));
  80. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  81. }
  82. /**
  83. * ZF-1666
  84. */
  85. public function testDisablingElementDoesNotRenderHiddenElements()
  86. {
  87. $html = $this->helper->formText(array(
  88. 'name' => 'foo',
  89. 'value' => 'bar',
  90. 'attribs' => array('disable' => true)
  91. ));
  92. $this->assertNotRegexp('/<input[^>]*?(type="hidden")/', $html);
  93. }
  94. public function testRendersAsHtmlByDefault()
  95. {
  96. $test = $this->helper->formText('foo', 'bar');
  97. $this->assertNotContains(' />', $test);
  98. }
  99. public function testCanRendersAsXHtml()
  100. {
  101. $this->view->doctype('XHTML1_STRICT');
  102. $test = $this->helper->formText('foo', 'bar');
  103. $this->assertContains(' />', $test);
  104. }
  105. }
  106. // Call Zend_View_Helper_FormTextTest::main() if this source file is executed directly.
  107. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormTextTest::main") {
  108. Zend_View_Helper_FormTextTest::main();
  109. }