diff --git a/src/mg/PAGI/Node/NodeController.php b/src/mg/PAGI/Node/NodeController.php index 84c31b8..11ccb26 100644 --- a/src/mg/PAGI/Node/NodeController.php +++ b/src/mg/PAGI/Node/NodeController.php @@ -84,12 +84,14 @@ class NodeController */ public function jumpTo($name) { - if (!isset($this->nodes[$name])) { - throw new NodeException("Unknown node: $name"); - } // Cant make this recursive because php does not support tail // recursion optimization. while($name !== false) { + + if (!isset($this->nodes[$name])) { + throw new NodeException("Unknown node: '$name''"); + } + $node = $this->nodes[$name]; $this->logDebug("Running $name"); $node->run(); diff --git a/test/node/Test_NodeController.php b/test/node/Test_NodeController.php index 29b2a2a..57db5b4 100644 --- a/test/node/Test_NodeController.php +++ b/test/node/Test_NodeController.php @@ -85,15 +85,53 @@ function (Node $node) use ($object) { $this->assertFalse($object->flag); } - /** - * @test - * @expectedException PAGI\Node\Exception\NodeException - */ - public function cannot_jump_to_unknown_node() - { - $controller = $this->createNodeController(__METHOD__); - $controller->jumpTo(__METHOD__); - } + /** + * @test + * @expectedException PAGI\Node\Exception\NodeException + */ + public function cannot_jump_to_unknown_node() + { + $controller = $this->createNodeController(__METHOD__); + $controller->jumpTo(__METHOD__); + } + + /** + * @test + * @expectedException PAGI\Node\Exception\NodeException + */ + public function cannot_jump_to_unknown_childnode() + { + $controller = $this->createNodeController(__METHOD__); + + $node = $controller->register(__METHOD__ . 'node'); + + $controller->registerResult($node->getName()) + ->jumpAfterEval(function (Node $node) + { + return 'def'; + }); + + $controller->jumpTo($node->getName()); + } + + /** + * @test + * @expectedException PAGI\Node\Exception\NodeException + */ + public function cannot_jump_to_empty_childnode() + { + $controller = $this->createNodeController(__METHOD__); + + $node = $controller->register(__METHOD__ . 'node'); + + $controller->registerResult($node->getName()) + ->jumpAfterEval(function (Node $node) + { + // do nothing, happends when we don't read the docs! + }); + + $controller->jumpTo($node->getName()); + } /** * @test @@ -150,26 +188,26 @@ function (Node $node) use ($object) { */ public function can_jump_after_evaluation() { - $object = new stdClass; - $object->flag = false; - - $this->client->onCreateNode(__METHOD__); - $this->client->onCreateNode('can_jump_after_evaluation2'); - - $controller = $this->createNodeController(__METHOD__); - $controller->registerResult(__METHOD__) + $object = new stdClass; + $object->flag = false; + + $this->client->onCreateNode(__METHOD__); + $this->client->onCreateNode('can_jump_after_evaluation2'); + + $controller = $this->createNodeController(__METHOD__); + $controller->registerResult(__METHOD__) ->onComplete()->jumpAfterEval(function (Node $node) { return 'can_jump_after_evaluation2'; - }); - $controller->registerResult('can_jump_after_evaluation2')->onComplete()->execute( - function (Node $node) use ($object) { - $object->flag = true; - } - ); - $controller->register(__METHOD__)->saySound('test'); - $controller->register('can_jump_after_evaluation2')->saySound('test2'); - $controller->jumpTo(__METHOD__); - $this->assertTrue($object->flag); + }); + $controller->registerResult('can_jump_after_evaluation2')->onComplete()->execute( + function (Node $node) use ($object) { + $object->flag = true; + } + ); + $controller->register(__METHOD__)->saySound('test'); + $controller->register('can_jump_after_evaluation2')->saySound('test2'); + $controller->jumpTo(__METHOD__); + $this->assertTrue($object->flag); } /**