Skip to content

Commit

Permalink
Adding unit tests for BelongsToMany::save() when combined with the
Browse files Browse the repository at this point in the history
replace strategy
  • Loading branch information
lorenzo committed Dec 18, 2013
1 parent 1fec962 commit 2a12b22
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Cake/Test/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -1057,4 +1057,56 @@ public function testReplaceLinkSuccess() {
$this->assertFalse($entity->dirty('tags'));
}

/**
* Tests saving with replace strategy returning true
*
* @return void
*/
public function testSaveWithReplace() {
$assoc = $this->getMock(
'\Cake\ORM\Association\BelongsToMany',
['replaceLinks'],
['tags']
);
$entity = new Entity([
'id' =>1,
'tags' => [
new Entity(['name' => 'foo'])
]
]);

$options = ['foo' => 'bar'];
$assoc->saveStrategy(BelongsToMany::SAVE_REPLACE);
$assoc->expects($this->once())->method('replaceLinks')
->with($entity, $entity->tags, $options)
->will($this->returnValue(true));
$this->assertSame($entity, $assoc->save($entity, $options));
}

/**
* Tests saving with replace strategy returning true
*
* @return void
*/
public function testSaveWithReplaceReturnFalse() {
$assoc = $this->getMock(
'\Cake\ORM\Association\BelongsToMany',
['replaceLinks'],
['tags']
);
$entity = new Entity([
'id' =>1,
'tags' => [
new Entity(['name' => 'foo'])
]
]);

$options = ['foo' => 'bar'];
$assoc->saveStrategy(BelongsToMany::SAVE_REPLACE);
$assoc->expects($this->once())->method('replaceLinks')
->with($entity, $entity->tags, $options)
->will($this->returnValue(false));
$this->assertSame(false, $assoc->save($entity, $options));
}

}

0 comments on commit 2a12b22

Please sign in to comment.