Skip to content

Commit

Permalink
bug TROPO-11236 tropo-webapi-php conference
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxli committed Jun 17, 2017
1 parent b8250d3 commit c4d2077
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 75 deletions.
135 changes: 76 additions & 59 deletions tests/ConferenceTest.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,94 @@
<?php
require_once 'PHPUnit/Framework.php';
use PHPUnit\Framework\TestCase;
require_once 'tropo.class.php';

class ConferenceTest extends PHPUnit_Framework_TestCase
{
public $partial;
public $expected;

public function ConferenceTest() {
$this->partial = '{"id":1234,"mute":false,"name":"foo","playTones":false,"terminator":"#"}';
$this->expected = '{"tropo":[{"conference":' . $this->partial . '}]}';
}

public function testCreateConferenceObject()
{
$conference = new Conference(1234, false, "foo", NULL, false, NULL, "#");
$this->assertEquals($this->partial, sprintf($conference));
}

public function testConferenceWithMinOptions() {
$tropo = new Tropo();
$params = array(
'name' => 'foo'
);
$tropo->conference("1234", $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234"}}]}');
}

public function testConferenceFromObject()
{
$conference = new Conference(1234, false, "foo", NULL, false, NULL, "#");
public function testConferenceWithAllOptions() {
$tropo = new Tropo();
$tropo->Conference($conference);
$this->assertEquals($this->expected, sprintf($tropo));
$allowSignals = array('exit', 'quit');
$params = array(
'allowSignals' => $allowSignals,
'interdigitTimeout' => 5.0,
'joinPrompt' => true,
'leavePrompt' => true,
'mute' => false,
'name' => 'foo',
'playTones' => true,
'required' => true,
'terminator' => '*',
'promptLogSecurity' => 'suppress',
);
$tropo->conference("1234", $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}');
}

public function testConferenceWithOptions()
{
$options = array(
'id' => 1234,
'mute' => 'false',
'name' => 'foo',
'playTones' => false,
'terminator' => '#'

public function testConferenceWithAllOptions1() {
$tropo = new Tropo();
$allowSignals = array('exit', 'quit');
$joinPrompt = array(
'value' => 'I am coming.',
'voice' => Voice::$US_English_female_allison
);
$leavePrompt = array(
'value' => 'I am leaving.',
'voice' => Voice::$US_English_female_allison
);
$params = array(
'allowSignals' => $allowSignals,
'interdigitTimeout' => 5.0,
'joinPrompt' => $joinPrompt,
'leavePrompt' => $leavePrompt,
'mute' => false,
'name' => 'foo',
'playTones' => true,
'required' => true,
'terminator' => '*',
'promptLogSecurity' => 'suppress',
);
$tropo->conference("1234", $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":{"value":"I am coming.","voice":"allison"},"leavePrompt":{"value":"I am leaving.","voice":"allison"}}}]}');
}

public function testCreateMinObject() {
$tropo = new Tropo();
$tropo->Conference($options);
$this->assertEquals($this->expected, sprintf($tropo));
$conference = new Conference("foo", "1234");
$tropo->conference($conference);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234"}}]}');
}

public function testConferenceWithOptionsInDifferentOrder()
{
$options = array(
'terminator' => '#',
'playTones' => false,
'id' => 1234,
'mute' => 'false',
'name' => 'foo'
);

public function testCreateObject1() {
$tropo = new Tropo();
$tropo->Conference($options);
$this->assertEquals($this->expected, sprintf($tropo));
$allowSignals = array('exit', 'quit');
$conference = new Conference("foo", "1234", false, null, true, true, "*", $allowSignals, 5.0, true, true, null, "suppress");
$tropo->conference($conference);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}');
}

public function testConferenceWithOnHandler() {
$say = new Say('Welcome to the conference. Press the pound key to exit.');
// Set up an On object to handle the event.
// Note - statically calling the properties of the Event object can be used
// as the first parameter to the On Object constructor.
$on = new On(Event::$join, NULL, $say);
$options = array(
'id' => 1234,
'mute' => 'false',
'terminator' => '#',
'playTones' => false,
'name' => 'foo',
'on' => $on
);

public function testCreateObject2() {
$tropo = new Tropo();
$tropo->Conference($options);
$this->assertEquals('{"tropo":[{"conference":{"id":1234,"mute":false,"on":{"event":"join","say":{"value":"Welcome to the conference. Press the pound key to exit."},"name":"foo","playTones":false,"terminator":"#"}}]}', sprintf($tropo));
$allowSignals = array('exit', 'quit');
$joinPrompt = array(
'value' => 'I am coming.',
'voice' => Voice::$US_English_female_allison
);
$leavePrompt = array(
'value' => 'I am leaving.',
'voice' => Voice::$US_English_female_allison
);
$conference = new Conference("foo", "1234", false, null, true, true, "*", $allowSignals, 5.0, $joinPrompt, $leavePrompt, null, "suppress");
$tropo->conference($conference);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":{"value":"I am coming.","voice":"allison"},"leavePrompt":{"value":"I am leaving.","voice":"allison"}}}]}');
}
}
?>
73 changes: 57 additions & 16 deletions tropo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,47 @@ public function call($call, Array $params=NULL) {
* @see https://www.tropo.com/docs/webapi/conference.htm
*/
public function conference($conference, Array $params=NULL) {
if(!is_object($conference)) {
$p = array('name', 'id', 'mute', 'on', 'playTones', 'required', 'terminator', 'allowSignals', 'interdigitTimeout', 'joinPrompt', 'leavePrompt', 'voice');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
if ($conference instanceof Conference) {

if(null === $conference->getId()) {
throw new Exception("Missing required property: 'id'");
}
if(null === $conference->getName()) {
throw new Exception("Missing required property: 'name'");
}

} elseif (is_string($conference) && ($conference !== '')) {

if (isset($params) && is_array($params)) {

if (array_key_exists('name', $params)) {
if (is_string($params["name"]) && ($params["name"] !=='')) {
$name = $params["name"];
} else {
throw new Exception("'name' must be is a string.");
}
} else {
throw new Exception("Missing required property: 'name'");
}

$p = array('name', 'mute', 'on', 'playTones', 'required', 'terminator', 'allowSignals', 'interdigitTimeout', 'joinPrompt', 'leavePrompt', 'voice', 'promptLogSecurity');
foreach ($p as $option) {
$$option = null;
if (array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$id = $conference;
$conference = new Conference($name, $id, $mute, $on, $playTones, $required, $terminator, $allowSignals, $interdigitTimeout, $joinPrompt, $leavePrompt, $voice, $promptLogSecurity);
} else {

throw new Exception("When Argument 1 passed to Tropo::conference() is a string, argument 2 passed to Tropo::conference() must be of the type array.");

}
$id = (empty($id) && !empty($conference)) ? $conference : $id;
$name = (empty($name)) ? (string)$id : $name;
$conference = new Conference($name, $id, $mute, $on, $playTones, $required, $terminator, $allowSignals, $interdigitTimeout, $joinPrompt, $leavePrompt, $voice);
} else {

throw new Exception("Argument 1 passed to Tropo::conference() must be a string or an instance of Conference.");

}
$this->conference = sprintf('%s', $conference);
}
Expand Down Expand Up @@ -1190,15 +1220,21 @@ class Conference extends BaseClass {
private $_id;
private $_mute;
private $_name;
private $_on;
private $_playTones;
private $_required;
private $_terminator;
private $_allowSignals;
private $_interdigitTimeout;
private $_joinPrompt;
private $_leavePrompt;
private $_voice;
private $_promptLogSecurity;

public function getName() {
return $this->_name;
}
public function getId() {
return $this->_id;
}


/**
Expand All @@ -1214,19 +1250,24 @@ class Conference extends BaseClass {
* @param string|array $allowSignals
* @param int $interdigitTimeout
*/
public function __construct($name, $id=NULL, $mute=NULL, On $on=NULL, $playTones=NULL, $required=NULL, $terminator=NULL, $allowSignals=NULL, $interdigitTimeout=NULL, $joinPrompt=NULL, $leavePrompt=NULL, $voice=NULL) {
public function __construct($name, $id, $mute=NULL, On $on=NULL, $playTones=NULL, $required=NULL, $terminator=NULL, $allowSignals=NULL, $interdigitTimeout=NULL, $joinPrompt=NULL, $leavePrompt=NULL, $voice=NULL, $promptLogSecurity=NULL) {
if(!isset($name)) {
throw new Exception("Missing required property: 'name'");
}
if(!isset($id)) {
throw new Exception("Missing required property: 'id'");
}
$this->_name = $name;
$this->_id = (string) $id;
$this->_mute = $mute;
$this->_on = isset($on) ? sprintf('%s', $on) : null;
$this->_playTones = $playTones;
$this->_required = $required;
$this->_terminator = $terminator;
$this->_allowSignals = $allowSignals;
$this->_interdigitTimeout = $interdigitTimeout;
$this->_joinPrompt = $joinPrompt;
$this->_leavePrompt = $leavePrompt;
$this->_voice = $voice;
$this->_promptLogSecurity = $promptLogSecurity;
}

/**
Expand All @@ -1235,14 +1276,14 @@ public function __construct($name, $id=NULL, $mute=NULL, On $on=NULL, $playTones
*/
public function __toString() {
$this->name = $this->_name;
if(isset($this->_id)) { $this->id = $this->_id; }
$this->id = $this->_id;
if(isset($this->_mute)) { $this->mute = $this->_mute; }
if(isset($this->_on)) { $this->on = $this->_on; }
if(isset($this->_playTones)) { $this->playTones = $this->_playTones; }
if(isset($this->_required)) { $this->required = $this->_required; }
if(isset($this->_terminator)) { $this->terminator = $this->_terminator; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
if(isset($this->_interdigitTimeout)) { $this->interdigitTimeout = $this->_interdigitTimeout; }
if(isset($this->_promptLogSecurity)) { $this->promptLogSecurity = $this->_promptLogSecurity; }
if(isset($this->_joinPrompt)) {
if($this->_joinPrompt == true || $this->_joinPrompt == false){
$this->joinPrompt = $this->_joinPrompt;
Expand Down

0 comments on commit c4d2077

Please sign in to comment.