|
|
@@ -15,6 +15,7 @@
|
|
|
namespace Cake\Test\TestCase\ORM;
|
|
|
|
|
|
use Cake\ORM\Entity;
|
|
|
+use Cake\ORM\RulesChecker;
|
|
|
use Cake\ORM\TableRegistry;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
|
|
@@ -29,7 +30,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
|
|
|
@@ -461,6 +462,30 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test ExistsIn on a new entity that doesn't have the field populated.
|
|
|
+ *
|
|
|
+ * This use case is important for saving records and their
|
|
|
+ * associated belongsTo records in one pass.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExistsInNotNullValueNewEntity()
|
|
|
+ {
|
|
|
+ $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->assertTrue($table->checkRules($entity, RulesChecker::CREATE));
|
|
|
+ $this->assertEmpty($entity->errors('parent_id'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Tests exists in uses the bindingKey of the association
|
|
|
*
|
|
|
* @return
|