Bladeren bron

[improvement] ZF-9913 Added fluent interface to Zend_Form_Element::loadDefaultDecorators and descendents

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22328 44c647ce-9c0f-0410-b52a-842ac1e357ba
bittarman 15 jaren geleden
bovenliggende
commit
dc35e49871

+ 2 - 1
library/Zend/Form/DisplayGroup.php

@@ -620,7 +620,7 @@ class Zend_Form_DisplayGroup implements Iterator,Countable
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -630,6 +630,7 @@ class Zend_Form_DisplayGroup implements Iterator,Countable
                  ->addDecorator('Fieldset')
                  ->addDecorator('DtDdWrapper');
         }
+        return $this;
     }
 
     /**

+ 3 - 2
library/Zend/Form/Element.php

@@ -305,12 +305,12 @@ class Zend_Form_Element implements Zend_Validate_Interface
     /**
      * Load default decorators
      *
-     * @return void
+     * @return Zend_Form_Element
      */
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -325,6 +325,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
                                                  'id'  => array('callback' => $getId)))
                  ->addDecorator('Label', array('tag' => 'dt'));
         }
+        return $this;
     }
 
     /**

+ 2 - 1
library/Zend/Form/Element/Captcha.php

@@ -258,7 +258,7 @@ class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -268,6 +268,7 @@ class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
                  ->addDecorator('HtmlTag', array('tag' => 'dd', 'id' => $this->getName() . '-element'))
                  ->addDecorator('Label', array('tag' => 'dt'));
         }
+        return $this;
     }
 
     /**

+ 2 - 1
library/Zend/Form/Element/File.php

@@ -76,7 +76,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -87,6 +87,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
                  ->addDecorator('HtmlTag', array('tag' => 'dd'))
                  ->addDecorator('Label', array('tag' => 'dt'));
         }
+        return $this;
     }
 
     /**

+ 2 - 1
library/Zend/Form/Element/Image.php

@@ -60,7 +60,7 @@ class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -71,6 +71,7 @@ class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
                  ->addDecorator('HtmlTag', array('tag' => 'dd'))
                  ->addDecorator('Label', array('tag' => 'dt'));
         }
+        return $this;
     }
 
     /**

+ 2 - 1
library/Zend/Form/Element/Radio.php

@@ -50,10 +50,11 @@ class Zend_Form_Element_Radio extends Zend_Form_Element_Multi
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
         parent::loadDefaultDecorators();
         $this->addDecorator('Label', array('tag' => 'dt',
                                            'disableFor' => true));
+        return $this;
     }
 }

+ 2 - 1
library/Zend/Form/Element/Submit.php

@@ -113,7 +113,7 @@ class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -122,5 +122,6 @@ class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
                  ->addDecorator('ViewHelper')
                  ->addDecorator('DtDdWrapper');
         }
+        return $this;
     }
 }

+ 3 - 2
library/Zend/Form/SubForm.php

@@ -41,12 +41,12 @@ class Zend_Form_SubForm extends Zend_Form
     /**
      * Load the default decorators
      *
-     * @return void
+     * @return Zend_Form_SubForm
      */
     public function loadDefaultDecorators()
     {
         if ($this->loadDefaultDecoratorsIsDisabled()) {
-            return;
+            return $this;
         }
 
         $decorators = $this->getDecorators();
@@ -56,5 +56,6 @@ class Zend_Form_SubForm extends Zend_Form
                  ->addDecorator('Fieldset')
                  ->addDecorator('DtDdWrapper');
         }
+        return $this;
     }
 }

+ 2 - 0
tests/Zend/Form/AllTests.php

@@ -31,6 +31,7 @@ require_once 'Zend/Form/DisplayGroupTest.php';
 require_once 'Zend/Form/ElementTest.php';
 require_once 'Zend/Form/Element/AllTests.php';
 require_once 'Zend/Form/FormTest.php';
+require_once 'Zend/Form/SubFormTest.php';
 
 /**
  * @category   Zend
@@ -56,6 +57,7 @@ class Zend_Form_AllTests
         $suite->addTestSuite('Zend_Form_ElementTest');
         $suite->addTest(Zend_Form_Element_AllTests::suite());
         $suite->addTestSuite('Zend_Form_FormTest');
+        $suite->addTestSuite('Zend_Form_SubFormTest');
 
         return $suite;
     }

+ 11 - 0
tests/Zend/Form/DisplayGroupTest.php

@@ -778,6 +778,17 @@ class Zend_Form_DisplayGroupTest extends PHPUnit_Framework_TestCase
             $this->markTestIncomplete('Error occurs for PHP 5.1.4 on Windows');
         }
     }
+
+    /**
+     * Prove the fluent interface on Zend_Form::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->group, $this->group->loadDefaultDecorators());
+    }
 }
 
 class Zend_Form_DisplayGroupTest_DisplayGroup extends Zend_Form_DisplayGroup

+ 11 - 0
tests/Zend/Form/Element/CaptchaTest.php

@@ -163,6 +163,17 @@ class Zend_Form_Element_CaptchaTest extends PHPUnit_Framework_TestCase
         require_once 'Zend/View.php';
         $this->assertFalse(array_key_exists('helper', $this->element->getAttribs()));
     }
+
+    /**
+     * Prove the fluent interface on Zend_Form_Element_Captcha::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->element, $this->element->loadDefaultDecorators());
+    }
 }
 
 /**

+ 12 - 0
tests/Zend/Form/Element/FileTest.php

@@ -481,6 +481,18 @@ class Zend_Form_Element_FileTest extends PHPUnit_Framework_TestCase
     {
         $this->_errorOccurred = true;
     }
+
+
+    /**
+     * Prove the fluent interface on Zend_Form_Element_File::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->element, $this->element->loadDefaultDecorators());
+    }
 }
 
 class Zend_Form_Element_FileTest_MockAdapter extends Zend_File_Transfer_Adapter_Abstract

+ 11 - 0
tests/Zend/Form/Element/ImageTest.php

@@ -205,6 +205,17 @@ class Zend_Form_Element_ImageTest extends PHPUnit_Framework_TestCase
             $this->markTestIncomplete('Error occurs for PHP 5.1.4 on Windows');
         }
     }
+
+    /**
+     * Prove the fluent interface on Zend_Form_Element_Image::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->element, $this->element->loadDefaultDecorators());
+    }
 }
 
 // Call Zend_Form_Element_ImageTest::main() if this source file is executed directly.

+ 11 - 0
tests/Zend/Form/Element/RadioTest.php

@@ -212,6 +212,17 @@ class Zend_Form_Element_RadioTest extends PHPUnit_Framework_TestCase
             $this->markTestIncomplete('Error occurs for PHP 5.1.4 on Windows');
         }
     }
+
+    /**
+     * Prove the fluent interface on Zend_Form_Element_Radio::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->element, $this->element->loadDefaultDecorators());
+    }
 }
 
 // Call Zend_Form_Element_RadioTest::main() if this source file is executed directly.

+ 11 - 0
tests/Zend/Form/Element/SubmitTest.php

@@ -248,6 +248,17 @@ class Zend_Form_Element_SubmitTest extends PHPUnit_Framework_TestCase
             $this->markTestIncomplete('Error occurs for PHP 5.1.4 on Windows');
         }
     }
+    
+    /**
+     * Prove the fluent interface on Zend_Form_Element_Submit::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->element, $this->element->loadDefaultDecorators());
+    }
 }
 
 // Call Zend_Form_Element_SubmitTest::main() if this source file is executed directly.

+ 14 - 1
tests/Zend/Form/ElementTest.php

@@ -2133,7 +2133,19 @@ class Zend_Form_ElementTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($this->element->isValid(123));
         $messages = $this->element->getMessages();
         $this->assertEquals('Direct validator message', $messages['alphaInvalid']);
-    }    
+    }
+
+    /**
+     * Prove the fluent interface on Zend_Form::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->element, $this->element->loadDefaultDecorators());
+    }
+
 }
 
 class Zend_Form_ElementTest_Decorator extends Zend_Form_Decorator_Abstract
@@ -2195,6 +2207,7 @@ class Zend_Form_ElementTest_ArrayFilter implements Zend_Filter_Interface
         $validator = $username->getValidator('regex');
         $this->assertTrue($validator->zfBreakChainOnFailure);
     }
+    
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Form_ElementTest::main') {

+ 11 - 0
tests/Zend/Form/FormTest.php

@@ -4321,6 +4321,17 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase
             $this->markTestIncomplete('Error occurs for PHP 5.1.4 on Windows');
         }
     }
+
+    /**
+     * Prove the fluent interface on Zend_Form::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->form, $this->form->loadDefaultDecorators());
+    }
 }
 
 class Zend_Form_FormTest_DisplayGroup extends Zend_Form_DisplayGroup

+ 14 - 1
tests/Zend/Form/SubFormTest.php

@@ -32,6 +32,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
 
 require_once 'Zend/Form/SubForm.php';
 require_once 'Zend/View.php';
+require_once 'Zend/Version.php';
 
 /**
  * @category   Zend
@@ -120,6 +121,7 @@ class Zend_Form_SubFormTest extends PHPUnit_Framework_TestCase
      */
     public function testRenderedSubFormDtShouldContainNoBreakSpace()
     {
+        $this->assertSame('1.11.0dev',Zend_Version::VERSION);
         $subForm = new Zend_Form_SubForm(array(
             'elements' => array(
                 'foo' => 'text',
@@ -130,7 +132,18 @@ class Zend_Form_SubFormTest extends PHPUnit_Framework_TestCase
         $form->addSubForm($subForm, 'foobar')
              ->setView(new Zend_View);
         $html = $form->render();
-        $this->assertContains('<dt>&#160;</dt>', $html);
+        $this->assertContains('>&#160;</dt>', $html  );
+    }
+
+    /**
+     * Prove the fluent interface on Zend_Form_Subform::loadDefaultDecorators
+     *
+     * @link http://framework.zend.com/issues/browse/ZF-9913
+     * @return void
+     */
+    public function testFluentInterfaceOnLoadDefaultDecorators()
+    {
+        $this->assertSame($this->form, $this->form->loadDefaultDecorators());
     }
 }