SubFormTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. if (!defined('PHPUnit_MAIN_METHOD')) {
  3. define('PHPUnit_MAIN_METHOD', 'Zend_Form_SubFormTest::main');
  4. }
  5. require_once dirname(__FILE__) . '/../../TestHelper.php';
  6. require_once 'PHPUnit/Framework/TestSuite.php';
  7. require_once 'PHPUnit/TextUI/TestRunner.php';
  8. // error_reporting(E_ALL);
  9. require_once 'Zend/Form/SubForm.php';
  10. require_once 'Zend/View.php';
  11. class Zend_Form_SubFormTest extends PHPUnit_Framework_TestCase
  12. {
  13. public static function main()
  14. {
  15. require_once "PHPUnit/TextUI/TestRunner.php";
  16. $suite = new PHPUnit_Framework_TestSuite('Zend_Form_SubFormTest');
  17. $result = PHPUnit_TextUI_TestRunner::run($suite);
  18. }
  19. public function setUp()
  20. {
  21. Zend_Form::setDefaultTranslator(null);
  22. $this->form = new Zend_Form_SubForm();
  23. }
  24. public function tearDown()
  25. {
  26. }
  27. // General
  28. public function testSubFormUtilizesDefaultDecorators()
  29. {
  30. $decorators = $this->form->getDecorators();
  31. $this->assertTrue(array_key_exists('Zend_Form_Decorator_FormElements', $decorators));
  32. $this->assertTrue(array_key_exists('Zend_Form_Decorator_HtmlTag', $decorators));
  33. $this->assertTrue(array_key_exists('Zend_Form_Decorator_Fieldset', $decorators));
  34. $this->assertTrue(array_key_exists('Zend_Form_Decorator_DtDdWrapper', $decorators));
  35. $htmlTag = $decorators['Zend_Form_Decorator_HtmlTag'];
  36. $tag = $htmlTag->getOption('tag');
  37. $this->assertEquals('dl', $tag);
  38. }
  39. public function testSubFormIsArrayByDefault()
  40. {
  41. $this->assertTrue($this->form->isArray());
  42. }
  43. public function testElementsBelongToSubFormNameByDefault()
  44. {
  45. $this->testSubFormIsArrayByDefault();
  46. $this->form->setName('foo');
  47. $this->assertEquals($this->form->getName(), $this->form->getElementsBelongTo());
  48. }
  49. // Extensions
  50. public function testInitCalledBeforeLoadDecorators()
  51. {
  52. $form = new Zend_Form_SubFormTest_SubForm();
  53. $decorators = $form->getDecorators();
  54. $this->assertTrue(empty($decorators));
  55. }
  56. // Bugfixes
  57. /**
  58. * @see ZF-2883
  59. */
  60. public function testDisplayGroupsShouldInheritSubFormNamespace()
  61. {
  62. $this->form->addElement('text', 'foo')
  63. ->addElement('text', 'bar')
  64. ->addDisplayGroup(array('foo', 'bar'), 'foobar');
  65. $form = new Zend_Form();
  66. $form->addSubForm($this->form, 'attributes');
  67. $html = $form->render(new Zend_View());
  68. $this->assertContains('name="attributes[foo]"', $html);
  69. $this->assertContains('name="attributes[bar]"', $html);
  70. }
  71. /**
  72. * @see ZF-3272
  73. */
  74. public function testRenderedSubFormDtShouldContainNoBreakSpace()
  75. {
  76. $subForm = new Zend_Form_SubForm(array(
  77. 'elements' => array(
  78. 'foo' => 'text',
  79. 'bar' => 'text',
  80. ),
  81. ));
  82. $form = new Zend_Form();
  83. $form->addSubForm($subForm, 'foobar')
  84. ->setView(new Zend_View);
  85. $html = $form->render();
  86. $this->assertContains('<dt>&nbsp;</dt>', $html);
  87. }
  88. }
  89. class Zend_Form_SubFormTest_SubForm extends Zend_Form_SubForm
  90. {
  91. public function init()
  92. {
  93. $this->setDisableLoadDefaultDecorators(true);
  94. }
  95. }
  96. if (PHPUnit_MAIN_METHOD == 'Zend_Form_SubFormTest::main') {
  97. Zend_Form_SubFormTest::main();
  98. }