Skip to content

Commit

Permalink
Add existsIn test: new Entity with not dirty field
Browse files Browse the repository at this point in the history
  • Loading branch information
raul338 committed May 8, 2016
1 parent c7c3ca6 commit edb4ac7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/TestCase/ORM/RulesCheckerIntegrationTest.php
Expand Up @@ -29,7 +29,7 @@ class RulesCheckerIntegrationTest extends TestCase
*
* @var array
*/
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags'];
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags', 'core.categories'];

/**
* Tear down
Expand Down Expand Up @@ -433,6 +433,29 @@ public function testExistsInNullValue()
$this->assertEquals([], $entity->errors('author_id'));
}

/**
* Test ExistsIn on not dirty field in new Entity
*
* @return
*/
public function testExistsInNotNullValue()
{
$entity = new Entity([
'name' => 'A Category',
]);

$table = TableRegistry::get('Categories');
$table->belongsTo('Categories', [
'foreignKey' => 'parent_id',
'bindingKey' => 'id',
]);
$rules = $table->rulesChecker();
$rules->add($rules->existsIn('parent_id', 'Categories'));

$this->assertFalse($table->save($entity));
$this->assertEquals(['_existsIn' => 'This value does not exist'], $entity->errors('parent_id'));
}

/**
* Tests exists in uses the bindingKey of the association
*
Expand Down

0 comments on commit edb4ac7

Please sign in to comment.