Skip to content

Commit

Permalink
Added test for deeply nested validation errors when using entities
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 27, 2014
1 parent 2c35268 commit c0faabb
Showing 1 changed file with 10 additions and 46 deletions.
56 changes: 10 additions & 46 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -2050,52 +2050,16 @@ public function testFormValidationAssociated() {
* @return void
*/
public function testFormValidationAssociatedSecondLevel() {
$this->markTestIncomplete('Need to revisit once models work again.');

$data = array(
'ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
'ValidateItem' => array('name' => 'Item')
);

$result = $this->ValidateUser->create($data);
$this->assertFalse(empty($result));
$this->assertFalse($this->ValidateUser->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());

$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->error(
'ValidateUser.email', 'Invalid email', array('wrap' => false)
);
$this->assertEquals('Invalid email', $result);

$result = $this->Form->error(
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
);
$this->assertEquals('Invalid name', $result);

$result = $this->Form->error(
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
);

$result = $this->Form->error(
'ValidateItem.description', 'Invalid description', array('wrap' => false)
);
$this->assertEquals('Invalid description', $result);

unset($this->ValidateUser->ValidateProfile->ValidateItem);
unset($this->ValidateUser->ValidateProfile);
unset($this->ValidateUser);
TableRegistry::get('Contacts', [
'className' => __NAMESPACE__ . '\ContactsTable'
]);
$inner = new Entity(['bar' => 'baz']);
$nested = new Entity(['foo' => $inner]);
$entity = new Entity(['nested' => $nested]);
$inner->errors('bar', ['not a valid one']);
$this->Form->create($entity, ['context' => ['table' => 'Contacts']]);
$result = $this->Form->error('nested.foo.bar');
$this->assertEquals('<div class="error-message">not a valid one</div>', $result);
}

/**
Expand Down

0 comments on commit c0faabb

Please sign in to comment.