Skip to content

Commit

Permalink
bug TROPO-12574 name shouldn't be a necessary parameter in WebAPI SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxli committed Jan 24, 2018
1 parent 63d3725 commit af88e52
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 406 deletions.
36 changes: 14 additions & 22 deletions tests/CallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ class CallTest extends PHPUnit_Framework_TestCase

public function testCallWithMinOptions() {
$tropo = new Tropo();
$params = array(
'name' => 'foo'
);
$tropo->call("sip:[email protected]:5678", $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:[email protected]:5678","name":"foo"}}]}');
$tropo->call("sip:[email protected]:5678");
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:[email protected]:5678"}}]}');
}

public function testCallWithExtraToOptiions() {
$tropo = new Tropo();
$call = array('sip:[email protected]:5678', 'sip:[email protected]:5678');
$params = array(
'name' => 'foo'
);
$tropo->call($call, $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"name":"foo"}}]}');
$tropo->call($call);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"]}}]}');
}

public function testCallWithAllOptions() {
Expand All @@ -36,7 +30,6 @@ public function testCallWithAllOptions() {
'from' => '3055551000',
'headers' => $headers,
'machineDetection' => false,
'name' => 'foo',
'network' => Network::$sip,
'required' => true,
'timeout' => 30.0,
Expand All @@ -46,7 +39,7 @@ public function testCallWithAllOptions() {
'label' => 'callLabel'
);
$tropo->call($call, $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
}

public function testCallWithAllOptions1() {
Expand All @@ -61,7 +54,6 @@ public function testCallWithAllOptions1() {
'from' => '3055551000',
'headers' => $headers,
'machineDetection' => 'For the most accurate results, the "introduction" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.',
'name' => 'foo',
'network' => Network::$sip,
'required' => true,
'timeout' => 30.0,
Expand All @@ -71,32 +63,32 @@ public function testCallWithAllOptions1() {
'label' => 'callLabel'
);
$tropo->call($call, $params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
}

public function testCreateMinObject() {
$tropo = new Tropo();
$call = new Call("sip:[email protected]:5678", null, null, null, null, null, null, null, null, null, null, "foo");
$call = new Call("sip:[email protected]:5678");
$tropo->call($call);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:[email protected]:5678","name":"foo"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:[email protected]:5678"}}]}');
}

public function testCreateObject1() {
$tropo = new Tropo();
$to = array("sip:[email protected]:5678", "sip:[email protected]:5678");
$call = new Call($to, null, null, null, null, null, null, null, null, null, null, "foo");
$call = new Call($to);
$tropo->call($call);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"name":"foo"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"]}}]}');
}

public function testCreateObject2() {
$tropo = new Tropo();
$to = array("sip:[email protected]:5678", "sip:[email protected]:5678");
$allowSignals = array('exit', 'quit');
$headers = array('foo' => 'bar', 'bling' => 'baz');
$call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, false, Voice::$US_English_female_allison, "foo", true, "http://192.168.26.203/result.php", "suppress", "callLabel");
$call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, false, Voice::$US_English_female_allison, null, true, "http://192.168.26.203/result.php", "suppress", "callLabel");
$tropo->call($call);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
}

public function testCreateObject3() {
Expand All @@ -105,9 +97,9 @@ public function testCreateObject3() {
$allowSignals = array('exit', 'quit');
$headers = array('foo' => 'bar', 'bling' => 'baz');
$machineDetection = 'For the most accurate results, the "introduction" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.';
$call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, $machineDetection, Voice::$US_English_female_allison, "foo", true, "http://192.168.26.203/result.php", "suppress", "callLabel");
$call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, $machineDetection, Voice::$US_English_female_allison, null, true, "http://192.168.26.203/result.php", "suppress", "callLabel");
$tropo->call($call);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:[email protected]:5678","sip:[email protected]:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}');
}
}
?>
25 changes: 10 additions & 15 deletions tests/ConferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ class ConferenceTest extends PHPUnit_Framework_TestCase

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

public function testConferenceWithAllOptions() {
Expand All @@ -23,14 +20,13 @@ public function testConferenceWithAllOptions() {
'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}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}');
}

public function testConferenceWithAllOptions1() {
Expand All @@ -50,29 +46,28 @@ public function testConferenceWithAllOptions1() {
'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"}}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"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();
$conference = new Conference("foo", "1234");
$conference = new Conference(null, "1234");
$tropo->conference($conference);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234"}}]}');
}

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

public function testCreateObject2() {
Expand All @@ -86,9 +81,9 @@ public function testCreateObject2() {
'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");
$conference = new Conference(null, "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"}}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"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"}}}]}');
}
}
?>
Loading

0 comments on commit af88e52

Please sign in to comment.