2
0

FormFileTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // Call Zend_View_Helper_FormFileTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormFileTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/View.php';
  8. require_once 'Zend/View/Helper/FormFile.php';
  9. require_once 'Zend/Registry.php';
  10. /**
  11. * Zend_View_Helper_FormFileTest
  12. *
  13. * Tests formFile helper
  14. *
  15. * @uses PHPUnit_Framework_TestCase
  16. */
  17. class Zend_View_Helper_FormFileTest 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_FormFileTest");
  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_FormFile();
  44. $this->helper->setView($this->view);
  45. }
  46. /**
  47. * ZF-1666
  48. */
  49. public function testCanDisableElement()
  50. {
  51. $html = $this->helper->formFile(array(
  52. 'name' => 'foo',
  53. 'attribs' => array('disable' => true)
  54. ));
  55. $this->assertRegexp('/<input[^>]*?(disabled="disabled")/', $html);
  56. }
  57. /**
  58. * ZF-1666
  59. */
  60. public function testDisablingElementDoesNotRenderHiddenElements()
  61. {
  62. $html = $this->helper->formFile(array(
  63. 'name' => 'foo',
  64. 'attribs' => array('disable' => true)
  65. ));
  66. $this->assertNotRegexp('/<input[^>]*?(type="hidden")/', $html);
  67. }
  68. public function testRendersAsHtmlByDefault()
  69. {
  70. $test = $this->helper->formFile(array(
  71. 'name' => 'foo',
  72. ));
  73. $this->assertNotContains(' />', $test);
  74. }
  75. public function testCanRendersAsXHtml()
  76. {
  77. $this->view->doctype('XHTML1_STRICT');
  78. $test = $this->helper->formFile(array(
  79. 'name' => 'foo',
  80. ));
  81. $this->assertContains(' />', $test);
  82. }
  83. }
  84. // Call Zend_View_Helper_FormFileTest::main() if this source file is executed directly.
  85. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormFileTest::main") {
  86. Zend_View_Helper_FormFileTest::main();
  87. }