Skip to content

Commit

Permalink
more tests for pagi nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelog committed Mar 23, 2012
1 parent 2790a0b commit a864098
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions test/node/Test_Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit a864098

Please sign in to comment.