FormFileTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_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-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_FormFileTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * @var Zend_View
  46. */
  47. protected $view;
  48. /**
  49. * @var Zend_View_Helper_FormFile
  50. */
  51. protected $helper;
  52. /**
  53. * Runs the test methods of this class.
  54. *
  55. * @access public
  56. * @static
  57. */
  58. public static function main()
  59. {
  60. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormFileTest");
  61. PHPUnit_TextUI_TestRunner::run($suite);
  62. }
  63. /**
  64. * Sets up the fixture, for example, open a network connection.
  65. * This method is called before a test is executed.
  66. *
  67. * @access protected
  68. */
  69. protected function setUp()
  70. {
  71. if (Zend_Registry::isRegistered('Zend_View_Helper_Doctype')) {
  72. $registry = Zend_Registry::getInstance();
  73. unset($registry['Zend_View_Helper_Doctype']);
  74. }
  75. $this->view = new Zend_View();
  76. $this->helper = new Zend_View_Helper_FormFile();
  77. $this->helper->setView($this->view);
  78. }
  79. /**
  80. * ZF-1666
  81. */
  82. public function testCanDisableElement()
  83. {
  84. $html = $this->helper->formFile(array(
  85. 'name' => 'foo',
  86. 'attribs' => array('disable' => true)
  87. ));
  88. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  89. }
  90. /**
  91. * ZF-1666
  92. */
  93. public function testDisablingElementDoesNotRenderHiddenElements()
  94. {
  95. $html = $this->helper->formFile(array(
  96. 'name' => 'foo',
  97. 'attribs' => array('disable' => true)
  98. ));
  99. $this->assertNotRegexp('/<input[^>]*?(type="hidden")/', $html);
  100. }
  101. public function testRendersAsHtmlByDefault()
  102. {
  103. $test = $this->helper->formFile(array(
  104. 'name' => 'foo',
  105. ));
  106. $this->assertNotContains(' />', $test);
  107. }
  108. public function testCanRendersAsXHtml()
  109. {
  110. $this->view->doctype('XHTML1_STRICT');
  111. $test = $this->helper->formFile(array(
  112. 'name' => 'foo',
  113. ));
  114. $this->assertContains(' />', $test);
  115. }
  116. /**
  117. * @group GH-191
  118. */
  119. public function testRendersCustomAttributes()
  120. {
  121. $test = $this->helper->formFile(
  122. 'foo',
  123. array(
  124. 'data-image-old' => 100,
  125. 'data-image-new' => 200,
  126. )
  127. );
  128. $this->assertEquals(
  129. '<input type="file" name="foo" id="foo" data-image-old="100" data-image-new="200">',
  130. $test
  131. );
  132. }
  133. }
  134. // Call Zend_View_Helper_FormFileTest::main() if this source file is executed directly.
  135. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormFileTest::main") {
  136. Zend_View_Helper_FormFileTest::main();
  137. }