diff --git a/tests/TestCase/ORM/RulesCheckerIntegrationTest.php b/tests/TestCase/ORM/RulesCheckerIntegrationTest.php index 7034221fc61..44690165ec7 100644 --- a/tests/TestCase/ORM/RulesCheckerIntegrationTest.php +++ b/tests/TestCase/ORM/RulesCheckerIntegrationTest.php @@ -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 @@ -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 *