Skip to content

Commit

Permalink
revert the throw thing
Browse files Browse the repository at this point in the history
we keep refactoring changes only
  • Loading branch information
quickapps authored and lorenzo committed Mar 29, 2014
1 parent 78bee17 commit 88430a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/Model/Behavior/TreeBehavior.php
Expand Up @@ -158,6 +158,7 @@ public function findChildren($query, $options) {
*
* @param integer|string $id The ID of the record to move
* @param integer|boolean $number How many places to move the node, or true to move to first position
* @throws \Cake\ORM\Error\RecordNotFoundException When node was not found
* @return boolean true on success, false on failure
*/
public function moveUp($id, $number = 1) {
Expand All @@ -175,7 +176,7 @@ public function moveUp($id, $number = 1) {
->first();

if (!$node) {
return false;
throw new \Cake\ORM\Error\RecordNotFoundException("Node \"{$id}\" was not found in the tree.");
}

if ($node->{$parent}) {
Expand Down Expand Up @@ -218,6 +219,7 @@ public function moveUp($id, $number = 1) {
*
* @param integer|string $id The ID of the record to move
* @param integer|boolean $number How many places to move the node or true to move to last position
* @throws \Cake\ORM\Error\RecordNotFoundException When node was not found
* @return boolean true on success, false on failure
*/
public function moveDown($id, $number = 1) {
Expand All @@ -235,7 +237,7 @@ public function moveDown($id, $number = 1) {
->first();

if (!$node) {
return false;
throw new \Cake\ORM\Error\RecordNotFoundException("Node \"{$id}\" was not found in the tree.");
}

if ($node->{$parent}) {
Expand Down
31 changes: 24 additions & 7 deletions tests/TestCase/Model/Behavior/TreeBehaviorTest.php
Expand Up @@ -172,9 +172,6 @@ public function testMoveUp() {
$this->assertFalse($this->table->moveUp(1, 0));
$this->assertFalse($this->table->moveUp(1, -10));

// move unexisting node
$this->assertFalse($table->moveUp(500, 1));

// move inner node
$result = $table->moveUp(3, 1);
$nodes = $table->find('children', ['for' => 1])->all();
Expand All @@ -194,6 +191,18 @@ public function testMoveUp() {
$this->assertEquals([8, 1, 6], $nodes->extract('id')->toArray());
}

/**
* Tests that moveUp() will throw an exception if the node was not found
*
* @expectedException \Cake\ORM\Error\RecordNotFoundException
* @return void
*/
public function testMoveUpException() {
$table = TableRegistry::get('MenuLinkTrees');
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
$table->moveUp(500, 1);
}

/**
* Tests the moveDown() method
*
Expand All @@ -211,15 +220,11 @@ public function testMoveDown() {
$this->assertFalse($this->table->moveUp(8, -10));

// move inner node
$nodeIds = [];
$result = $table->moveDown(2, 1);
$nodes = $table->find('children', ['for' => 1])->all();
$this->assertEquals([3, 4, 5, 2], $nodes->extract('id')->toArray());
$this->assertTrue($result);

// move unexisting node
$this->assertFalse($table->moveDown(500, 1));

// move leaf
$this->assertFalse( $table->moveDown(5, 1));

Expand All @@ -233,6 +238,18 @@ public function testMoveDown() {
$this->assertEquals([6, 8, 1], $nodes->extract('id')->toArray());
}

/**
* Tests that moveDown() will throw an exception if the node was not found
*
* @expectedException \Cake\ORM\Error\RecordNotFoundException
* @return void
*/
public function testMoveDownException() {
$table = TableRegistry::get('MenuLinkTrees');
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
$table->moveDown(500, 1);
}

/**
* Tests the recover function
*
Expand Down

0 comments on commit 88430a3

Please sign in to comment.