Skip to content

Commit

Permalink
Split row creation and add comments to make tests more transparent.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndm2 authored and markstory committed Dec 31, 2016
1 parent 59b0506 commit f332556
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -2100,26 +2100,33 @@ public function testHasManyNonCascadingUnlinkDeleteUsesAssociationConditions()
'user_id' => 1,
'comment' => 'Second comment',
'published' => 'Y'
],
[
'user_id' => 1,
'comment' => 'Third comment',
'published' => 'N'
]
]
]);

$article = $Articles->save($article);
$this->assertNotEmpty($article);

$comment3 = $Comments->target()->newEntity([
'article_id' => $article->get('id'),
'user_id' => 1,
'comment' => 'Third comment',
'published' => 'N'
]);
$comment3 = $Comments->target()->save($comment3);
$this->assertNotEmpty($comment3);

$this->assertEquals(3, $Comments->target()->find()->where(['Comments.article_id' => $article->get('id')])->count());

unset($article->comments[1], $article->comments[2]);
unset($article->comments[1]);
$article->dirty('comments', true);

$article = $Articles->save($article);
$this->assertNotEmpty($article);

// Given the association condition of `'Comments.published' => 'Y'`,
// it is expected that only one the three linked comments are actually
// being deleted, as only one of them matches the association
// conditions.
$this->assertEquals(2, $Comments->target()->find()->where(['Comments.article_id' => $article->get('id')])->count());
}

Expand Down Expand Up @@ -2154,28 +2161,34 @@ public function testHasManyNonDependentNonCascadingUnlinkUpdateUsesAssociationCo
'title' => 'Second article',
'body' => 'Second article',
'published' => 'Y'
],
[
'title' => 'Third article',
'body' => 'Third article',
'published' => 'N'
]
]
]);

$author = $Authors->save($author);
$this->assertNotEmpty($author);

$article3 = $Articles->target()->newEntity([
'author_id' => $author->get('id'),
'title' => 'Third article',
'body' => 'Third article',
'published' => 'N'
]);
$article3 = $Articles->target()->save($article3);
$this->assertNotEmpty($article3);

$this->assertEquals(3, $Articles->target()->find()->where(['Articles.author_id' => $author->get('id')])->count());

$article2 = $author->articles[1];
$article3 = $author->articles[2];
unset($author->articles[1], $author->articles[2]);
unset($author->articles[1]);
$author->dirty('articles', true);

$author = $Authors->save($author);
$this->assertNotEmpty($author);

// Given the association condition of `'Articles.published' => 'Y'`,
// it is expected that only one the three linked articles are actually
// being unlinked (nulled), as only one of them matches the association
// conditions.
$this->assertEquals(2, $Articles->target()->find()->where(['Articles.author_id' => $author->get('id')])->count());
$this->assertNull($Articles->get($article2->get('id'))->get('author_id'));
$this->assertEquals($author->get('id'), $Articles->get($article3->get('id'))->get('author_id'));
Expand Down

0 comments on commit f332556

Please sign in to comment.