forked from marcelog/PAGI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
255 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
<?php | ||
/** | ||
* This class will test the node mock | ||
* | ||
* PHP Version 5 | ||
* | ||
* @category Pagi | ||
* @package Test | ||
* @subpackage Mock | ||
* @author Marcelo Gornstein <[email protected]> | ||
* @license http://marcelog.github.com/ Apache License 2.0 | ||
* @version SVN: $Id$ | ||
* @link http://marcelog.github.com/ | ||
* | ||
* Copyright 2011 Marcelo Gornstein <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
use PAGI\Client\Impl\MockedClientImpl; | ||
use PAGI\Node\MockedNode; | ||
use PAGI\Node\Node; | ||
|
||
/** | ||
* This class will test the node mock | ||
* | ||
* PHP Version 5 | ||
* | ||
* @category Pagi | ||
* @package Test | ||
* @subpackage Mock | ||
* @author Marcelo Gornstein <[email protected]> | ||
* @license http://marcelog.github.com/ Apache License 2.0 | ||
* @link http://marcelog.github.com/ | ||
*/ | ||
class Test_MockedNode extends PHPUnit_Framework_TestCase | ||
{ | ||
private $properties = array(); | ||
private $client; | ||
|
||
public function setUp() | ||
{ | ||
$this->properties = array( | ||
'log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', | ||
); | ||
$this->client = new MockedClientImpl($this->properties); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_skip_input_on_uninterruptable_message() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->runWithInput('1') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->unInterruptablePrompts() | ||
->expectExactly(1) | ||
->saySound('prompt') | ||
->run() | ||
; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_consume_whitespace_as_no_input() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->runWithInput(' ') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectExactly(3) | ||
->saySound('prompt') | ||
->playOnNoInput('no-input') | ||
->run() | ||
; | ||
} | ||
|
||
/** | ||
* @test | ||
* @expectedException PAGI\Exception\MockedException | ||
*/ | ||
public function can_assert_wrong_state() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->assertCancelled() | ||
->runWithInput('*') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectExactly(1) | ||
->run() | ||
; | ||
} | ||
|
||
/** | ||
* @test | ||
* @expectedException PAGI\Exception\MockedException | ||
*/ | ||
public function can_assert_sound_not_played() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->assertSaySound('max-attempts', 1) | ||
->assertSaySound('no-input', 1) | ||
->assertSaySound('prompt', 99) | ||
->assertMaxInputAttemptsReached() | ||
->runWithInput('1') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectExactly(1) | ||
->validateInputWith( | ||
'fails', | ||
function (Node $node) { | ||
return false; | ||
}, | ||
'invalid' | ||
) | ||
->maxAttemptsForInput(3) | ||
->saySound('prompt') | ||
->playOnNoInput('no-input') | ||
->playOnMaxValidInputAttempts('max-attempts') | ||
->run() | ||
; | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function can_assert_play_sound() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->assertSaySound('max-attempts', 1) | ||
->assertSaySound('no-input', 1) | ||
->assertSaySound('prompt', 3) | ||
->assertMaxInputAttemptsReached() | ||
->runWithInput('1') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectExactly(1) | ||
->validateInputWith( | ||
'fails', | ||
function (Node $node) { | ||
return false; | ||
}, | ||
'invalid' | ||
) | ||
->maxAttemptsForInput(3) | ||
->saySound('prompt') | ||
->playOnNoInput('no-input') | ||
->playOnMaxValidInputAttempts('max-attempts') | ||
->run() | ||
; | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function can_assert_max_attempts_reached() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->assertMaxInputAttemptsReached() | ||
->runWithInput('111') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectExactly(1) | ||
->validateInputWith('fails', function (Node $node) { return false; }) | ||
->maxAttemptsForInput(3) | ||
->run() | ||
; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_assert_complete_node() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->assertComplete() | ||
->runWithInput('12345678901#') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectAtLeast(10) | ||
->endInputWith(Node::DTMF_HASH) | ||
->expectAtMost(12) | ||
->run() | ||
; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_assert_cancelled_node() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->assertCancelled() | ||
->runWithInput('*') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->cancelWith(Node::DTMF_STAR) | ||
->expectExactly(1) | ||
->run() | ||
; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_skip_input_on_non_interrupt_digit_input() | ||
{ | ||
$this->client | ||
->onCreateNode(__METHOD__) | ||
->runWithInput('X X') | ||
; | ||
$node = $this->client | ||
->createNode(__METHOD__) | ||
->expectExactly(1) | ||
->saySound('prompt') | ||
->run() | ||
; | ||
} | ||
} |