Przeglądaj źródła

Merge r25188 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25189 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch 13 lat temu
rodzic
commit
05d93125a3

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

@@ -196,7 +196,8 @@ class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
             if ($element instanceof $type) {
                 if (stristr($type, 'button')) {
                     $element->content = $element->getLabel();
-                    return null;
+
+                    return $element->getValue();
                 }
                 return $element->getLabel();
             }

+ 14 - 0
library/Zend/Form/Element/Button.php

@@ -39,4 +39,18 @@ class Zend_Form_Element_Button extends Zend_Form_Element_Submit
      * @var string
      */
     public $helper = 'formButton';
+
+    /**
+     * Validate element value (pseudo)
+     *
+     * There is no need to reset the value
+     *
+     * @param  mixed $value Is always ignored
+     * @param  mixed $context Is always ignored
+     * @return boolean Returns always TRUE
+     */
+    public function isValid($value, $context = null)
+    {
+        return true;
+    }
 }

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

@@ -236,6 +236,54 @@ class Zend_Form_Decorator_ViewHelperTest extends PHPUnit_Framework_TestCase
         
         $this->assertEquals($expected, $actual);
     }
+
+    /**
+     * @group ZF-5056
+     */
+    public function testRenderingButtonWithValue()
+    {
+        // Create element
+        require_once 'Zend/Form/Element/Button.php';
+
+        $element = new Zend_Form_Element_Button('foo');
+        $element->setValue('bar');
+        $element->setLabel('baz');
+        $element->setDecorators(
+            array(
+                 'ViewHelper',
+            )
+        );
+
+        // Test
+        $this->assertEquals(
+            PHP_EOL
+                . '<button name="foo" id="foo" type="button" value="bar">baz</button>',
+            $element->render($this->getView())
+        );
+    }
+
+    /**
+     * @group ZF-5056
+     */
+    public function testRenderingButtonAsTypeSubmit()
+    {
+        // Create element
+        require_once 'Zend/Form/Element/Button.php';
+
+        $element = new Zend_Form_Element_Button('foo');
+        $element->setAttrib('type', 'submit');
+        $element->setDecorators(
+            array(
+                 'ViewHelper',
+            )
+        );
+
+        // Test
+        $this->assertEquals(
+            PHP_EOL . '<button name="foo" id="foo" type="submit">foo</button>',
+            $element->render($this->getView())
+        );
+    }
 }
 
 class Zend_Form_Decorator_ViewHelperTest_Textarea extends Zend_Form_Element

+ 40 - 0
tests/Zend/Form/Element/ButtonTest.php

@@ -41,6 +41,11 @@ require_once 'Zend/Translate.php';
 class Zend_Form_Element_ButtonTest extends PHPUnit_Framework_TestCase
 {
     /**
+     * @var Zend_Form_Element_Button
+     */
+    protected $element;
+
+    /**
      * Runs the test methods of this class.
      *
      * @return void
@@ -151,6 +156,41 @@ class Zend_Form_Element_ButtonTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * @group ZF-5056
+     */
+    public function testValidateAlwaysReturnsTrue()
+    {
+        $this->element->setValue('foo');
+
+        $this->assertTrue($this->element->isValid('bar'));
+    }
+
+    /**
+     * @group ZF-5056
+     */
+    public function testRenderingWithValueAfterValidation()
+    {
+        // Set element options
+        $this->element->setOptions(
+            array(
+                 'label'      => 'Foo',
+                 'value'      => 'bar',
+                 'decorators' => array(
+                     'ViewHelper',
+                 ),
+            )
+        );
+
+        // Validate
+        $this->element->isValid(null);
+
+        $this->assertEquals(
+            PHP_EOL . '<button name="foo" id="foo" type="button" value="bar">Foo</button>',
+            $this->element->render($this->getView())
+        );
+    }
+
+    /**
      * Used by test methods susceptible to ZF-2794, marks a test as incomplete
      *
      * @link   http://framework.zend.com/issues/browse/ZF-2794