public function testErrorsPropertyAccess() { $errors = array( 'title' => 'please enter a title', 'email' => array('email is empty', 'email is not valid') ); $record = new Record(); $result = $record->errors($errors); $this->assertEqual($errors, $result); $result = $record->errors(); $this->assertEqual($errors, $result); $expected = 'please enter a title'; $result = $record->errors('title'); $this->assertEqual($expected, $result); $expected = array('email is empty', 'email is not valid'); $result = $record->errors('email'); $this->assertEqual($expected, $result); $result = $record->errors('not_a_field'); $this->assertNull($result); $result = $record->errors('not_a_field', 'badness'); $this->assertEqual('badness', $result); }
public function testErrorWithCustomConfiguration() { $this->form->config(array('error' => array('class' => 'custom-error-class'))); $record = new Record(); $record->errors(array('name' => array('Please enter a name'))); $this->form->create($record); $result = $this->form->field('name'); $expected = '<div><label for="name">Name</label><input type="text" name="name" />'; $expected .= '<div class="custom-error-class">Please enter a name</div></div>'; $this->assertEqual($expected, $result); }
public function testErrorWithCustomConfiguration() { $this->form->config(array('error' => array('class' => 'custom-error-class'))); $record = new Record(array('model' => $this->_model)); $record->errors(array('name' => array('Please enter a name'))); $this->form->create($record); $result = $this->form->field('name'); $this->assertTags($result, array('<div', 'label' => array('for' => 'MockFormPostName'), 'Name', '/label', 'input' => array('type' => "text", 'name' => 'name', 'id' => 'MockFormPostName'), 'div' => array('class' => "custom-error-class"), 'Please enter a name', '/div', '/div')); }
public function testFormErrorMultipleBindings() { $record1 = new Record(array('model' => $this->_model, 'data' => array('author_id' => '2', 'title' => 'New post', 'body' => 'New post body'))); $record2 = new Record(array('model' => $this->_model2, 'data' => array('section' => 'New post section', 'notes' => 'New post notes'))); $record1->errors(array('title' => 'Not a cool title')); $record2->errors(array('section' => 'Not a cool section')); $this->form->create(compact('record1', 'record2')); $result = $this->form->error('title'); $this->assertTags($result, array('div' => array('class' => 'error'), 'Not a cool title', '/div')); $result = $this->form->error('body'); $this->assertEmpty($result); $result = $this->form->error('record1.title'); $this->assertTags($result, array('div' => array('class' => 'error'), 'Not a cool title', '/div')); $result = $this->form->error('record2.section'); $this->assertTags($result, array('div' => array('class' => 'error'), 'Not a cool section', '/div')); }