Просмотр исходного кода

Fix ZF-6061: Zend_View_Helper_FormSubmit with viewscript decorator produces invalid (x)html code. Patch by Frank Brückner.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24824 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob 13 лет назад
Родитель
Сommit
3a8a2cc540

+ 1 - 0
library/Zend/Form/Element.php

@@ -904,6 +904,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
     public function getAttribs()
     {
         $attribs = get_object_vars($this);
+        unset($attribs['helper']);
         foreach ($attribs as $key => $value) {
             if ('_' == substr($key, 0, 1)) {
                 unset($attribs[$key]);

+ 0 - 18
library/Zend/Form/Element/Captcha.php

@@ -127,24 +127,6 @@ class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
     }
 
     /**
-     * Return all attributes
-     *
-     * @return array
-     */
-    public function getAttribs()
-    {
-        $attribs = get_object_vars($this);
-        unset($attribs['helper']);
-        foreach ($attribs as $key => $value) {
-            if ('_' == substr($key, 0, 1)) {
-                unset($attribs[$key]);
-            }
-        }
-
-        return $attribs;
-    }
-
-    /**
      * Set options
      *
      * Overrides to allow passing captcha options

+ 15 - 0
tests/Zend/Form/Decorator/ViewScriptTest.php

@@ -222,6 +222,21 @@ class Zend_Form_Decorator_ViewScriptTest extends PHPUnit_Framework_TestCase
         $this->assertContains('This text prefixes the content', $test);
         $this->assertContains('This text appends the content', $test);
     }
+
+    /**
+     * @group ZF-6061
+     */
+    public function testRenderingWithoutHelperInAttribs()
+    {
+        $this->decorator->setViewScript('withouthelperinattribs.phtml')
+            ->setElement($this->getElement());
+
+        $expected = 'Foo:'
+                  . "\n"
+                  . '<input type="text" name="foo" id="foo" value="">';
+
+        $this->assertSame($expected, $this->decorator->render('Foo:'));
+    }
 }
 
 // Call Zend_Form_Decorator_ViewScriptTest::main() if this source file is executed directly.

+ 15 - 2
tests/Zend/Form/ElementTest.php

@@ -458,12 +458,25 @@ class Zend_Form_ElementTest extends PHPUnit_Framework_TestCase
         );
         $this->element->setAttribs($attribs);
 
-        $attribs['helper'] = 'formText';
-
         $received = $this->element->getAttribs();
         $this->assertEquals($attribs, $received);
     }
 
+    /**
+     * @group ZF-6061
+     */
+    public function testHelperDoesNotShowUpInAttribs()
+    {
+        $attribs = array(
+            'foo' => 'bar',
+            'bar' => 'baz',
+            'baz' => 'bat'
+        );
+        $this->element->setAttribs($attribs);
+
+        $this->assertFalse(array_key_exists('helper', $this->element->getAttribs()));
+    }
+
     public function testPassingNullValuesToSetAttribsUnsetsAttribs()
     {
         $this->testSetAttribsSetsMultipleAttribs();

+ 7 - 0
tests/Zend/Form/_files/views/withouthelperinattribs.phtml

@@ -0,0 +1,7 @@
+<?php
+
+echo $this->{$this->element->helper}(
+    $this->element->getName(),
+    null,
+    $this->element->getAttribs()
+);