FormFileTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-2012 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_FormFileTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormFileTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/FormFile.php';
  28. require_once 'Zend/Registry.php';
  29. /**
  30. * Zend_View_Helper_FormFileTest
  31. *
  32. * Tests formFile helper
  33. *
  34. * @category Zend
  35. * @package Zend_View
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2012 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_FormFileTest 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_FormFileTest");
  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_FormFile();
  69. $this->helper->setView($this->view);
  70. }
  71. /**
  72. * ZF-1666
  73. */
  74. public function testCanDisableElement()
  75. {
  76. $html = $this->helper->formFile(array(
  77. 'name' => 'foo',
  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->formFile(array(
  88. 'name' => 'foo',
  89. 'attribs' => array('disable' => true)
  90. ));
  91. $this->assertNotRegexp('/<input[^>]*?(type="hidden")/', $html);
  92. }
  93. public function testRendersAsHtmlByDefault()
  94. {
  95. $test = $this->helper->formFile(array(
  96. 'name' => 'foo',
  97. ));
  98. $this->assertNotContains(' />', $test);
  99. }
  100. public function testCanRendersAsXHtml()
  101. {
  102. $this->view->doctype('XHTML1_STRICT');
  103. $test = $this->helper->formFile(array(
  104. 'name' => 'foo',
  105. ));
  106. $this->assertContains(' />', $test);
  107. }
  108. }
  109. // Call Zend_View_Helper_FormFileTest::main() if this source file is executed directly.
  110. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormFileTest::main") {
  111. Zend_View_Helper_FormFileTest::main();
  112. }