Skip to content

Commit

Permalink
Adding failing tests for ticket #3873
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 5, 2014
1 parent c854e1f commit 9b20a21
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -2083,6 +2083,32 @@ public function testAfterValidate() {
$this->assertEquals(['Not good'], $entity->errors('username'));
}

/**
* Tests using a custom validation object when saving and saving associations
*
* @return void
*/
public function testSaveWithDifferentValidatorAndAssociations() {
$entity = new \Cake\ORM\Entity([
'title' => 'foo',
'body' => 'bar',
'author' => new \Cake\ORM\Entity([
'name' => 'Susan'
])
]);
$table = TableRegistry::get('articles');
$table->belongsTo('authors');
$validator = (new Validator)->validatePresence('body');
$table->validator('custom', $validator);

$validator2 = (new Validator)->validatePresence('thing');
$table->authors->validator('default', $validator2);
$this->assertFalse($table->save($entity, ['validate' => 'custom']));
$this->assertNotEmpty($entity->author->errors('thing'));

$this->assertSame($entity, $table->save($entity), 'default was not used');
}

/**
* Test magic findByXX method.
*
Expand Down

0 comments on commit 9b20a21

Please sign in to comment.