Changeset 970

Show
Ignore:
Timestamp:
05/31/08 15:12:08 (6 months ago)
Author:
laurentj
Message:

jforms: made tests for <group> and created the jformscontrol object for <choice>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r926 r970  
    147147    public function check(){ 
    148148        $this->container->errors = array(); 
    149         foreach($this->controls as $name=>$ctrl){ 
     149        foreach($this->rootControls as $name=>$ctrl){ 
    150150            if($this->container->isActivated($name)) 
    151151                $ctrl->check(); 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r926 r970  
    147147    public function check(){ 
    148148        $this->container->errors = array(); 
    149         foreach($this->controls as $name=>$ctrl){ 
     149        foreach($this->rootControls as $name=>$ctrl){ 
    150150            if($this->container->isActivated($name)) 
    151151                $ctrl->check(); 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r926 r970  
    147147    public function check(){ 
    148148        $this->container->errors = array(); 
    149         foreach($this->controls as $name=>$ctrl){ 
     149        foreach($this->rootControls as $name=>$ctrl){ 
    150150            if($this->container->isActivated($name)) 
    151151                $ctrl->check(); 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r926 r970  
    147147    public function check(){ 
    148148        $this->container->errors = array(); 
    149         foreach($this->controls as $name=>$ctrl){ 
     149        foreach($this->rootControls as $name=>$ctrl){ 
    150150            if($this->container->isActivated($name)) 
    151151                $ctrl->check(); 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r926 r970  
    527527    public $type = 'groups'; 
    528528 
     529    /** 
     530     * all child controls of the group 
     531     */ 
    529532    protected $childControls = array(); 
    530533 
    531534    function check(){ 
    532         $v = parent::check()
     535        $rv = null
    533536        foreach($this->childControls as $ctrl) { 
    534             $ctrl->check($this); 
    535         } 
    536         return $v; 
     537            if(($rv2 = $ctrl->check())!==null) { 
     538                $rv = $rv2; 
     539            } 
     540        } 
     541        return $rv; 
    537542    } 
    538543 
     
    572577 
    573578/** 
    574  * choice 
     579 * group 
    575580 * @package     jelix 
    576581 * @subpackage  forms 
     
    580585} 
    581586 
     587 
    582588/** 
    583589 * choice 
     
    589595    public $type="choice"; 
    590596 
     597    /** 
     598     * list of item. Each value is an array which contains corresponding controls of the item 
     599     * an item could not have controls, in this case its value is an empty array 
     600     */ 
    591601    public $items = array(); 
    592602 
    593     function addChildControl($control, $itemName = '') { 
     603    public $itemsNames = array(); 
     604 
     605    function check(){ 
     606        if(isset($this->items[$this->container->data[$this->ref]])) { 
     607            $rv = null; 
     608            foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 
     609                if (($rv2 = $ctrl->check()) !== null) { 
     610                    $rv = $rv2; 
     611                } 
     612            } 
     613            return $rv; 
     614        } else { 
     615            return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 
     616        } 
     617    } 
     618 
     619    function createItem($value, $label) { 
     620        $this->items[$value] = array(); 
     621        $this->itemsNames[$value]= $label; 
     622    } 
     623 
     624    function addChildControl($control, $itemValue = '') { 
    594625        $this->childControls[$control->ref]=$control; 
    595         $this->items[$itemName][$control->ref] = $control; 
    596     } 
     626        $this->items[$itemValue][$control->ref] = $control; 
     627    } 
     628 
    597629 
    598630    function setData($value) { 
    599631        parent::setData($value); 
     632        // we deactivate controls which are not selected 
    600633        foreach($this->items as $item => $list) { 
    601634            $ro = ($item != $value); 
     
    608641    function setValueFromRequest($request) { 
    609642        $this->setData($request->getParam($this->ref,'')); 
    610         foreach($this->childControls as $name=>$ctrl)
    611             if(!$this->container->isActivated($name) || $this->container->isReadOnly($name)) 
    612                 continue
    613             $ctrl->setValueFromRequest($request); 
    614         } 
    615     } 
    616 } 
    617  
    618 /** 
    619  * choice 
     643        if(isset($this->items[$this->container->data[$this->ref]]))
     644            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     645                $ctrl->setValueFromRequest($request)
     646            } 
     647        } 
     648    } 
     649} 
     650 
     651/** 
     652 * switch 
    620653 * @package     jelix 
    621654 * @subpackage  forms 
     
    623656class jFormsControlSwitch extends jFormsControlChoice { 
    624657    public $type="switch"; 
    625 
    626  
    627 /** 
    628  * choice 
    629  * @package     jelix 
    630  * @subpackage  forms 
    631  */ 
     658 
     659 
     660    function setValueFromRequest($request) { 
     661        //$this->setData($request->getParam($this->ref,'')); 
     662        if(isset($this->items[$this->container->data[$this->ref]])){ 
     663            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     664                $ctrl->setValueFromRequest($request); 
     665            } 
     666        } 
     667    } 
     668
     669 
     670/* 
     671 * repeat 
     672 * @package     jelix 
     673 * @subpackage  forms 
     674 */ 
     675/* 
    632676class jFormsControlRepeat extends jFormsControlGroups { 
    633677    public $type="repeat"; 
    634 } 
    635  
     678}*/ 
     679 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r926 r970  
    527527    public $type = 'groups'; 
    528528 
     529    /** 
     530     * all child controls of the group 
     531     */ 
    529532    protected $childControls = array(); 
    530533 
    531534    function check(){ 
    532         $v = parent::check()
     535        $rv = null
    533536        foreach($this->childControls as $ctrl) { 
    534             $ctrl->check($this); 
    535         } 
    536         return $v; 
     537            if(($rv2 = $ctrl->check())!==null) { 
     538                $rv = $rv2; 
     539            } 
     540        } 
     541        return $rv; 
    537542    } 
    538543 
     
    572577 
    573578/** 
    574  * choice 
     579 * group 
    575580 * @package     jelix 
    576581 * @subpackage  forms 
     
    580585} 
    581586 
     587 
    582588/** 
    583589 * choice 
     
    589595    public $type="choice"; 
    590596 
     597    /** 
     598     * list of item. Each value is an array which contains corresponding controls of the item 
     599     * an item could not have controls, in this case its value is an empty array 
     600     */ 
    591601    public $items = array(); 
    592602 
    593     function addChildControl($control, $itemName = '') { 
     603    public $itemsNames = array(); 
     604 
     605    function check(){ 
     606        if(isset($this->items[$this->container->data[$this->ref]])) { 
     607            $rv = null; 
     608            foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 
     609                if (($rv2 = $ctrl->check()) !== null) { 
     610                    $rv = $rv2; 
     611                } 
     612            } 
     613            return $rv; 
     614        } else { 
     615            return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 
     616        } 
     617    } 
     618 
     619    function createItem($value, $label) { 
     620        $this->items[$value] = array(); 
     621        $this->itemsNames[$value]= $label; 
     622    } 
     623 
     624    function addChildControl($control, $itemValue = '') { 
    594625        $this->childControls[$control->ref]=$control; 
    595         $this->items[$itemName][$control->ref] = $control; 
    596     } 
     626        $this->items[$itemValue][$control->ref] = $control; 
     627    } 
     628 
    597629 
    598630    function setData($value) { 
    599631        parent::setData($value); 
     632        // we deactivate controls which are not selected 
    600633        foreach($this->items as $item => $list) { 
    601634            $ro = ($item != $value); 
     
    608641    function setValueFromRequest($request) { 
    609642        $this->setData($request->getParam($this->ref,'')); 
    610         foreach($this->childControls as $name=>$ctrl)
    611             if(!$this->container->isActivated($name) || $this->container->isReadOnly($name)) 
    612                 continue
    613             $ctrl->setValueFromRequest($request); 
    614         } 
    615     } 
    616 } 
    617  
    618 /** 
    619  * choice 
     643        if(isset($this->items[$this->container->data[$this->ref]]))
     644            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     645                $ctrl->setValueFromRequest($request)
     646            } 
     647        } 
     648    } 
     649} 
     650 
     651/** 
     652 * switch 
    620653 * @package     jelix 
    621654 * @subpackage  forms 
     
    623656class jFormsControlSwitch extends jFormsControlChoice { 
    624657    public $type="switch"; 
    625 
    626  
    627 /** 
    628  * choice 
    629  * @package     jelix 
    630  * @subpackage  forms 
    631  */ 
     658 
     659 
     660    function setValueFromRequest($request) { 
     661        //$this->setData($request->getParam($this->ref,'')); 
     662        if(isset($this->items[$this->container->data[$this->ref]])){ 
     663            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     664                $ctrl->setValueFromRequest($request); 
     665            } 
     666        } 
     667    } 
     668
     669 
     670/* 
     671 * repeat 
     672 * @package     jelix 
     673 * @subpackage  forms 
     674 */ 
     675/* 
    632676class jFormsControlRepeat extends jFormsControlGroups { 
    633677    public $type="repeat"; 
    634 } 
    635  
     678}*/ 
     679 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r926 r970  
    527527    public $type = 'groups'; 
    528528 
     529    /** 
     530     * all child controls of the group 
     531     */ 
    529532    protected $childControls = array(); 
    530533 
    531534    function check(){ 
    532         $v = parent::check()
     535        $rv = null
    533536        foreach($this->childControls as $ctrl) { 
    534             $ctrl->check($this); 
    535         } 
    536         return $v; 
     537            if(($rv2 = $ctrl->check())!==null) { 
     538                $rv = $rv2; 
     539            } 
     540        } 
     541        return $rv; 
    537542    } 
    538543 
     
    572577 
    573578/** 
    574  * choice 
     579 * group 
    575580 * @package     jelix 
    576581 * @subpackage  forms 
     
    580585} 
    581586 
     587 
    582588/** 
    583589 * choice 
     
    589595    public $type="choice"; 
    590596 
     597    /** 
     598     * list of item. Each value is an array which contains corresponding controls of the item 
     599     * an item could not have controls, in this case its value is an empty array 
     600     */ 
    591601    public $items = array(); 
    592602 
    593     function addChildControl($control, $itemName = '') { 
     603    public $itemsNames = array(); 
     604 
     605    function check(){ 
     606        if(isset($this->items[$this->container->data[$this->ref]])) { 
     607            $rv = null; 
     608            foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 
     609                if (($rv2 = $ctrl->check()) !== null) { 
     610                    $rv = $rv2; 
     611                } 
     612            } 
     613            return $rv; 
     614        } else { 
     615            return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 
     616        } 
     617    } 
     618 
     619    function createItem($value, $label) { 
     620        $this->items[$value] = array(); 
     621        $this->itemsNames[$value]= $label; 
     622    } 
     623 
     624    function addChildControl($control, $itemValue = '') { 
    594625        $this->childControls[$control->ref]=$control; 
    595         $this->items[$itemName][$control->ref] = $control; 
    596     } 
     626        $this->items[$itemValue][$control->ref] = $control; 
     627    } 
     628 
    597629 
    598630    function setData($value) { 
    599631        parent::setData($value); 
     632        // we deactivate controls which are not selected 
    600633        foreach($this->items as $item => $list) { 
    601634            $ro = ($item != $value); 
     
    608641    function setValueFromRequest($request) { 
    609642        $this->setData($request->getParam($this->ref,'')); 
    610         foreach($this->childControls as $name=>$ctrl)
    611             if(!$this->container->isActivated($name) || $this->container->isReadOnly($name)) 
    612                 continue
    613             $ctrl->setValueFromRequest($request); 
    614         } 
    615     } 
    616 } 
    617  
    618 /** 
    619  * choice 
     643        if(isset($this->items[$this->container->data[$this->ref]]))
     644            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     645                $ctrl->setValueFromRequest($request)
     646            } 
     647        } 
     648    } 
     649} 
     650 
     651/** 
     652 * switch 
    620653 * @package     jelix 
    621654 * @subpackage  forms 
     
    623656class jFormsControlSwitch extends jFormsControlChoice { 
    624657    public $type="switch"; 
    625 
    626  
    627 /** 
    628  * choice 
    629  * @package     jelix 
    630  * @subpackage  forms 
    631  */ 
     658 
     659 
     660    function setValueFromRequest($request) { 
     661        //$this->setData($request->getParam($this->ref,'')); 
     662        if(isset($this->items[$this->container->data[$this->ref]])){ 
     663            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     664                $ctrl->setValueFromRequest($request); 
     665            } 
     666        } 
     667    } 
     668
     669 
     670/* 
     671 * repeat 
     672 * @package     jelix 
     673 * @subpackage  forms 
     674 */ 
     675/* 
    632676class jFormsControlRepeat extends jFormsControlGroups { 
    633677    public $type="repeat"; 
    634 } 
    635  
     678}*/ 
     679 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r926 r970  
    527527    public $type = 'groups'; 
    528528 
     529    /** 
     530     * all child controls of the group 
     531     */ 
    529532    protected $childControls = array(); 
    530533 
    531534    function check(){ 
    532         $v = parent::check()
     535        $rv = null
    533536        foreach($this->childControls as $ctrl) { 
    534             $ctrl->check($this); 
    535         } 
    536         return $v; 
     537            if(($rv2 = $ctrl->check())!==null) { 
     538                $rv = $rv2; 
     539            } 
     540        } 
     541        return $rv; 
    537542    } 
    538543 
     
    572577 
    573578/** 
    574  * choice 
     579 * group 
    575580 * @package     jelix 
    576581 * @subpackage  forms 
     
    580585} 
    581586 
     587 
    582588/** 
    583589 * choice 
     
    589595    public $type="choice"; 
    590596 
     597    /** 
     598     * list of item. Each value is an array which contains corresponding controls of the item 
     599     * an item could not have controls, in this case its value is an empty array 
     600     */ 
    591601    public $items = array(); 
    592602 
    593     function addChildControl($control, $itemName = '') { 
     603    public $itemsNames = array(); 
     604 
     605    function check(){ 
     606        if(isset($this->items[$this->container->data[$this->ref]])) { 
     607            $rv = null; 
     608            foreach($this->items[$this->container->data[$this->ref]] as $ctrl) { 
     609                if (($rv2 = $ctrl->check()) !== null) { 
     610                    $rv = $rv2; 
     611                } 
     612            } 
     613            return $rv; 
     614        } else { 
     615            return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; 
     616        } 
     617    } 
     618 
     619    function createItem($value, $label) { 
     620        $this->items[$value] = array(); 
     621        $this->itemsNames[$value]= $label; 
     622    } 
     623 
     624    function addChildControl($control, $itemValue = '') { 
    594625        $this->childControls[$control->ref]=$control; 
    595         $this->items[$itemName][$control->ref] = $control; 
    596     } 
     626        $this->items[$itemValue][$control->ref] = $control; 
     627    } 
     628 
    597629 
    598630    function setData($value) { 
    599631        parent::setData($value); 
     632        // we deactivate controls which are not selected 
    600633        foreach($this->items as $item => $list) { 
    601634            $ro = ($item != $value); 
     
    608641    function setValueFromRequest($request) { 
    609642        $this->setData($request->getParam($this->ref,'')); 
    610         foreach($this->childControls as $name=>$ctrl)
    611             if(!$this->container->isActivated($name) || $this->container->isReadOnly($name)) 
    612                 continue
    613             $ctrl->setValueFromRequest($request); 
    614         } 
    615     } 
    616 } 
    617  
    618 /** 
    619  * choice 
     643        if(isset($this->items[$this->container->data[$this->ref]]))
     644            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     645                $ctrl->setValueFromRequest($request)
     646            } 
     647        } 
     648    } 
     649} 
     650 
     651/** 
     652 * switch 
    620653 * @package     jelix 
    621654 * @subpackage  forms 
     
    623656class jFormsControlSwitch extends jFormsControlChoice { 
    624657    public $type="switch"; 
    625 
    626  
    627 /** 
    628  * choice 
    629  * @package     jelix 
    630  * @subpackage  forms 
    631  */ 
     658 
     659 
     660    function setValueFromRequest($request) { 
     661        //$this->setData($request->getParam($this->ref,'')); 
     662        if(isset($this->items[$this->container->data[$this->ref]])){ 
     663            foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) { 
     664                $ctrl->setValueFromRequest($request); 
     665            } 
     666        } 
     667    } 
     668
     669 
     670/* 
     671 * repeat 
     672 * @package     jelix 
     673 * @subpackage  forms 
     674 */ 
     675/* 
    632676class jFormsControlRepeat extends jFormsControlGroups { 
    633677    public $type="repeat"; 
    634 } 
    635  
     678}*/ 
     679 
  • branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r914 r970  
    2929    protected $form; 
    3030    protected $container; 
    31     function testStart() { 
     31    function setUp() { 
    3232        $this->container = new jFormsDataContainer('',''); 
    3333        $this->form = new testCDForm('foo',$this->container); 
     
    124124        $ctrl->required = false; 
    125125        $this->form->addCtrl($ctrl); 
    126          
     126 
    127127        $this->form->setData('nom',null); 
    128128        $this->assertTrue($this->form->check()); 
     
    137137        $ctrl2->primarySecret = 'nom'; 
    138138        $this->form->addCtrl($ctrl2, false); 
    139          
     139 
    140140        $this->form->setData('nom_confirm',''); 
    141141        $this->assertTrue($this->form->check()); 
    142          
     142 
    143143        $this->form->setData('nom','aaa'); 
    144144        $this->assertFalse($this->form->check()); 
     
    181181        $this->assertTrue($this->form->check()); 
    182182    } 
     183 
     184    function testGroup() { 
     185        $group = new jFormsControlGroup('group'); 
     186 
     187        $ctrl = new jFormsControlInput('nom'); 
     188        $ctrl->required = false; 
     189        $group->addChildControl($ctrl); 
     190 
     191        $ctrl = new jFormsControlCheckboxes('categories'); 
     192        $ctrl->required = true; 
     193        $group->addChildControl($ctrl); 
     194        $this->form->addCtrl($group); 
     195 
     196        $this->assertFalse($this->form->check()); 
     197 
     198        $this->form->setData('categories',array('toto','titi')); 
     199        $this->assertTrue($this->form->check()); 
     200 
     201        $this->form->setData('nom', 'foo'); 
     202        $this->assertTrue($this->form->check()); 
     203 
     204    } 
     205 
     206 
     207    function testChoice() { 
     208        $choice = new jFormsControlChoice('choice'); 
     209        $choice->required = false; 
     210 
     211        $choice->createItem('item1','labelitem1'); 
     212        $choice->createItem('item2','labelitem2'); 
     213        $choice->createItem('item3','labelitem3'); 
     214 
     215        $ctrl = new jFormsControlInput('nom'); 
     216        $ctrl->required = false; 
     217        $choice->addChildControl($ctrl, 'item1'); 
     218 
     219        $ctrl = new jFormsControlCheckboxes('categories'); 
     220        $ctrl->required = true; 
     221        $choice->addChildControl($ctrl, 'item1'); 
     222 
     223        $ctrl = new jFormsControlinput('datenaissance'); 
     224        $ctrl->datatype= new jDatatypelocaledate(); 
     225        $choice->addChildControl($ctrl, 'item2'); 
     226 
     227        $this->form->addCtrl($choice); 
     228 
     229        $this->assertFalse($this->form->check()); 
     230 
     231        $this->form->setData('choice', 'foo'); 
     232        $this->assertFalse($this->form->check()); 
     233 
     234        $this->form->setData('choice', 'item3'); 
     235        $this->assertTrue($this->form->check()); 
     236 
     237        $this->form->setData('choice', 'item1'); 
     238        $this->assertFalse($this->form->check()); 
     239 
     240        $this->form->setData('categories','toto'); 
     241        $this->assertFalse($this->form->check()); 
     242 
     243        $this->form->setData('categories',array('toto')); 
     244        $this->assertTrue($this->form->check()); 
     245 
     246        $this->form->setData('categories',array('toto','titi')); 
     247        $this->assertTrue($this->form->check()); 
     248 
     249        $this->form->setData('choice', 'item2'); 
     250        $this->assertTrue($this->form->check()); 
     251 
     252        $this->form->setData('categories',''); 
     253        $this->assertTrue($this->form->check()); 
     254 
     255    } 
    183256} 
    184257 
  • branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r914 r970  
    2929    protected $form; 
    3030    protected $container; 
    31     function testStart() { 
     31    function setUp() { 
    3232        $this->container = new jFormsDataContainer('',''); 
    3333        $this->form = new testCDForm('foo',$this->container); 
     
    124124        $ctrl->required = false; 
    125125        $this->form->addCtrl($ctrl); 
    126          
     126 
    127127        $this->form->setData('nom',null); 
    128128        $this->assertTrue($this->form->check()); 
     
    137137        $ctrl2->primarySecret = 'nom'; 
    138138        $this->form->addCtrl($ctrl2, false); 
    139          
     139 
    140140        $this->form->setData('nom_confirm',''); 
    141141        $this->assertTrue($this->form->check()); 
    142          
     142 
    143143        $this->form->setData('nom','aaa'); 
    144144        $this->assertFalse($this->form->check()); 
     
    181181        $this->assertTrue($this->form->check()); 
    182182    } 
     183 
     184    function testGroup() { 
     185        $group = new jFormsControlGroup('group'); 
     186 
     187        $ctrl = new jFormsControlInput('nom'); 
     188        $ctrl->required = false; 
     189        $group->addChildControl($ctrl); 
     190 
     191        $ctrl = new jFormsControlCheckboxes('categories'); 
     192        $ctrl->required = true; 
     193        $group->addChildControl($ctrl); 
     194        $this->form->addCtrl($group); 
     195 
     196        $this->assertFalse($this->form->check()); 
     197 
     198        $this->form->setData('categories',array('toto','titi')); 
     199        $this->assertTrue($this->form->check()); 
     200 
     201        $this->form->setData('nom', 'foo'); 
     202        $this->assertTrue($this->form->check()); 
     203 
     204    } 
     205 
     206 
     207    function testChoice() { 
     208        $choice = new jFormsControlChoice('choice'); 
     209        $choice->required = false; 
     210 
     211        $choice->createItem('item1','labelitem1'); 
     212        $choice->createItem('item2','labelitem2'); 
     213        $choice->createItem('item3','labelitem3'); 
     214 
     215        $ctrl = new jFormsControlInput('nom'); 
     216        $ctrl->required = false; 
     217        $choice->addChildControl($ctrl, 'item1'); 
     218 
     219        $ctrl = new jFormsControlCheckboxes('categories'); 
     220        $ctrl->required = true; 
     221        $choice->addChildControl($ctrl, 'item1'); 
     222 
     223        $ctrl = new jFormsControlinput('datenaissance'); 
     224        $ctrl->datatype= new jDatatypelocaledate(); 
     225        $choice->addChildControl($ctrl, 'item2'); 
     226 
     227        $this->form->addCtrl($choice); 
     228 
     229        $this->assertFalse($this->form->check()); 
     230 
     231        $this->form->setData('choice', 'foo'); 
     232        $this->assertFalse($this->form->check()); 
     233 
     234        $this->form->setData('choice', 'item3'); 
     235        $this->assertTrue($this->form->check()); 
     236 
     237        $this->form->setData('choice', 'item1'); 
     238        $this->assertFalse($this->form->check()); 
     239 
     240        $this->form->setData('categories','toto'); 
     241        $this->assertFalse($this->form->check()); 
     242 
     243        $this->form->setData('categories',array('toto')); 
     244        $this->assertTrue($this->form->check()); 
     245 
     246        $this->form->setData('categories',array('toto','titi')); 
     247        $this->assertTrue($this->form->check()); 
     248 
     249        $this->form->setData('choice', 'item2'); 
     250        $this->assertTrue($this->form->check()); 
     251 
     252        $this->form->setData('categories',''); 
     253        $this->assertTrue($this->form->check()); 
     254 
     255    } 
    183256} 
    184257 
  • branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r914 r970  
    2929    protected $form; 
    3030    protected $container; 
    31     function testStart() { 
     31    function setUp() { 
    3232        $this->container = new jFormsDataContainer('',''); 
    3333        $this->form = new testCDForm('foo',$this->container); 
     
    124124        $ctrl->required = false; 
    125125        $this->form->addCtrl($ctrl); 
    126          
     126 
    127127        $this->form->setData('nom',null); 
    128128        $this->assertTrue($this->form->check()); 
     
    137137        $ctrl2->primarySecret = 'nom'; 
    138138        $this->form->addCtrl($ctrl2, false); 
    139          
     139 
    140140        $this->form->setData('nom_confirm',''); 
    141141        $this->assertTrue($this->form->check()); 
    142          
     142 
    143143        $this->form->setData('nom','aaa'); 
    144144        $this->assertFalse($this->form->check()); 
     
    181181        $this->assertTrue($this->form->check()); 
    182182    } 
     183 
     184    function testGroup() { 
     185        $group = new jFormsControlGroup('group'); 
     186 
     187        $ctrl = new jFormsControlInput('nom'); 
     188        $ctrl->required = false; 
     189        $group->addChildControl($ctrl); 
     190 
     191        $ctrl = new jFormsControlCheckboxes('categories'); 
     192        $ctrl->required = true; 
     193        $group->addChildControl($ctrl); 
     194        $this->form->addCtrl($group); 
     195 
     196        $this->assertFalse($this->form->check()); 
     197 
     198        $this->form->setData('categories',array('toto','titi')); 
     199        $this->assertTrue($this->form->check()); 
     200 
     201        $this->form->setData('nom', 'foo'); 
     202        $this->assertTrue($this->form->check()); 
     203 
     204    } 
     205 
     206 
     207    function testChoice() { 
     208        $choice = new jFormsControlChoice('choice'); 
     209        $choice->required = false; 
     210 
     211        $choice->createItem('item1','labelitem1'); 
     212        $choice->createItem('item2','labelitem2'); 
     213        $choice->createItem('item3','labelitem3'); 
     214 
     215        $ctrl = new jFormsControlInput('nom'); 
     216        $ctrl->required = false; 
     217        $choice->addChildControl($ctrl, 'item1'); 
     218 
     219        $ctrl = new jFormsControlCheckboxes('categories'); 
     220        $ctrl->required = true; 
     221        $choice->addChildControl($ctrl, 'item1'); 
     222 
     223        $ctrl = new jFormsControlinput('datenaissance'); 
     224        $ctrl->datatype= new jDatatypelocaledate(); 
     225        $choice->addChildControl($ctrl, 'item2'); 
     226 
     227        $this->form->addCtrl($choice); 
     228 
     229        $this->assertFalse($this->form->check()); 
     230 
     231        $this->form->setData('choice', 'foo'); 
     232        $this->assertFalse($this->form->check()); 
     233 
     234        $this->form->setData('choice', 'item3'); 
     235        $this->assertTrue($this->form->check()); 
     236 
     237        $this->form->setData('choice', 'item1'); 
     238        $this->assertFalse($this->form->check()); 
     239 
     240        $this->form->setData('categories','toto'); 
     241        $this->assertFalse($this->form->check()); 
     242 
     243        $this->form->setData('categories',array('toto')); 
     244        $this->assertTrue($this->form->check()); 
     245 
     246        $this->form->setData('categories',array('toto','titi')); 
     247        $this->assertTrue($this->form->check()); 
     248 
     249        $this->form->setData('choice', 'item2'); 
     250        $this->assertTrue($this->form->check()); 
     251 
     252        $this->form->setData('categories',''); 
     253        $this->assertTrue($this->form->check()); 
     254 
     255    } 
    183256} 
    184257 
  • branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r914 r970  
    2929    protected $form; 
    3030    protected $container; 
    31     function testStart() { 
     31    function setUp() { 
    3232        $this->container = new jFormsDataContainer('',''); 
    3333        $this->form = new testCDForm('foo',$this->container); 
     
    124124        $ctrl->required = false; 
    125125        $this->form->addCtrl($ctrl); 
    126          
     126 
    127127        $this->form->setData('nom',null); 
    128128        $this->assertTrue($this->form->check()); 
     
    137137        $ctrl2->primarySecret = 'nom'; 
    138138        $this->form->addCtrl($ctrl2, false); 
    139          
     139 
    140140        $this->form->setData('nom_confirm',''); 
    141141        $this->assertTrue($this->form->check()); 
    142          
     142 
    143143        $this->form->setData('nom','aaa'); 
    144144        $this->assertFalse($this->form->check()); 
     
    181181        $this->assertTrue($this->form->check()); 
    182182    } 
     183 
     184    function testGroup() { 
     185        $group = new jFormsControlGroup('group'); 
     186 
     187        $ctrl = new jFormsControlInput('nom'); 
     188        $ctrl->required = false; 
     189        $group->addChildControl($ctrl); 
     190 
     191        $ctrl = new jFormsControlCheckboxes('categories'); 
     192        $ctrl->required = true; 
     193        $group->addChildControl($ctrl); 
     194        $this->form->addCtrl($group