Exemple #1
0
 function testErrorsPassedToListListTagIfInsideFormErrorsTag()
 {
     $template = '<form id="my_form" runat="server"><form:errors>' . '<list:list><list:item>{$message}</list:item></list:list></form:errors>' . '</form>';
     $this->registerTestingTemplate('/form/form_errors/passed_to_nested_list.html', $template);
     $page = $this->initTemplate('/form/form_errors/passed_to_nested_list.html');
     $error_list = new WactFormErrorList();
     $error_list->addError('Error1 text');
     $error_list->addError('Error2 text');
     $form = $page->getChild("my_form");
     $form->setErrors($error_list);
     $this->assertEqual($page->capture(), '<form id="my_form">Error1 textError2 text</form>');
 }
Exemple #2
0
 function testErrorsForSpecifiedFormElement()
 {
     $template = '<form id="my_form" runat="server"><form:field_errors for="field2">' . '<list:list id="errors"><list:item>{$message}|</list:item></list:list>' . '</form:field_errors></form>';
     $this->registerTestingTemplate('/form/form_field_errors/for_element_passed_to_list.html', $template);
     $page = $this->initTemplate('/form/form_field_errors/for_element_passed_to_list.html');
     $error_list = new WactFormErrorList();
     $error_list->addError('Error1 text', array('FIRST' => 'field1', 'SECOND' => 'field2'));
     $error_list->addError('Error2 text', array('FIELD' => 'field1'));
     $error_list->addError('Error3 text', array('FIELD' => 'field2'));
     $form = $page->getChild("my_form");
     $form->setErrors($error_list);
     $this->assertEqual($page->capture(), '<form id="my_form">Error1 text|Error3 text|</form>');
 }
Exemple #3
0
 protected function _fillWactTemplate($template)
 {
     foreach ($this->getVariables() as $variable_name => $value) {
         $template->set($variable_name, $value);
     }
     foreach ($this->forms_datasources as $form_id => $datasource) {
         $form_component = $template->getChild($form_id);
         $form_component->registerDataSource($datasource);
     }
     foreach ($this->forms_errors as $form_id => $error_list) {
         $form_component = $template->getChild($form_id);
         if (!$error_list->isValid()) {
             lmb_require('limb/wact/src/components/form/error.inc.php');
             $wact_error_list = new WactFormErrorList($error_list->getArray());
             $wact_error_list->bindToForm($form_component);
         }
     }
 }
Exemple #4
0
    function testSetErrorsTricky()
    {
        $error_list = new WactFormErrorList();
        $errorFields = array('a' => 'InputText', 'b' => 'Select1', 'c' => 'Select2', 'd' => 'Select3', 'e' => 'Select4', 'f' => 'InputCheckbox2');
        $error_list->addError('message', $errorFields);
        $template = '<form id="testForm" runat="server">

                    <label id="Label1" for="InputText" class="Normal" errorclass="Error" runat="server">A label</label>
                    <input id="InputText" type="text" runat="server"/>

                    <label id="Label2" for="Select1" class="Normal" errorclass="Error" runat="server">A label</label>
                    <select id="Select1" name="mySelect1" type="text" runat="server"></select>

                    <label id="Label3" for="Select2" class="Normal" errorclass="Error" runat="server">A label</label>
                    <select name="Select2" type="text" runat="server"></select>

                    <label id="Label4" for="Select3" class="Normal" errorclass="Error" runat="server">A label</label>
                    <select id="Select3" name="Test[]" type="text" runat="server" multiple="true"></select>

                    <label id="Label5" for="Select4" class="Normal" errorclass="Error" runat="server">A label</label>
                    <select name="Select4[]" type="text" runat="server" multiple="true"></select>

                    <label id="Label6" for="InputCheckbox1" class="Normal" errorclass="Error" runat="server">A label</label>
                    <label id="Label7" for="InputCheckbox2" class="Normal" errorclass="Error" runat="server">A label</label>
                    <label id="Label8" for="InputCheckbox3" class="Normal" errorclass="Error" runat="server">A label</label>
                    <input id="InputCheckbox1" type="checkbox" name="test" value="x" checked="true" runat="server"/>
                    <input id="InputCheckbox2" type="checkbox" name="test" value="y" runat="server"/>
                    <input id="InputCheckbox3" type="checkbox" name="test" value="z" runat="server"/>

                </form>';
        $this->registerTestingTemplate('/tags/form/form/seterrorstricky.html', $template);
        $page = $this->initTemplate('/tags/form/form/seterrorstricky.html');
        $form = $page->getChild('testForm');
        $form->setErrors($error_list);
        $label1 = $page->getChild('Label1');
        $this->assertEqual($label1->getAttribute('class'), 'Error');
        $InputText = $page->getChild('InputText');
        $this->assertTrue($InputText->hasErrors());
        $label2 = $page->getChild('Label2');
        $this->assertEqual($label2->getAttribute('class'), 'Error');
        $Select1 = $page->getChild('Select1');
        $this->assertTrue($Select1->hasErrors());
        $label3 = $page->getChild('Label3');
        $this->assertEqual($label3->getAttribute('class'), 'Normal');
        $Select2 = $page->getChild('Select2');
        $this->assertTrue($Select2->hasErrors());
        $label4 = $page->getChild('Label4');
        $this->assertEqual($label4->getAttribute('class'), 'Error');
        $Select3 = $page->getChild('Select3');
        $this->assertTrue($Select3->hasErrors());
        $label5 = $page->getChild('Label5');
        $this->assertEqual($label5->getAttribute('class'), 'Normal');
        $Select4 = $page->getChild('Select4');
        $this->assertTrue($Select4->hasErrors());
        $label6 = $page->getChild('Label6');
        $this->assertEqual($label6->getAttribute('class'), 'Normal');
        $InputCheckbox1 = $page->getChild('InputCheckbox1');
        $this->assertFalse($InputCheckbox1->hasErrors());
        $label7 = $page->getChild('Label7');
        $this->assertEqual($label7->getAttribute('class'), 'Error');
        $InputCheckbox2 = $page->getChild('InputCheckbox2');
        $this->assertTrue($InputCheckbox2->hasErrors());
        $label8 = $page->getChild('Label8');
        $this->assertEqual($label8->getAttribute('class'), 'Normal');
        $InputCheckbox3 = $page->getChild('InputCheckbox3');
        $this->assertFalse($InputCheckbox3->hasErrors());
    }