Skip to content

Commit

Permalink
Merging two tests into one
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 27, 2014
1 parent 0119f79 commit e34e917
Showing 1 changed file with 15 additions and 74 deletions.
89 changes: 15 additions & 74 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -2069,97 +2069,38 @@ public function testFormValidationMultiRecord() {
TableRegistry::get('Contacts', [
'className' => __NAMESPACE__ . '\ContactsTable'
]);
$one->errors('email', ['invalid email']);
$two->errors('name', ['This is wrong']);
$this->Form->create([$one, $two], ['context' => ['table' => 'Contacts']]);
$result = $this->Form->input('Contacts.1.name');
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'contacts-1-name'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'Contacts[1][name]', 'id' => 'contacts-1-name',
'class' => 'form-error', 'maxlength' => 255
),
array('div' => array('class' => 'error-message')),
'This is wrong',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}

/**
* testMultipleInputValidation method
*
* test multiple record form validation error display.
*
* @return void
*/
public function testMultipleInputValidation() {
$this->markTestIncomplete('Need to revisit once models work again.');
$Address->validationErrors[0] = array(
'title' => array('This field cannot be empty'),
'first_name' => array('This field cannot be empty')
);
$Address->validationErrors[1] = array(
'last_name' => array('You must have a last name')
);
$this->Form->create();

$result = $this->Form->input('Address.0.title');
$result = $this->Form->input('Contacts.0.email');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'div' => array('class' => 'input email error'),
'label' => array('for' => 'contacts-0-email'),
'Email',
'/label',
'input' => array(
'type' => 'text', 'name', 'id', 'class' => 'form-error'
'type' => 'text', 'name' => 'Contacts[0][email]', 'id' => 'contacts-0-email',
'class' => 'form-error', 'maxlength' => 255
),
array('div' => array('class' => 'error-message')),
'This field cannot be empty',
'invalid email',
'/div',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Address.0.first_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')),
'This field cannot be empty',
'/div',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Address.0.last_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array('type' => 'text', 'name', 'id'),
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Address.1.last_name');
$result = $this->Form->input('Contacts.1.name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'div' => array('class' => 'input text error'),
'label' => array('for' => 'contacts-1-name'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'preg:/[^<]+/',
'id' => 'preg:/[^<]+/', 'class' => 'form-error'
'type' => 'text', 'name' => 'Contacts[1][name]', 'id' => 'contacts-1-name',
'class' => 'form-error', 'maxlength' => 255
),
array('div' => array('class' => 'error-message')),
'You must have a last name',
'This is wrong',
'/div',
'/div'
);
Expand Down

0 comments on commit e34e917

Please sign in to comment.