Changeset 5936


Ignore:
Timestamp:
01/14/12 19:51:31 (4 months ago)
Author:
vain
Message:
  • added chaining to setter + test
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/viewhelper/form/form.php

    r5934 r5936  
    638638     * Shortcut to set the Legend text of the fieldset decorator. 
    639639     * 
    640      * The legend belongs to the fieldset decorator. 
     640     * The legend tag belongs to the fieldset decorator. 
    641641     * The fieldset decorator is a default decorator instantiated, when rendering the form. 
    642642     * It does not exist at the time of form definition. 
    643      * So we keep the legend value till the fieldset decorator is instantiated. 
    644      * Then the decorator attributes array is automatically set applied to the form and it's objects. 
    645      * 
    646      * Note: you can use the long form anytime, when defining your form. 
    647      * 
    648      * @param string String for the legend of the fieldset. 
     643     * So we keep the legend value stored, till the fieldset decorator is instantiated. 
     644     * Then the decorator attributes array is automatically assigned to the form and it's objects. 
     645     * 
     646     * Note: you can use the long form (array notation) anytime, when defining your form. 
     647     * Though using method chaining is a bit nicer (fluent interface). 
     648     * 
     649     * @param string String for the legend tag of the fieldset. 
     650     * 
     651     * @return object Clansuite_Form 
    649652     */ 
    650653    public function setLegend($legend) 
    651654    { 
    652655        $this->setDecoratorAttributesArray(array('form' => array('fieldset' => array('legend' => $legend)))); 
     656 
     657        return $this; 
    653658    } 
    654659 
  • trunk/tests/unittests/core/viewhelper/form/form.core.php

    r5927 r5936  
    11<?php 
     2/** 
     3 * @todo method chaining tests on all setter methods 
     4 */ 
    25class Clansuite_Form_Test extends Clansuite_UnitTestCase 
    36{ 
     
    710    protected $form; 
    811 
    9     public function markTestIncomplete($msg) 
    10     { 
    11         $this->assertTrue(false, $msg); 
    12     } 
    13  
    1412    /** 
    1513     * Sets up the fixture, for example, opens a network connection. 
     
    7068        # set external url 
    7169        $this->form->setAction('index.php?mod=news&action=show'); 
    72         $this->assertEqual( WWW_ROOT . 'index.php?mod=index.php%3Fmod%3Dnews%26action%3Dshow', $this->form->getAction()); 
     70        $this->assertEqual( WWW_ROOT . 'index.php?mod%3Dnews%26action%3Dshow', $this->form->getAction()); 
    7371    } 
    7472 
     
    7876 
    7977        # via getter - qualified url 
    80         $this->assertEqual( WWW_ROOT . 'index.php?mod=index.php%3Fmod%3Dnews%26action%3Dshow', $this->form->getAction()); 
     78        $this->assertEqual( WWW_ROOT . 'index.php?mod%3Dnews%26action%3Dshow', $this->form->getAction()); 
    8179    } 
    8280 
     
    294292        # via getter - returns string 
    295293        $this->assertEqual('legend-set', $this->form->getLegend()); 
     294 
     295        # allows method chaining 
     296        $this->assertEqual($this->form, $this->form->setLegend('returns form object')); 
     297    } 
     298 
     299    public function testSetLegend_allowsMethodChaining() 
     300    { 
     301        $return_value = $this->form->setLegend('returns form object'); 
     302 
     303        $this->assertIdentical($this->form, $return_value); 
    296304    } 
    297305 
Note: See TracChangeset for help on using the changeset viewer.