Merge pull request #2557 from rchavik/2.4-save-tree-invalid-scope

2.4 save tree invalid scope
This commit is contained in:
Mark Story 2013-12-27 07:17:52 -08:00
commit b682732c1e
2 changed files with 24 additions and 1 deletions

View file

@ -212,7 +212,7 @@ class TreeBehavior extends ModelBehavior {
'fields' => array($Model->primaryKey, $parent, $left, $right), 'recursive' => $recursive)
);
if ($values === false) {
if (empty($values)) {
return false;
}
list($node) = array_values($values);

View file

@ -130,6 +130,29 @@ class TreeBehaviorScopedTest extends CakeTestCase {
$this->assertEquals(11, $this->Tree->find('count'));
}
/**
* testSaveWithParentAndInvalidScope method
*
* Attempting to save an invalid data should not trigger an `Undefined offset`
* error
*
* @return void
*/
public function testSaveWithParentAndInvalidScope() {
$this->Tree = new FlagTree();
$this->Tree->order = null;
$data = $this->Tree->create(array(
'name' => 'Flag',
));
$tree = $this->Tree->save($data);
$this->Tree->Behaviors->load('Tree', array(
'scope' => array('FlagTree.flag' => 100)
));
$tree['FlagTree']['parent_id'] = 1;
$result = $this->Tree->save($tree);
$this->assertFalse($result);
}
/**
* testMoveUpWithScope method
*