Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test for deeply nested validation errors when using entities

  • Loading branch information...
commit c0faabbbe45ae2a3893cd4c02d8f65838384611b 1 parent 2c35268
@lorenzo lorenzo authored
Showing with 10 additions and 46 deletions.
  1. +10 −46 tests/TestCase/View/Helper/FormHelperTest.php
View
56 tests/TestCase/View/Helper/FormHelperTest.php
@@ -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);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.