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