|
|
@@ -2778,6 +2778,72 @@ class TableTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test saveMany() with entities array
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSaveManyArray()
|
|
|
+ {
|
|
|
+ $entities = [
|
|
|
+ new Entity(['name' => 'admad']),
|
|
|
+ new Entity(['name' => 'dakota'])
|
|
|
+ ];
|
|
|
+
|
|
|
+ $table = TableRegistry::get('authors');
|
|
|
+ $result = $table->saveMany($entities);
|
|
|
+
|
|
|
+ $this->assertSame($entities, $result);
|
|
|
+ $this->assertTrue(isset($result[0]->id));
|
|
|
+ foreach ($entities as $entity) {
|
|
|
+ $this->assertFalse($entity->isNew());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test saveMany() with ResultSet instance
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSaveManyResultSet()
|
|
|
+ {
|
|
|
+ $table = TableRegistry::get('authors');
|
|
|
+
|
|
|
+ $entities = $table->find()
|
|
|
+ ->order(['id' => 'ASC'])
|
|
|
+ ->all();
|
|
|
+ $entities->first()->name = 'admad';
|
|
|
+
|
|
|
+ $result = $table->saveMany($entities);
|
|
|
+ $this->assertSame($entities, $result);
|
|
|
+
|
|
|
+ $first = $table->find()
|
|
|
+ ->order(['id' => 'ASC'])
|
|
|
+ ->first();
|
|
|
+ $this->assertSame('admad', $first->name);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test saveMany() with failed save
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSaveManyFailed()
|
|
|
+ {
|
|
|
+ $table = TableRegistry::get('authors');
|
|
|
+ $entities = [
|
|
|
+ new Entity(['name' => 'mark']),
|
|
|
+ new Entity(['name' => 'jose'])
|
|
|
+ ];
|
|
|
+ $entities[1]->errors(['name' => ['message']]);
|
|
|
+ $result = $table->saveMany($entities);
|
|
|
+
|
|
|
+ $this->assertFalse($result);
|
|
|
+ foreach ($entities as $entity) {
|
|
|
+ $this->assertTrue($entity->isNew());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test simple delete.
|
|
|
*
|
|
|
* @return void
|