2
0

FormTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-2010 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_FormTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  27. require_once 'Zend/View.php';
  28. require_once 'Zend/View/Helper/Form.php';
  29. /**
  30. * Test class for Zend_View_Helper_Form.
  31. *
  32. * @category Zend
  33. * @package Zend_View
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_View
  38. * @group Zend_View_Helper
  39. */
  40. class Zend_View_Helper_FormTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Runs the test methods of this class.
  44. *
  45. * @access public
  46. * @static
  47. */
  48. public static function main()
  49. {
  50. require_once "PHPUnit/TextUI/TestRunner.php";
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormTest");
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Sets up the fixture, for example, open a network connection.
  56. * This method is called before a test is executed.
  57. *
  58. * @access protected
  59. */
  60. protected function setUp()
  61. {
  62. $this->view = new Zend_View();
  63. $this->helper = new Zend_View_Helper_Form();
  64. $this->helper->setView($this->view);
  65. }
  66. /**
  67. * Tears down the fixture, for example, close a network connection.
  68. * This method is called after a test is executed.
  69. *
  70. * @access protected
  71. */
  72. protected function tearDown()
  73. {
  74. }
  75. public function testFormWithSaneInput()
  76. {
  77. $form = $this->helper->form('foo', array('action' => '/foo', 'method' => 'get'));
  78. $this->assertRegexp('/<form[^>]*(id="foo")/', $form);
  79. $this->assertRegexp('/<form[^>]*(action="\/foo")/', $form);
  80. $this->assertRegexp('/<form[^>]*(method="get")/', $form);
  81. }
  82. public function testFormWithInputNeedingEscapesUsesViewEscaping()
  83. {
  84. $form = $this->helper->form('<&foo');
  85. $this->assertContains($this->view->escape('<&foo'), $form);
  86. }
  87. public function testPassingIdAsAttributeShouldRenderIdAttribAndNotName()
  88. {
  89. $form = $this->helper->form('foo', array('action' => '/foo', 'method' => 'get', 'id' => 'bar'));
  90. $this->assertRegexp('/<form[^>]*(id="bar")/', $form);
  91. $this->assertNotRegexp('/<form[^>]*(name="foo")/', $form);
  92. }
  93. /**
  94. * @see ZF-3832
  95. */
  96. public function testEmptyIdShouldNotRenderIdAttribute()
  97. {
  98. $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get'));
  99. $this->assertNotRegexp('/<form[^>]*(id="")/', $form);
  100. $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get', 'id' => null));
  101. $this->assertNotRegexp('/<form[^>]*(id="")/', $form);
  102. }
  103. }
  104. // Call Zend_View_Helper_FormTest::main() if this source file is executed directly.
  105. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormTest::main") {
  106. Zend_View_Helper_FormTest::main();
  107. }