Skip to content

Commit edb4ac7

Browse files
committed
Add existsIn test: new Entity with not dirty field
1 parent c7c3ca6 commit edb4ac7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/TestCase/ORM/RulesCheckerIntegrationTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RulesCheckerIntegrationTest extends TestCase
2929
*
3030
* @var array
3131
*/
32-
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags'];
32+
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags', 'core.categories'];
3333

3434
/**
3535
* Tear down
@@ -433,6 +433,29 @@ public function testExistsInNullValue()
433433
$this->assertEquals([], $entity->errors('author_id'));
434434
}
435435

436+
/**
437+
* Test ExistsIn on not dirty field in new Entity
438+
*
439+
* @return
440+
*/
441+
public function testExistsInNotNullValue()
442+
{
443+
$entity = new Entity([
444+
'name' => 'A Category',
445+
]);
446+
447+
$table = TableRegistry::get('Categories');
448+
$table->belongsTo('Categories', [
449+
'foreignKey' => 'parent_id',
450+
'bindingKey' => 'id',
451+
]);
452+
$rules = $table->rulesChecker();
453+
$rules->add($rules->existsIn('parent_id', 'Categories'));
454+
455+
$this->assertFalse($table->save($entity));
456+
$this->assertEquals(['_existsIn' => 'This value does not exist'], $entity->errors('parent_id'));
457+
}
458+
436459
/**
437460
* Tests exists in uses the bindingKey of the association
438461
*

0 commit comments

Comments
 (0)