|
|
@@ -890,9 +890,9 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
/**
|
|
|
* Tests new allowNullableNulls flag with author id set to null
|
|
|
*
|
|
|
- * @return
|
|
|
+ * @return void
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorIdNullA()
|
|
|
+ public function testExistsInAllowNullableNullsOn()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -913,9 +913,9 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
/**
|
|
|
* Tests new allowNullableNulls flag with author id set to null
|
|
|
*
|
|
|
- * @return
|
|
|
+ * @return void
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorIdNullB()
|
|
|
+ public function testExistsInAllowNullableNullsOff()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -938,7 +938,7 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorIdNullC()
|
|
|
+ public function testExistsInAllowNullableNullsDefaultValue()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -959,7 +959,7 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorIdNullD()
|
|
|
+ public function testExistsInAllowNullableNullsCustomMessage()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -980,35 +980,11 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests new allowNullableNulls flag with author id set to null
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorIdNullE()
|
|
|
- {
|
|
|
- $entity = new Entity([
|
|
|
- 'id' => 10,
|
|
|
- 'author_id' => null,
|
|
|
- 'site_id' => 1,
|
|
|
- 'name' => 'New Site Article without Author',
|
|
|
- ]);
|
|
|
- $table = $this->getTableLocator()->get('SiteArticles');
|
|
|
- $table->belongsTo('SiteAuthors');
|
|
|
- $rules = $table->rulesChecker();
|
|
|
-
|
|
|
- $rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
|
|
|
- 'allowNullableNulls' => true,
|
|
|
- 'message' => 'Niente'
|
|
|
- ]));
|
|
|
- $this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* Tests new allowNullableNulls flag with author id set to 1
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1A()
|
|
|
+ public function testExistsInAllowNullableNullsOnAllKeysSet()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -1029,7 +1005,7 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorIdB()
|
|
|
+ public function testExistsInAllowNullableNullsOffAllKeysSet()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -1050,28 +1026,7 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1C()
|
|
|
- {
|
|
|
- $entity = new Entity([
|
|
|
- 'id' => 10,
|
|
|
- 'author_id' => 1,
|
|
|
- 'site_id' => 1,
|
|
|
- 'name' => 'New Site Article with Author',
|
|
|
- ]);
|
|
|
- $table = $this->getTableLocator()->get('SiteArticles');
|
|
|
- $table->belongsTo('SiteAuthors');
|
|
|
- $rules = $table->rulesChecker();
|
|
|
-
|
|
|
- $rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors'));
|
|
|
- $this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Tests new allowNullableNulls flag with author id set to 1
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1E()
|
|
|
+ public function testExistsInAllowNullableNullsOnAllKeysCustomMessage()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
@@ -1090,15 +1045,15 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests new allowNullableNulls flag with author id set to 1
|
|
|
+ * Tests new allowNullableNulls flag with author id set to 99999999 (does not exist)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1F()
|
|
|
+ public function testExistsInAllowNullableNullsOnInvalidKey()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
- 'author_id' => 1,
|
|
|
+ 'author_id' => 99999999,
|
|
|
'site_id' => 1,
|
|
|
'name' => 'New Site Article with Author',
|
|
|
]);
|
|
|
@@ -1107,22 +1062,24 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
$rules = $table->rulesChecker();
|
|
|
|
|
|
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
|
|
|
- 'allowNullableNulls' => false,
|
|
|
- 'message' => 'will not error']));
|
|
|
- $this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
|
|
|
+ 'allowNullableNulls' => true,
|
|
|
+ 'message' => 'will error']));
|
|
|
+ $this->assertFalse($table->save($entity));
|
|
|
+ $this->assertEquals(['author_id' => ['_existsIn' => 'will error']], $entity->getErrors());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Tests new allowNullableNulls flag with author id set to 99999999 (does not exist)
|
|
|
+ * and site_id set to 99999999 (does not exist)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1G()
|
|
|
+ public function testExistsInAllowNullableNullsOnInvalidKeys()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
'author_id' => 99999999,
|
|
|
- 'site_id' => 1,
|
|
|
+ 'site_id' => 99999999,
|
|
|
'name' => 'New Site Article with Author',
|
|
|
]);
|
|
|
$table = $this->getTableLocator()->get('SiteArticles');
|
|
|
@@ -1137,16 +1094,16 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests new allowNullableNulls flag with author id set to 99999999 (does not exist)
|
|
|
+ * Tests new allowNullableNulls flag with author id set to 1 (does exist)
|
|
|
* and site_id set to 99999999 (does not exist)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1H()
|
|
|
+ public function testExistsInAllowNullableNullsOnInvalidKeySecond()
|
|
|
{
|
|
|
$entity = new Entity([
|
|
|
'id' => 10,
|
|
|
- 'author_id' => 99999999,
|
|
|
+ 'author_id' => 1,
|
|
|
'site_id' => 99999999,
|
|
|
'name' => 'New Site Article with Author',
|
|
|
]);
|
|
|
@@ -1162,28 +1119,41 @@ class RulesCheckerIntegrationTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests new allowNullableNulls flag with author id set to 1 (does exist)
|
|
|
- * and site_id set to 99999999 (does not exist)
|
|
|
+ * Tests new allowNullableNulls with saveMany
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public function testExistsInAllowNullableNullsWithAuthorId1I()
|
|
|
+ public function testExistsInAllowNullableNullsSaveMany()
|
|
|
{
|
|
|
- $entity = new Entity([
|
|
|
- 'id' => 10,
|
|
|
- 'author_id' => 1,
|
|
|
- 'site_id' => 99999999,
|
|
|
- 'name' => 'New Site Article with Author',
|
|
|
- ]);
|
|
|
+ $entities = [
|
|
|
+ new Entity([
|
|
|
+ 'id' => 1,
|
|
|
+ 'author_id' => null,
|
|
|
+ 'site_id' => 1,
|
|
|
+ 'name' => 'New Site Article without Author',
|
|
|
+ ]),
|
|
|
+ new Entity([
|
|
|
+ 'id' => 2,
|
|
|
+ 'author_id' => 1,
|
|
|
+ 'site_id' => 1,
|
|
|
+ 'name' => 'New Site Article with Author',
|
|
|
+ ]),
|
|
|
+ ];
|
|
|
$table = $this->getTableLocator()->get('SiteArticles');
|
|
|
$table->belongsTo('SiteAuthors');
|
|
|
$rules = $table->rulesChecker();
|
|
|
|
|
|
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
|
|
|
'allowNullableNulls' => true,
|
|
|
- 'message' => 'will error']));
|
|
|
- $this->assertFalse($table->save($entity));
|
|
|
- $this->assertEquals(['author_id' => ['_existsIn' => 'will error']], $entity->getErrors());
|
|
|
+ 'message' => 'will error with array_combine warning']));
|
|
|
+ $result = $table->saveMany($entities);
|
|
|
+ $this->assertCount(2, $result);
|
|
|
+
|
|
|
+ $this->assertInstanceOf(Entity::class, $result[0]);
|
|
|
+ $this->assertEmpty($result[0]->getErrors());
|
|
|
+
|
|
|
+ $this->assertInstanceOf(Entity::class, $result[1]);
|
|
|
+ $this->assertEmpty($result[1]->getErrors());
|
|
|
}
|
|
|
|
|
|
/**
|