Переглянути джерело

Merge r25192 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25193 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch 13 роки тому
батько
коміт
23054dcb34
2 змінених файлів з 125 додано та 2 видалено
  1. 10 1
      library/Zend/Form.php
  2. 115 1
      tests/Zend/Form/FormTest.php

+ 10 - 1
library/Zend/Form.php

@@ -353,6 +353,11 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
             unset($options['attribs']);
         }
 
+        if (isset($options['subForms'])) {
+            $this->addSubForms($options['subForms']);
+            unset($options['subForms']);
+        }
+
         $forbidden = array(
             'Options', 'Config', 'PluginLoader', 'SubForms', 'Translator',
             'Attrib', 'Default',
@@ -1640,7 +1645,7 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
     public function addSubForms(array $subForms)
     {
         foreach ($subForms as $key => $spec) {          
-            $name= (string) $key;
+            $name = (string) $key;
             if ($spec instanceof Zend_Form) {
                 $this->addSubForm($spec, $name);
                 continue;
@@ -1654,6 +1659,10 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
                         continue;
                     case (1 <= $argc):
                         $subForm = array_shift($spec);
+
+                        if (!$subForm instanceof Zend_Form) {
+                            $subForm = new Zend_Form_SubForm($subForm);
+                        }
                     case (2 <= $argc):
                         $name  = array_shift($spec);
                     case (3 <= $argc):

+ 115 - 1
tests/Zend/Form/FormTest.php

@@ -137,7 +137,6 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase
     {
         $options = $this->getOptions();
         $options['pluginLoader'] = true;
-        $options['subForms']     = true;
         $options['view']         = true;
         $options['translator']   = true;
         $options['default']      = true;
@@ -4377,6 +4376,121 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase
         );
     }
 
+    public function testNameAttributeOutputForXhtml()
+    {
+        // Create form
+        $form = new Zend_Form();
+        $form->setName('foo');
+        $form->setMethod(Zend_Form::METHOD_GET);
+        $form->removeDecorator('HtmlTag');
+
+        // Set doctype
+        $this->getView()->getHelper('doctype')->doctype(
+            Zend_View_Helper_Doctype::XHTML1_STRICT
+        );
+
+        $expected = '<form id="foo" method="get" action="">'
+                  . PHP_EOL
+                  . '</form>';
+
+        $this->assertSame(
+            $expected,
+            $form->render($this->getView())
+        );
+    }
+
+    /**
+     * @group ZF-5613
+     */
+    public function testAddSubFormsPerConfig()
+    {
+        // Create form
+        $form = new Zend_Form(
+            array(
+                'subForms' => array(
+                    array(
+                        'form' => array(
+                            'elements' => array(
+                                'foo' => array(
+                                    'text',
+                                    array(
+                                        'label'      => 'Foo',
+                                        'decorators' => array(
+                                            'ViewHelper',
+                                            'Label',
+                                        ),
+                                    ),
+                                ),
+                            ),
+                            'id'       => 'subform1',
+                            'decorators' => array(
+                                'FormElements',
+                            ),
+                        ),
+                        'name'  => 'subform1',
+                        'order' => 2,
+                    ),
+                    array(
+                        'form' => array(
+                            'elements' => array(
+                                'bar' => array(
+                                    'text',
+                                    array(
+                                        'label'      => 'Bar',
+                                        'decorators' => array(
+                                            'ViewHelper',
+                                            'Label',
+                                        ),
+                                    ),
+                                ),
+                            ),
+                            'id'       => 'subform2',
+                            'decorators' => array(
+                                'FormElements',
+                            ),
+                        ),
+                        'name'  => 'subform2',
+                        'order' => 1,
+                    ),
+                ),
+            )
+        );
+        $form->removeDecorator('HtmlTag');
+
+        // Tests
+        $subForms = $form->getSubForms();
+        $subForm1 = current($subForms);
+        $subForm2 = next($subForms);
+
+        $this->assertSame(
+            array(
+                 'subform1',
+                 'subform2',
+            ),
+            array(
+                 $subForm1->getName(),
+                 $subForm2->getName(),
+            )
+        );
+
+        $expected = '<form enctype="application/x-www-form-urlencoded" action="" method="post">'
+                  . PHP_EOL
+                  . PHP_EOL
+                  . '<label for="subform2-bar" class="optional">Bar</label>'
+                  . PHP_EOL
+                  . PHP_EOL
+                  . '<input type="text" name="subform2[bar]" id="subform2-bar" value="" />'
+                  . PHP_EOL
+                  . PHP_EOL
+                  . '<label for="subform1-foo" class="optional">Foo</label>'
+                  . PHP_EOL
+                  . PHP_EOL
+                  . '<input type="text" name="subform1[foo]" id="subform1-foo" value="" />'
+                  . '</form>';
+
+        $this->assertSame($expected, $form->render($this->getView()));
+    }
+
     /**
      * Used by test methods susceptible to ZF-2794, marks a test as incomplete
      *