function testGetErrorsForParticularField() { $template = '{{form name="my_form"}}' . '{{form:field_errors to="$form_errors" for="field2"/}}' . '{{list using="$form_errors" as="$item"}}{{list:item}}{$item.id}-{$item.message}|{{/list:item}}{{/list}}' . '{{/form}}'; $page = $this->_createMacroTemplate($template, 'tpl.html'); $error_list = new lmbMacroFormErrorList(); $error_list->addError('Error1', array('first' => 'field1', 'second' => 'field2')); $error_list->addError('Error2', array('first' => 'field1')); $page->set('form_my_form_error_list', $error_list); $out = $page->render(); $this->assertEqual($out, '<form name="my_form">field2-Error1|</form>'); }
function testChildFieldsGetErrorsAsWell() { $template = '{{form name="my_form"}}' . '{{form:errors to="$form_errors"/}}' . '{{list using="$form_errors" as="$item"}}{{list:item}}{$item.message}{{/list:item}}{{/list}}' . '{{label for="text_field" error_style="style_of_error"}}My text{{/label}}' . '{{input type="text" name="text_field" title="My text field" error_class="class_of_error"/}}' . '{{label for="select_field" error_class="class_of_error"}}My select{{/label}}' . '{{select name="select_field" title="My select field" error_style="style_of_error"/}}' . '{{/form}}'; $page = $this->_createMacroTemplate($template, 'tpl.html'); $error_list = new lmbMacroFormErrorList(); $error_list->addError('Error in {field}', array('field' => 'text_field')); $error_list->addError('Other error in {field}', array('field' => 'select_field')); $page->set('form_my_form_error_list', $error_list); $expected = '<form name="my_form">Error in "My text field"Other error in "My select field"' . '<label for="text_field" style="style_of_error">My text</label>' . '<input type="text" name="text_field" title="My text field" class="class_of_error" value="" />' . '<label for="select_field" class="class_of_error">My select</label>' . '<select name="select_field" title="My select field" style="style_of_error"></select>' . '</form>'; $this->assertEqual($page->render(), $expected); }
function testFormTakesErrorListFromTemplateVariable() { $template = '{{form name="my_form"}}' . '<?php $error_list = $this->form_my_form->getErrorList(); ' . 'if($error_list[0]["message"] == $this->error_message) echo 1111;' . '?>' . '{{/form}}'; $page = $this->_createMacroTemplate($template, 'tpl.html'); $error_list = new lmbMacroFormErrorList(); $error_list->addError($message = 'Any error message'); $page->set('error_message', $message); $page->set('form_my_form_error_list', $error_list); $out = $page->render(); $this->assertEqual($out, '<form name="my_form">1111</form>'); }
function testGetFieldErrorsForField() { $error_list = new lmbMacroFormErrorList(); $error_list->addError('message1', array('x' => 'Input1')); $error_list->addError('message2', array('x' => 'Input1', 'z' => 'Input2')); $form = new lmbMacroFormWidget('my_id'); $form->setErrorList($error_list); $errors = $form->getErrorsListForFields(); $this->assertEqual(sizeof($errors), 3); $errors = $form->getErrorsListForFields('Input1'); $this->assertEqual($errors[0]['message'], 'message1'); $this->assertEqual($errors[1]['message'], 'message2'); $errors = $form->getErrorsListForFields('Input2'); $this->assertEqual($errors[0]['message'], 'message2'); }
function testAddErrorWithFieldAndValuePlaceholders() { $error_list = new lmbMacroFormErrorList(); $error_list->addError('{Field} should be between {value_min} and {value_max}', array('Field' => 'title'), array('value_min' => 10, 'value_max' => 100)); $this->assertErrorsInList($error_list, array(array('message' => '"title" should be between 10 and 100', 'fields' => array('Field' => 'title'), 'values' => array('value_min' => 10, 'value_max' => 100)))); }