2
0

SubFormTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_Form
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Form_SubFormTest::main');
  24. }
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. require_once 'PHPUnit/Framework/TestSuite.php';
  27. require_once 'PHPUnit/TextUI/TestRunner.php';
  28. // error_reporting(E_ALL);
  29. require_once 'Zend/Form/SubForm.php';
  30. require_once 'Zend/View.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_Form
  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_Form
  38. */
  39. class Zend_Form_SubFormTest extends PHPUnit_Framework_TestCase
  40. {
  41. public static function main()
  42. {
  43. require_once "PHPUnit/TextUI/TestRunner.php";
  44. $suite = new PHPUnit_Framework_TestSuite('Zend_Form_SubFormTest');
  45. $result = PHPUnit_TextUI_TestRunner::run($suite);
  46. }
  47. public function setUp()
  48. {
  49. Zend_Form::setDefaultTranslator(null);
  50. $this->form = new Zend_Form_SubForm();
  51. }
  52. public function tearDown()
  53. {
  54. }
  55. // General
  56. public function testSubFormUtilizesDefaultDecorators()
  57. {
  58. $decorators = $this->form->getDecorators();
  59. $this->assertTrue(array_key_exists('Zend_Form_Decorator_FormElements', $decorators));
  60. $this->assertTrue(array_key_exists('Zend_Form_Decorator_HtmlTag', $decorators));
  61. $this->assertTrue(array_key_exists('Zend_Form_Decorator_Fieldset', $decorators));
  62. $this->assertTrue(array_key_exists('Zend_Form_Decorator_DtDdWrapper', $decorators));
  63. $htmlTag = $decorators['Zend_Form_Decorator_HtmlTag'];
  64. $tag = $htmlTag->getOption('tag');
  65. $this->assertEquals('dl', $tag);
  66. }
  67. public function testSubFormIsArrayByDefault()
  68. {
  69. $this->assertTrue($this->form->isArray());
  70. }
  71. public function testElementsBelongToSubFormNameByDefault()
  72. {
  73. $this->testSubFormIsArrayByDefault();
  74. $this->form->setName('foo');
  75. $this->assertEquals($this->form->getName(), $this->form->getElementsBelongTo());
  76. }
  77. // Extensions
  78. public function testInitCalledBeforeLoadDecorators()
  79. {
  80. $form = new Zend_Form_SubFormTest_SubForm();
  81. $decorators = $form->getDecorators();
  82. $this->assertTrue(empty($decorators));
  83. }
  84. // Bugfixes
  85. /**
  86. * @see ZF-2883
  87. */
  88. public function testDisplayGroupsShouldInheritSubFormNamespace()
  89. {
  90. $this->form->addElement('text', 'foo')
  91. ->addElement('text', 'bar')
  92. ->addDisplayGroup(array('foo', 'bar'), 'foobar');
  93. $form = new Zend_Form();
  94. $form->addSubForm($this->form, 'attributes');
  95. $html = $form->render(new Zend_View());
  96. $this->assertContains('name="attributes[foo]"', $html);
  97. $this->assertContains('name="attributes[bar]"', $html);
  98. }
  99. /**
  100. * @see ZF-3272
  101. */
  102. public function testRenderedSubFormDtShouldContainNoBreakSpace()
  103. {
  104. $subForm = new Zend_Form_SubForm(array(
  105. 'elements' => array(
  106. 'foo' => 'text',
  107. 'bar' => 'text',
  108. ),
  109. ));
  110. $form = new Zend_Form();
  111. $form->addSubForm($subForm, 'foobar')
  112. ->setView(new Zend_View);
  113. $html = $form->render();
  114. $this->assertContains('<dt>&nbsp;</dt>', $html);
  115. }
  116. }
  117. class Zend_Form_SubFormTest_SubForm extends Zend_Form_SubForm
  118. {
  119. public function init()
  120. {
  121. $this->setDisableLoadDefaultDecorators(true);
  122. }
  123. }
  124. if (PHPUnit_MAIN_METHOD == 'Zend_Form_SubFormTest::main') {
  125. Zend_Form_SubFormTest::main();
  126. }