Changeset 840

Show
Ignore:
Timestamp:
03/25/08 15:40:30 (8 months ago)
Author:
laurentj
Message:

ticket #248: added support of <captcha> element in jforms type=turing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/jelix-lib.mn

    r839 r840  
    102102  auth.ISO-8859-15.properties 
    103103  auth.UTF-8.properties 
     104  captcha.ISO-8859-1.properties 
     105  captcha.ISO-8859-15.properties 
     106  captcha.UTF-8.properties 
    104107  common.ISO-8859-1.properties 
    105108  common.ISO-8859-15.properties 
     
    139142  auth.ISO-8859-15.properties 
    140143  auth.UTF-8.properties 
     144  captcha.ISO-8859-1.properties 
     145  captcha.ISO-8859-15.properties 
     146  captcha.UTF-8.properties 
    141147  common.ISO-8859-1.properties 
    142148  common.ISO-8859-15.properties 
     
    176182  auth.ISO-8859-15.properties 
    177183  auth.UTF-8.properties 
     184  captcha.ISO-8859-1.properties 
     185  captcha.ISO-8859-15.properties 
     186  captcha.UTF-8.properties 
    178187  common.ISO-8859-1.properties 
    179188  common.ISO-8859-15.properties 
  • trunk/build/manifests/jelix-lib.mn

    r839 r840  
    102102  auth.ISO-8859-15.properties 
    103103  auth.UTF-8.properties 
     104  captcha.ISO-8859-1.properties 
     105  captcha.ISO-8859-15.properties 
     106  captcha.UTF-8.properties 
    104107  common.ISO-8859-1.properties 
    105108  common.ISO-8859-15.properties 
     
    139142  auth.ISO-8859-15.properties 
    140143  auth.UTF-8.properties 
     144  captcha.ISO-8859-1.properties 
     145  captcha.ISO-8859-15.properties 
     146  captcha.UTF-8.properties 
    141147  common.ISO-8859-1.properties 
    142148  common.ISO-8859-15.properties 
     
    176182  auth.ISO-8859-15.properties 
    177183  auth.UTF-8.properties 
     184  captcha.ISO-8859-1.properties 
     185  captcha.ISO-8859-15.properties 
     186  captcha.UTF-8.properties 
    178187  common.ISO-8859-1.properties 
    179188  common.ISO-8859-15.properties 
  • trunk/build/manifests/jelix-lib.mn

    r839 r840  
    102102  auth.ISO-8859-15.properties 
    103103  auth.UTF-8.properties 
     104  captcha.ISO-8859-1.properties 
     105  captcha.ISO-8859-15.properties 
     106  captcha.UTF-8.properties 
    104107  common.ISO-8859-1.properties 
    105108  common.ISO-8859-15.properties 
     
    139142  auth.ISO-8859-15.properties 
    140143  auth.UTF-8.properties 
     144  captcha.ISO-8859-1.properties 
     145  captcha.ISO-8859-15.properties 
     146  captcha.UTF-8.properties 
    141147  common.ISO-8859-1.properties 
    142148  common.ISO-8859-15.properties 
     
    176182  auth.ISO-8859-15.properties 
    177183  auth.UTF-8.properties 
     184  captcha.ISO-8859-1.properties 
     185  captcha.ISO-8859-15.properties 
     186  captcha.UTF-8.properties 
    178187  common.ISO-8859-1.properties 
    179188  common.ISO-8859-15.properties 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r839 r840  
    213213        $this->readLabel($source, $control, 'output'); 
    214214        $this->readHelpHintAlert($source, $control); 
    215  
    216215    } 
    217216 
     
    347346        } 
    348347    } 
     348 
     349    protected function generateCaptcha(&$source, $control, &$attributes) { 
     350        $this->readLabel($source, $control, 'captcha'); 
     351        $this->readHelpHintAlert($source, $control); 
     352    } 
     353 
     354 
     355 
    349356 
    350357    protected function attrReadonly(&$source, &$attributes) { 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r839 r840  
    213213        $this->readLabel($source, $control, 'output'); 
    214214        $this->readHelpHintAlert($source, $control); 
    215  
    216215    } 
    217216 
     
    347346        } 
    348347    } 
     348 
     349    protected function generateCaptcha(&$source, $control, &$attributes) { 
     350        $this->readLabel($source, $control, 'captcha'); 
     351        $this->readHelpHintAlert($source, $control); 
     352    } 
     353 
     354 
     355 
    349356 
    350357    protected function attrReadonly(&$source, &$attributes) { 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r839 r840  
    213213        $this->readLabel($source, $control, 'output'); 
    214214        $this->readHelpHintAlert($source, $control); 
    215  
    216215    } 
    217216 
     
    347346        } 
    348347    } 
     348 
     349    protected function generateCaptcha(&$source, $control, &$attributes) { 
     350        $this->readLabel($source, $control, 'captcha'); 
     351        $this->readHelpHintAlert($source, $control); 
     352    } 
     353 
     354 
     355 
    349356 
    350357    protected function attrReadonly(&$source, &$attributes) { 
  • trunk/lib/jelix/forms/jFormsControl.class.php

    r839 r840  
    218218} 
    219219 
    220  
     220/** 
     221 * captcha control 
     222 * @package     jelix 
     223 * @subpackage  forms 
     224 */ 
     225class jFormsControlCaptcha extends jFormsControl { 
     226    public $type = 'captcha'; 
     227    public $question=''; 
     228    public $required = true; 
     229    function check($form){ 
     230        $value = $form->getContainer()->data[$this->ref]; 
     231        if($value == '') { 
     232            return jForms::ERRDATA_REQUIRED; 
     233        }elseif($value != $form->getContainer()->privateData[$this->ref]){ 
     234            return jForms::ERRDATA_INVALID; 
     235        } 
     236        return null; 
     237    } 
     238 
     239    function initExpectedValue($form){ 
     240        $numbers = jLocale::get('jelix~captcha.number'); 
     241        $id = rand(1,intval($numbers)); 
     242        $this->question = jLocale::get('jelix~captcha.question.'.$id); 
     243        $form->getContainer()->privateData[$this->ref] = jLocale::get('jelix~captcha.response.'.$id); 
     244    } 
     245
    221246 
    222247/** 
  • trunk/lib/jelix/forms/jFormsControl.class.php

    r839 r840  
    218218} 
    219219 
    220  
     220/** 
     221 * captcha control 
     222 * @package     jelix 
     223 * @subpackage  forms 
     224 */ 
     225class jFormsControlCaptcha extends jFormsControl { 
     226    public $type = 'captcha'; 
     227    public $question=''; 
     228    public $required = true; 
     229    function check($form){ 
     230        $value = $form->getContainer()->data[$this->ref]; 
     231        if($value == '') { 
     232            return jForms::ERRDATA_REQUIRED; 
     233        }elseif($value != $form->getContainer()->privateData[$this->ref]){ 
     234            return jForms::ERRDATA_INVALID; 
     235        } 
     236        return null; 
     237    } 
     238 
     239    function initExpectedValue($form){ 
     240        $numbers = jLocale::get('jelix~captcha.number'); 
     241        $id = rand(1,intval($numbers)); 
     242        $this->question = jLocale::get('jelix~captcha.question.'.$id); 
     243        $form->getContainer()->privateData[$this->ref] = jLocale::get('jelix~captcha.response.'.$id); 
     244    } 
     245
    221246 
    222247/** 
  • trunk/lib/jelix/forms/jFormsControl.class.php

    r839 r840  
    218218} 
    219219 
    220  
     220/** 
     221 * captcha control 
     222 * @package     jelix 
     223 * @subpackage  forms 
     224 */ 
     225class jFormsControlCaptcha extends jFormsControl { 
     226    public $type = 'captcha'; 
     227    public $question=''; 
     228    public $required = true; 
     229    function check($form){ 
     230        $value = $form->getContainer()->data[$this->ref]; 
     231        if($value == '') { 
     232            return jForms::ERRDATA_REQUIRED; 
     233        }elseif($value != $form->getContainer()->privateData[$this->ref]){ 
     234            return jForms::ERRDATA_INVALID; 
     235        } 
     236        return null; 
     237    } 
     238 
     239    function initExpectedValue($form){ 
     240        $numbers = jLocale::get('jelix~captcha.number'); 
     241        $id = rand(1,intval($numbers)); 
     242        $this->question = jLocale::get('jelix~captcha.question.'.$id); 
     243        $form->getContainer()->privateData[$this->ref] = jLocale::get('jelix~captcha.response.'.$id); 
     244    } 
     245
    221246 
    222247/** 
  • trunk/lib/jelix/forms/jFormsDataContainer.class.php

    r839 r840  
    55* @author      Laurent Jouanneau 
    66* @contributor 
    7 * @copyright   2006-2007 Laurent Jouanneau 
     7* @copyright   2006-2008 Laurent Jouanneau 
    88* @link        http://www.jelix.org 
    99* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    1717class jFormsDataContainer { 
    1818    /** 
     19     * contains data provided by the user in each controls 
    1920     * @var array 
    2021     */ 
    2122    public $data = array(); 
     23 
     24    /** 
     25     * internal use. Used by controls object to store some private data. (captcha for example) 
     26     * @var array 
     27     */ 
     28    public $privateData = array(); 
     29 
    2230    /** 
    2331     * the instance id of the form 
  • trunk/lib/jelix/forms/jFormsDataContainer.class.php

    r839 r840  
    55* @author      Laurent Jouanneau 
    66* @contributor 
    7 * @copyright   2006-2007 Laurent Jouanneau 
     7* @copyright   2006-2008 Laurent Jouanneau 
    88* @link        http://www.jelix.org 
    99* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    1717class jFormsDataContainer { 
    1818    /** 
     19     * contains data provided by the user in each controls 
    1920     * @var array 
    2021     */ 
    2122    public $data = array(); 
     23 
     24    /** 
     25     * internal use. Used by controls object to store some private data. (captcha for example) 
     26     * @var array 
     27     */ 
     28    public $privateData = array(); 
     29 
    2230    /** 
    2331     * the instance id of the form 
  • trunk/lib/jelix/forms/jFormsDataContainer.class.php

    r839 r840  
    55* @author      Laurent Jouanneau 
    66* @contributor 
    7 * @copyright   2006-2007 Laurent Jouanneau 
     7* @copyright   2006-2008 Laurent Jouanneau 
    88* @link        http://www.jelix.org 
    99* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    1717class jFormsDataContainer { 
    1818    /** 
     19     * contains data provided by the user in each controls 
    1920     * @var array 
    2021     */ 
    2122    public $data = array(); 
     23 
     24    /** 
     25     * internal use. Used by controls object to store some private data. (captcha for example) 
     26     * @var array 
     27     */ 
     28    public $privateData = array(); 
     29 
    2230    /** 
    2331     * the instance id of the form 
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r839 r840  
    243243            echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
    244244            break; 
     245        case 'captcha': 
     246            $ctrl->initExpectedValue($this->_form); 
     247            echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
     248            echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
     249            break; 
    245250        } 
    246251 
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r839 r840  
    243243            echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
    244244            break; 
     245        case 'captcha': 
     246            $ctrl->initExpectedValue($this->_form); 
     247            echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
     248            echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
     249            break; 
    245250        } 
    246251 
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r839 r840  
    243243            echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
    244244            break; 
     245        case 'captcha': 
     246            $ctrl->initExpectedValue($this->_form); 
     247            echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
     248            echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
     249            break; 
    245250        } 
    246251 
  • trunk/lib/jelix/plugins/tpl/html/block.formcontrols.php

    r831 r840  
    7979    if($ctrl->type == \'reset\' || $ctrl->type == \'hidden\') continue; 
    8080    if($ctrl->type == \'submit\' && (isset($t->_privateVars[\'__formbuilder\']) || $ctrl->standalone)) continue; 
     81    if($ctrl->type == \'captcha\' && !isset($t->_privateVars[\'__formbuilder\'])) continue; 
    8182    if(!isset($t->_privateVars[\'__displayed_ctrl\'][$ctrlref]) 
    8283       && (  ($ctrls_to_display===null && $ctrls_notto_display === null) 
  • trunk/lib/jelix/plugins/tpl/html/block.formcontrols.php

    r831 r840  
    7979    if($ctrl->type == \'reset\' || $ctrl->type == \'hidden\') continue; 
    8080    if($ctrl->type == \'submit\' && (isset($t->_privateVars[\'__formbuilder\']) || $ctrl->standalone)) continue; 
     81    if($ctrl->type == \'captcha\' && !isset($t->_privateVars[\'__formbuilder\'])) continue; 
    8182    if(!isset($t->_privateVars[\'__displayed_ctrl\'][$ctrlref]) 
    8283       && (  ($ctrls_to_display===null && $ctrls_notto_display === null) 
  • trunk/lib/jelix/plugins/tpl/html/block.formcontrols.php

    r831 r840  
    7979    if($ctrl->type == \'reset\' || $ctrl->type == \'hidden\') continue; 
    8080    if($ctrl->type == \'submit\' && (isset($t->_privateVars[\'__formbuilder\']) || $ctrl->standalone)) continue; 
     81    if($ctrl->type == \'captcha\' && !isset($t->_privateVars[\'__formbuilder\'])) continue; 
    8182    if(!isset($t->_privateVars[\'__displayed_ctrl\'][$ctrlref]) 
    8283       && (  ($ctrls_to_display===null && $ctrls_notto_display === null) 
  • trunk/lib/jelix/plugins/tpl/html/function.ctrl_label.php

    r831 r840  
    2929    if ($ctrl->type == 'hidden') 
    3030        return; 
     31 
     32    // if _formbuilder exists, we are inside a {form} (so it displays a form) 
     33    // else we are inside a {formdata} 
    3134    if(isset($tpl->_privateVars['__formbuilder'])){ 
    3235        if($ctrl->type == 'submit' || $ctrl->type == 'reset') 
    3336            return; 
    3437        $tpl->_privateVars['__formbuilder']->outputControlLabel($ctrl); 
    35     }else 
     38    }else { 
     39        if($ctrl->type == 'captcha') 
     40            return; 
    3641        echo htmlspecialchars($ctrl->label); 
     42    } 
    3743} 
    3844 
  • trunk/lib/jelix/plugins/tpl/html/function.ctrl_label.php

    r831 r840  
    2929    if ($ctrl->type == 'hidden') 
    3030        return; 
     31 
     32    // if _formbuilder exists, we are inside a {form} (so it displays a form) 
     33    // else we are inside a {formdata} 
    3134    if(isset($tpl->_privateVars['__formbuilder'])){ 
    3235        if($ctrl->type == 'submit' || $ctrl->type == 'reset') 
    3336            return; 
    3437        $tpl->_privateVars['__formbuilder']->outputControlLabel($ctrl); 
    35     }else 
     38    }else { 
     39        if($ctrl->type == 'captcha') 
     40            return; 
    3641        echo htmlspecialchars($ctrl->label); 
     42    } 
    3743} 
    3844 
  • trunk/lib/jelix/plugins/tpl/html/function.ctrl_label.php

    r831 r840  
    2929    if ($ctrl->type == 'hidden') 
    3030        return; 
     31 
     32    // if _formbuilder exists, we are inside a {form} (so it displays a form) 
     33    // else we are inside a {formdata} 
    3134    if(isset($tpl->_privateVars['__formbuilder'])){ 
    3235        if($ctrl->type == 'submit' || $ctrl->type == 'reset') 
    3336            return; 
    3437        $tpl->_privateVars['__formbuilder']->outputControlLabel($ctrl); 
    35     }else 
     38    }else { 
     39        if($ctrl->type == 'captcha') 
     40            return; 
    3641        echo htmlspecialchars($ctrl->label); 
     42    } 
    3743} 
    3844 
  • trunk/lib/jelix/plugins/tpl/html/function.ctrl_value.php

    r836 r840  
    2525 
    2626    if($ctrlname =='') { 
    27         if($tpl->_privateVars['__ctrl']->type == 'hidden') 
    28             return; 
    29         if(($tpl->_privateVars['__ctrl']->type == 'submit') 
    30                 && ($tpl->_privateVars['__ctrl']->standalone || $insideForm)){ 
    31             return; 
    32         } 
    33         if(($tpl->_privateVars['__ctrl']->type == 'reset') && $insideForm){ 
    34             return; 
    35         } 
     27        $ctrl = $tpl->_privateVars['__ctrl']; 
    3628        $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true; 
    37         $ctrl = $tpl->_privateVars['__ctrl']; 
    3829        $ctrlname = $tpl->_privateVars['__ctrlref']; 
    3930    }else{ 
    4031        $ctrls = $tpl->_privateVars['__form']->getControls(); 
    41         if($ctrls[$ctrlname]->type == 'hidden') 
    42             return; 
    43         if(($ctrls[$ctrlname]->type == 'submit' || $ctrls[$ctrlname]->type == 'reset') 
    44                 && ($ctrls[$ctrlname]->standalone || $insideForm)){ 
    45             return; 
    46         } 
    4732        $ctrl = $ctrls[$ctrlname]; 
     33    } 
     34 
     35    if($ctrl->type == 'hidden' || $ctrl->type == 'captcha') 
     36        return; 
     37 
     38    if($ctrl->type == 'submit'  && ($ctrl->standalone || $insideForm)) 
     39        return; 
     40 
     41    if($ctrl->type == 'reset' && $insideForm){ 
     42        return; 
    4843    } 
    4944 
  • trunk/lib/jelix/plugins/tpl/html/function.ctrl_value.php

    r836 r840  
    2525 
    2626    if($ctrlname =='') { 
    27         if($tpl->_privateVars['__ctrl']->type == 'hidden') 
    28             return; 
    29         if(($tpl->_privateVars['__ctrl']->type == 'submit') 
    30                 && ($tpl->_privateVars['__ctrl']->standalone || $insideForm)){ 
    31             return; 
    32         } 
    33         if(($tpl->_privateVars['__ctrl']->type == 'reset') && $insideForm){ 
    34             return; 
    35         } 
     27        $ctrl = $tpl->_privateVars['__ctrl']; 
    3628        $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true; 
    37         $ctrl = $tpl->_privateVars['__ctrl']; 
    3829        $ctrlname = $tpl->_privateVars['__ctrlref']; 
    3930    }else{ 
    4031        $ctrls = $tpl->_privateVars['__form']->getControls(); 
    41         if($ctrls[$ctrlname]->type == 'hidden') 
    42             return; 
    43         if(($ctrls[$ctrlname]->type == 'submit' || $ctrls[$ctrlname]->type == 'reset') 
    44                 && ($ctrls[$ctrlname]->standalone || $insideForm)){ 
    45             return; 
    46         } 
    4732        $ctrl = $ctrls[$ctrlname]; 
     33    } 
     34 
     35    if($ctrl->type == 'hidden' || $ctrl->type == 'captcha') 
     36        return; 
     37 
     38    if($ctrl->type == 'submit'  && ($ctrl->standalone || $insideForm)) 
     39        return; 
     40 
     41    if($ctrl->type == 'reset' && $insideForm){ 
     42        return; 
    4843    } 
    4944 
  • trunk/lib/jelix/plugins/tpl/html/function.ctrl_value.php

    r836 r840  
    2525 
    2626    if($ctrlname =='') { 
    27         if($tpl->_privateVars['__ctrl']->type == 'hidden') 
    28             return; 
    29         if(($tpl->_privateVars['__ctrl']->type == 'submit') 
    30                 && ($tpl->_privateVars['__ctrl']->standalone || $insideForm)){ 
    31             return; 
    32         } 
    33         if(($tpl->_privateVars['__ctrl']->type == 'reset') && $insideForm){ 
    34             return; 
    35         } 
     27        $ctrl = $tpl->_privateVars['__ctrl']; 
    3628        $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true; 
    37         $ctrl = $tpl->_privateVars['__ctrl']; 
    3829        $ctrlname = $tpl->_privateVars['__ctrlref']; 
    3930    }else{ 
    4031        $ctrls = $tpl->_privateVars['__form']->getControls(); 
    41         if($ctrls[$ctrlname]->type == 'hidden') 
    42             return; 
    43         if(($ctrls[$ctrlname]->type == 'submit' || $ctrls[$ctrlname]->type == 'reset') 
    44                 && ($ctrls[$ctrlname]->standalone || $insideForm)){ 
    45             return; 
    46         } 
    4732        $ctrl = $ctrls[$ctrlname]; 
     33    } 
     34 
     35    if($ctrl->type == 'hidden' || $ctrl->type == 'captcha') 
     36        return; 
     37 
     38    if($ctrl->type == 'submit'  && ($ctrl->standalone || $insideForm)) 
     39        return; 
     40 
     41    if($ctrl->type == 'reset' && $insideForm){ 
     42        return; 
    4843    } 
    4944 
  • trunk/lib/jelix/plugins/tpl/html/function.formdatafull.php

    r839 r840  
    2525 
    2626    foreach( $form->getControls() as $ctrlref=>$ctrl){ 
    27         if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden') continue; 
     27        if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden' || $ctrl->type == 'captcha') continue; 
    2828 
    2929        echo '<tr><th scope="row">'; 
  • trunk/lib/jelix/plugins/tpl/html/function.formdatafull.php

    r839 r840  
    2525 
    2626    foreach( $form->getControls() as $ctrlref=>$ctrl){ 
    27         if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden') continue; 
     27        if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden' || $ctrl->type == 'captcha') continue; 
    2828 
    2929        echo '<tr><th scope="row">'; 
  • trunk/lib/jelix/plugins/tpl/html/function.formdatafull.php

    r839 r840  
    2525 
    2626    foreach( $form->getControls() as $ctrlref=>$ctrl){ 
    27         if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden') continue; 
     27        if($ctrl->type == 'submit' || $ctrl->type == 'reset' || $ctrl->type == 'hidden' || $ctrl->type == 'captcha') continue; 
    2828 
    2929        echo '<tr><th scope="row">'; 
  • trunk/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r839 r840  
    155155        $this->form->addCtrl($ctrl); 
    156156        $this->assertTrue($this->form->check()); 
    157      
     157 
    158158    } 
    159159 
     160    function testCaptcha() { 
     161 
     162        $ctrl = new jFormsControlCaptcha('captcha'); 
     163        $this->form->addCtrl($ctrl); 
     164 
     165        $ctrl->initExpectedValue($this->form); 
     166 
     167        $this->assertTrue(isset($this->form->getContainer()->privateData['captcha'])); 
     168 
     169        $expectedResponse = $this->form->getContainer()->privateData['captcha']; 
     170        $this->assertFalse($this->form->check()); 
     171 
     172        if( $expectedResponse == '1234') 
     173            $badresponse = '12345'; 
     174        else 
     175            $badresponse = '1234'; 
     176 
     177        $this->form->setData('captcha',$badresponse); 
     178        $this->assertFalse($this->form->check()); 
     179 
     180        $this->form->setData('captcha',$expectedResponse); 
     181        $this->assertTrue($this->form->check()); 
     182    } 
    160183} 
    161184 
  • trunk/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r839 r840  
    155155        $this->form->addCtrl($ctrl); 
    156156        $this->assertTrue($this->form->check()); 
    157      
     157 
    158158    } 
    159159 
     160    function testCaptcha() { 
     161 
     162        $ctrl = new jFormsControlCaptcha('captcha'); 
     163        $this->form->addCtrl($ctrl); 
     164 
     165        $ctrl->initExpectedValue($this->form); 
     166 
     167        $this->assertTrue(isset($this->form->getContainer()->privateData['captcha'])); 
     168 
     169        $expectedResponse = $this->form->getContainer()->privateData['captcha']; 
     170        $this->assertFalse($this->form->check()); 
     171 
     172        if( $expectedResponse == '1234') 
     173            $badresponse = '12345'; 
     174        else 
     175            $badresponse = '1234'; 
     176 
     177        $this->form->setData('captcha',$badresponse); 
     178        $this->assertFalse($this->form->check()); 
     179 
     180        $this->form->setData('captcha',$expectedResponse); 
     181        $this->assertTrue($this->form->check()); 
     182    } 
    160183} 
    161184 
  • trunk/testapp/modules/jelix_tests/tests/jforms.check_datas.html_cli.php

    r839 r840  
    155155        $this->form->addCtrl($ctrl); 
    156156        $this->assertTrue($this->form->check()); 
    157      
     157 
    158158    } 
    159159 
     160    function testCaptcha() { 
     161 
     162        $ctrl = new jFormsControlCaptcha('captcha'); 
     163        $this->form->addCtrl($ctrl); 
     164 
     165        $ctrl->initExpectedValue($this->form); 
     166 
     167        $this->assertTrue(isset($this->form->getContainer()->privateData['captcha'])); 
     168 
     169        $expectedResponse = $this->form->getContainer()->privateData['captcha']; 
     170        $this->assertFalse($this->form->check()); 
     171 
     172        if( $expectedResponse == '1234') 
     173            $badresponse = '12345'; 
     174        else 
     175            $badresponse = '1234'; 
     176 
     177        $this->form->setData('captcha',$badresponse); 
     178        $this->assertFalse($this->form->check()); 
     179 
     180        $this->form->setData('captcha',$expectedResponse); 
     181        $this->assertTrue($this->form->check()); 
     182    } 
    160183} 
    161184 
  • trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html_cli.php

    r839 r840  
    295295    <label>Votre nom</label> 
    296296</textarea>', 
     29771=>'<captcha ref="cap" xmlns="http://jelix.org/ns/forms/1.0"> 
     298    <label>captcha</label> 
     299</captcha>', 
    297300    ); 
    298301 
     
    664667$ctrl->label=\'Votre nom\'; 
    665668$this->addControl($ctrl);', 
     66971=>'$ctrl= new jFormsControlcaptcha(\'cap\'); 
     670$ctrl->label=\'captcha\'; 
     671$this->addControl($ctrl);', 
    666672); 
    667673 
     
    1030103670=>'$label = \'Votre nom\'; 
    10311037$js.="jForms.tControl = new jFormsControl(\'nom\', \'".str_replace("\'","\\\'",$label)."\', \'string\');\n"; 
     1038$js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 
     1039$js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~for