Ver Fonte

ZF-9689: Zend_Form_Decorator_ViewHelper does not forward list separator argument

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24873 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan há 13 anos atrás
pai
commit
7c856539c3

+ 12 - 1
library/Zend/Form/Decorator/ViewHelper.php

@@ -243,7 +243,18 @@ class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
             $helperObject->setTranslator($element->getTranslator());
         }
 
-        $elementContent = $view->$helper($name, $value, $attribs, $element->options);
+        // Check list separator
+        if (isset($attribs['listsep'])
+            && in_array($helper, array('formMulticheckbox', 'formRadio', 'formSelect'))
+        ) {
+            $listsep = $attribs['listsep'];
+            unset($attribs['listsep']);
+
+            $elementContent = $view->$helper($name, $value, $attribs, $element->options, $listsep);
+        } else {
+            $elementContent = $view->$helper($name, $value, $attribs, $element->options);
+        }
+
         switch ($this->getPlacement()) {
             case self::APPEND:
                 return $content . $separator . $elementContent;

+ 56 - 0
tests/Zend/Form/Decorator/ViewHelperTest.php

@@ -180,6 +180,62 @@ class Zend_Form_Decorator_ViewHelperTest extends PHPUnit_Framework_TestCase
             $this->assertContains($translations[$value], $test);
         }
     }
+    
+    /**
+     * @group ZF-9689
+     */
+    public function testRenderWithListSeparatorForMulticheckbox()
+    {
+        require_once 'Zend/Form/Element/MultiCheckbox.php';
+        
+        $element = new Zend_Form_Element_MultiCheckbox('foo');
+        $options = array(
+            'foo' => 'Foo',
+            'bar' => 'Bar',
+        );
+        $element->setMultiOptions($options);
+        $element->setSeparator('</p><p>');
+        $element->setDecorators(
+            array(
+                array('ViewHelper', array('separator' => '')),
+                array('HtmlTag', array('tag' => 'p')),
+            )
+        );
+        
+        $expected = '<p><label><input type="checkbox" name="foo[]" id="foo-foo" value="foo">Foo</label></p>'
+                  . '<p><label><input type="checkbox" name="foo[]" id="foo-bar" value="bar">Bar</label></p>';
+        $actual   = $element->render($this->getView());
+        
+        $this->assertEquals($expected, $actual);
+    }
+    
+    /**
+     * @group ZF-9689
+     */
+    public function testRenderWithListSeparatorForRadio()
+    {
+        require_once 'Zend/Form/Element/Radio.php';
+        
+        $element = new Zend_Form_Element_Radio('foo');
+        $options = array(
+            'foo' => 'Foo',
+            'bar' => 'Bar',
+        );
+        $element->setMultiOptions($options);
+        $element->setSeparator('</p><p>');
+        $element->setDecorators(
+            array(
+                array('ViewHelper', array('separator' => '')),
+                array('HtmlTag', array('tag' => 'p')),
+            )
+        );
+        
+        $expected = '<p><label><input type="radio" name="foo" id="foo-foo" value="foo">Foo</label></p>'
+                  . '<p><label><input type="radio" name="foo" id="foo-bar" value="bar">Bar</label></p>';
+        $actual   = $element->render($this->getView());
+        
+        $this->assertEquals($expected, $actual);
+    }
 }
 
 class Zend_Form_Decorator_ViewHelperTest_Textarea extends Zend_Form_Element