Explorar o código

ZF-7660: "required" attribute value should always be rendered as string

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19107 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew %!s(int64=16) %!d(string=hai) anos
pai
achega
2637c7487c

+ 3 - 0
library/Zend/Dojo/View/Helper/Dijit.php

@@ -260,6 +260,9 @@ abstract class Zend_Dojo_View_Helper_Dijit extends Zend_View_Helper_HtmlElement
         $dijit = (null === $dijit) ? $this->_dijit : $dijit;
         if ($this->_useDeclarative()) {
             $attribs = array_merge($attribs, $params);
+            if (isset($attribs['required'])) {
+                $attribs['required'] = ($attribs['required']) ? 'true' : 'false';
+            }
             $attribs['dojoType'] = $dijit;
         } elseif (!$this->_useProgrammaticNoScript()) {
             $this->_createDijit($dijit, $attribs['id'], $params);

+ 26 - 0
tests/Zend/Dojo/View/Helper/ValidationTextBoxTest.php

@@ -129,6 +129,32 @@ class Zend_Dojo_View_Helper_ValidationTextBoxTest extends PHPUnit_Framework_Test
         $html = $this->getElement();
         $this->assertRegexp('/<input[^>]*(type="text")/', $html);
     }
+
+    /**
+     * @group ZF-7660
+     */
+    public function testTrueRequiredParameterShouldBeRenderedAsStringValue()
+    {
+        $html = $this->getElement();
+        $this->assertContains('required="true"', $html);
+    }
+
+    /**
+     * @group ZF-7660
+     */
+    public function testFalseRequiredParameterShouldBeRenderedAsStringValue()
+    {
+        $html = $this->helper->validationTextBox(
+            'elementId',
+            '2008-07-07',
+            array(
+                'required'    => false,
+                'regExp'      => '[\w]+',
+            ),
+            array()
+        );
+        $this->assertContains('required="false"', $html);
+    }
 }
 
 // Call Zend_Dojo_View_Helper_ValidationTextBoxTest::main() if this source file is executed directly.