Skip to content

Commit

Permalink
Adding tests for saveStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 18, 2013
1 parent ae6bf52 commit 1fec962
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cake/ORM/Association/BelongsToMany.php
Expand Up @@ -319,7 +319,7 @@ public function saveStrategy($strategy = null) {
$msg = __d('cake_dev', 'Invalid save strategy "%s"', $strategy);
throw new \InvalidArgumentException($msg);
}
return $this->_strategy = $strategy;
return $this->_saveStrategy = $strategy;
}

/**
Expand Down
35 changes: 35 additions & 0 deletions Cake/Test/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -160,6 +160,41 @@ public function testJunctionWithDefaultTableName() {
$this->assertEquals('tags_articles', $junction->table());
}

/**
* Tests saveStrategy
*
* @return void
*/
public function testSaveStrategy() {
$assoc = new BelongsToMany('Test');
$this->assertEquals(BelongsToMany::SAVE_APPEND, $assoc->saveStrategy());
$assoc->saveStrategy(BelongsToMany::SAVE_REPLACE);
$this->assertEquals(BelongsToMany::SAVE_REPLACE, $assoc->saveStrategy());
$assoc->saveStrategy(BelongsToMany::SAVE_APPEND);
$this->assertEquals(BelongsToMany::SAVE_APPEND, $assoc->saveStrategy());
}

/**
* Tests that it is possible to pass the save strategy in the constructor
*
* @return void
*/
public function testSaveStrategyInOptions() {
$assoc = new BelongsToMany('Test', ['saveStrategy' => BelongsToMany::SAVE_REPLACE]);
$this->assertEquals(BelongsToMany::SAVE_REPLACE, $assoc->saveStrategy());
}

/**
* Tests that passing an invalid strategy will throw an exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid save strategy "depsert"
* @return void
*/
public function testSaveStrategyInvalid() {
$assoc = new BelongsToMany('Test', ['saveStrategy' => 'depsert']);
}

/**
* Tests that the correct join and fields are attached to a query depending on
* the association config
Expand Down

0 comments on commit 1fec962

Please sign in to comment.