From a864098a9fddacbdbc77a352a161d1a799de3e75 Mon Sep 17 00:00:00 2001 From: Marcelo Gornstein Date: Fri, 23 Mar 2012 16:22:01 -0300 Subject: [PATCH] more tests for pagi nodes --- test/node/Test_Node.php | 101 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/test/node/Test_Node.php b/test/node/Test_Node.php index 924ac9c..a8b8282 100644 --- a/test/node/Test_Node.php +++ b/test/node/Test_Node.php @@ -77,6 +77,103 @@ protected function createNode($name = 'test') ); } + /** + * @test + */ + public function can_discard_input_on_pre_prompt_messages() + { + $validators = array( + 'validator1' => Node::createValidatorInfo( + function (Node $node) { + return true; + } + ), + 'validator2' => Node::createValidatorInfo( + function ($node) { + return $node->getInput() > 1; + }, + 'sound2' + ), + 'validator3' => Node::createValidatorInfo( + function ($node) { + return $node->getInput() > 2; + }, + array('sound2', 'sound3') + ) + ); + $node = $this->createNode(); + $node->getClient() + ->assert('streamFile', array('you-have', Node::DTMF_ANY)) + ->assert('streamFile', array('sound2', Node::DTMF_ANY)) + ->assert('streamFile', array('you-have', Node::DTMF_ANY)) + ->assert('streamFile', array('sound2', Node::DTMF_ANY)) + ->assert('streamFile', array('you-have', Node::DTMF_ANY)) + ->onStreamFile(true, '1') + ->onStreamFile(true, '1') + ->onStreamFile(true, '2') + ->onStreamFile(true, '2') + ->onStreamFile(true, '3') + ; + $node + ->saySound('you-have') + ->dontAcceptPrePromptInputAsInput() + ->expectExactly(1) + ->maxAttemptsForInput(5) + ->loadValidatorsFrom($validators) + ->run() + ; + $this->assertTrue($node->hasInput()); + $this->assertEquals($node->getInput(), '3'); + $this->assertTrue($node->isComplete()); + } + + /** + * @test + */ + public function can_accept_input_on_pre_prompt_messages() + { + $validators = array( + 'validator1' => Node::createValidatorInfo( + function (Node $node) { + return true; + } + ), + 'validator2' => Node::createValidatorInfo( + function ($node) { + return $node->getInput() > 1; + }, + 'sound2' + ), + 'validator3' => Node::createValidatorInfo( + function ($node) { + return $node->getInput() > 2; + }, + array('sound2', 'sound3') + ) + ); + $node = $this->createNode(); + $node->getClient() + ->assert('streamFile', array('you-have', Node::DTMF_ANY)) + ->assert('streamFile', array('sound2', Node::DTMF_ANY)) + ->assert('streamFile', array('sound2', Node::DTMF_ANY)) + ->assert('streamFile', array('sound3', Node::DTMF_ANY)) + ->onStreamFile(true, '1') + ->onStreamFile(true, '2') + ->onStreamFile(false) + ->onStreamFile(true, '3') + ; + $node + ->saySound('you-have') + ->expectExactly(1) + ->maxAttemptsForInput(5) + ->loadValidatorsFrom($validators) + ->run() + ; + $this->assertTrue($node->hasInput()); + $this->assertEquals($node->getInput(), '3'); + $this->assertTrue($node->isComplete()); + } + /** * @test */ @@ -302,6 +399,7 @@ public function can_play_on_max_attempts_reached() $this->assertTrue($node->maxInputsReached()); $this->assertEquals($node->getInput(), ''); $this->assertFalse($node->hasInput()); + $this->assertEquals($node->getTotalInputAttemptsUsed(), 2); } /** @@ -332,6 +430,7 @@ public function can_cancel_and_retry_input() $this->assertTrue($node->maxInputsReached()); $this->assertEquals($node->getInput(), ''); $this->assertFalse($node->hasInput()); + $this->assertEquals($node->getTotalInputAttemptsUsed(), 2); } /** @@ -359,6 +458,7 @@ public function can_cancel_without_retrying_input() $this->assertTrue($node->wasCancelled()); $this->assertEquals($node->getInput(), '123'); $this->assertTrue($node->hasInput()); + $this->assertEquals($node->getTotalInputAttemptsUsed(), 1); } /** @@ -384,6 +484,7 @@ public function can_play_on_no_input() $this->assertTrue($node->isTimeout()); $this->assertEquals($node->getInput(), ''); $this->assertFalse($node->hasInput()); + $this->assertEquals($node->getTotalInputAttemptsUsed(), 2); } /**