FormPasswordTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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-2015 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_FormPasswordTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormPasswordTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/FormPassword.php';
  28. require_once 'Zend/Registry.php';
  29. /**
  30. * Zend_View_Helper_FormPasswordTest
  31. *
  32. * Tests formPassword helper
  33. *
  34. * @category Zend
  35. * @package Zend_View
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2015 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_FormPasswordTest 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_FormPasswordTest");
  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_FormPassword();
  69. $this->helper->setView($this->view);
  70. }
  71. /**
  72. * @group ZF-1666
  73. */
  74. public function testCanDisableElement()
  75. {
  76. $html = $this->helper->formPassword(array(
  77. 'name' => 'foo',
  78. 'value' => 'bar',
  79. 'attribs' => array('disable' => true)
  80. ));
  81. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  82. }
  83. /**
  84. * @group ZF-1666
  85. */
  86. public function testDisablingElementDoesNotRenderHiddenElements()
  87. {
  88. $html = $this->helper->formPassword(array(
  89. 'name' => 'foo',
  90. 'value' => 'bar',
  91. 'attribs' => array('disable' => true)
  92. ));
  93. $this->assertNotRegexp('/<input[^>]*?(type="hidden")/', $html);
  94. }
  95. public function testShouldRenderAsHtmlByDefault()
  96. {
  97. $test = $this->helper->formPassword('foo', 'bar');
  98. $this->assertNotContains(' />', $test);
  99. }
  100. public function testShouldAllowRenderingAsXhtml()
  101. {
  102. $this->view->doctype('XHTML1_STRICT');
  103. $test = $this->helper->formPassword('foo', 'bar');
  104. $this->assertContains(' />', $test);
  105. }
  106. public function testShouldNotRenderValueByDefault()
  107. {
  108. $test = $this->helper->formPassword('foo', 'bar');
  109. $this->assertNotContains('bar', $test);
  110. }
  111. /**
  112. * @group ZF-2860
  113. */
  114. public function testShouldRenderValueWhenRenderPasswordFlagPresentAndTrue()
  115. {
  116. $test = $this->helper->formPassword('foo', 'bar', array('renderPassword' => true));
  117. $this->assertContains('value="bar"', $test);
  118. }
  119. /**
  120. * @group ZF-2860
  121. */
  122. public function testRenderPasswordAttribShouldNeverBeRendered()
  123. {
  124. $test = $this->helper->formPassword('foo', 'bar', array('renderPassword' => true));
  125. $this->assertNotContains('renderPassword', $test);
  126. $test = $this->helper->formPassword('foo', 'bar', array('renderPassword' => false));
  127. $this->assertNotContains('renderPassword', $test);
  128. }
  129. }
  130. // Call Zend_View_Helper_FormPasswordTest::main() if this source file is executed directly.
  131. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormPasswordTest::main") {
  132. Zend_View_Helper_FormPasswordTest::main();
  133. }