FormPasswordTest.php 3.5 KB

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