Skip to content
Permalink
Browse files

Adding one more test, with entities to be added in a replace operatio…

…n while the target table has no records
  • Loading branch information...
mylux committed Nov 2, 2015
1 parent 4bb24a9 commit 9a853a187a13a33a4631715aa26cdd49db0e7f25
Showing with 42 additions and 0 deletions.
  1. +42 −0 tests/TestCase/ORM/TableTest.php
@@ -4438,6 +4438,48 @@ public function testReplaceHasManyEmptyList()
$this->assertCount(0, $authors->Articles->findAllByAuthorId($author->id));
}
/**
* Integration test for replacing entities with HasMany and no already persisted entities. The transaction must be successfull.
* Replace operation should prevent considering 0 changed records an error when they are not found in the table
*
* @return void
*/
public function testReplaceHasManyNoPersistedEntities()
{
$authors = new Table([
'connection' => $this->connection,
'alias' => 'Authors',
'table' => 'authors',
]);
$authors->hasMany('Articles');
$author = $authors->newEntity(['name' => 'mylux']);
$author = $authors->save($author);
$newArticles = $authors->Articles->newEntities(
[
[
'title' => 'New bakery next corner',
'body' => 'They sell tastefull cakes'
],
[
'title' => 'Spicy cake recipe',
'body' => 'chocolate and peppers'
]
]
);
$authors->Articles->deleteAll(['1=1']);
$sizeArticles = count($newArticles);
$this->assertTrue($authors->Articles->link($author, $newArticles));
$this->assertEquals($authors->Articles->findAllByAuthorId($author->id)->count(), $sizeArticles);
$this->assertEquals(count($author->articles), $sizeArticles);
$this->assertTrue($authors->Articles->replace($author, $newArticles));
$this->assertCount($sizeArticles, $authors->Articles->findAllByAuthorId($author->id));
}
/**
* Integration test for replacing entities with HasMany.
*

0 comments on commit 9a853a1

Please sign in to comment.
You can’t perform that action at this time.