Skip to content

Commit

Permalink
Adding test to prove that fetched entities are marked as clean
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 26, 2013
1 parent 5dca57e commit 67571cf
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Cake/Test/TestCase/ORM/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,37 @@ public function testReciprocalBelongsToMany() {
]);
$result = $table->find('all')->contain(['tag'])->first();
$this->assertInstanceOf('TestApp\Model\Entity\Tag', $result->tags[0]);
$this->assertInstanceOf('TestApp\Model\Entity\ArticlesTag', $result->tags[0]->extraInfo);
$this->assertInstanceOf(
'TestApp\Model\Entity\ArticlesTag',
$result->tags[0]->extraInfo
);
}

/**
* Tests that recently fetched entities are always clean
*
* @return void
*/
public function testFindCleanEntities() {
$table = new \TestApp\Model\Repository\ArticleTable([
'connection' => $this->connection,
]);
$results = $table->find('all')->contain(['tag', 'author'])->toArray();
$this->assertCount(3, $results);
foreach ($results as $article) {
$this->assertFalse($article->dirty('id'));
$this->assertFalse($article->dirty('title'));
$this->assertFalse($article->dirty('author_id'));
$this->assertFalse($article->dirty('body'));
$this->assertFalse($article->dirty('published'));
$this->assertFalse($article->dirty('author'));
$this->assertFalse($article->author->dirty('id'));
$this->assertFalse($article->author->dirty('name'));
$this->assertFalse($article->dirty('tag'));
if ($article->tag) {
$this->assertFalse($article->tag[0]->extraInfo->dirty('tag_id'));
}
}
}

/**
Expand Down

0 comments on commit 67571cf

Please sign in to comment.