Skip to content

Commit

Permalink
DX-2335 XML Encoding Test Updates (#45)
Browse files Browse the repository at this point in the history
* Fixed double-encoding of attributes, and encoded element contents.

* DX-2335 XML Encoding Test Updates

Co-authored-by: Joel Stein <[email protected]>
  • Loading branch information
ckoegel and joelstein authored Dec 16, 2021
1 parent 382e650 commit f5647a1
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/Voice/Bxml/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public function fallbackPassword($fallbackPassword) {
}

public function toBxml($doc) {
$element = $doc->createElement("Bridge", $this->targetCall);
$element = $doc->createElement("Bridge");

$element->appendChild($doc->createTextNode($this->targetCall));

if(isset($this->bridgeCompleteUrl)) {
$element->setAttribute("bridgeCompleteUrl", $this->bridgeCompleteUrl);
Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/Conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public function fallbackPassword($fallbackPassword) {
}

public function toBxml($doc) {
$element = $doc->createElement("Conference", $this->conferenceName);
$element = $doc->createElement("Conference");

$element->appendChild($doc->createTextNode($this->conferenceName));

if(isset($this->username)) {
$element->setattribute("username", $this->username);
Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ public function fallbackPassword($fallbackPassword) {
}

public function toBxml($doc) {
$element = $doc->createElement("PhoneNumber", $this->phoneNumber);
$element = $doc->createElement("PhoneNumber");

$element->appendChild($doc->createTextNode($this->phoneNumber));

if(isset($this->username)) {
$element->setAttribute("username", $this->username);
Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/PlayAudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function password($password) {
}

public function toBxml($doc) {
$element = $doc->createElement("PlayAudio", $this->url);
$element = $doc->createElement("PlayAudio");

$element->appendChild($doc->createTextNode($this->url));

if(isset($this->username)) {
$element->setAttribute("username", $this->username);
Expand Down
5 changes: 0 additions & 5 deletions src/Voice/Bxml/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public function __construct() {
* @param Verb $verb The verb to add to the list
*/
public function addVerb($verb) {
foreach($verb as $key => $value) { // encodes any verb attributes of type string to avoid php character encoding bug
if(gettype($value) == "string") {
$verb->$key = htmlspecialchars($value, ENT_XML1, 'UTF-8');
}
}
array_push($this->verbs, $verb);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/SendDtmf.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function toneInterval($toneInterval) {
}

public function toBxml($doc) {
$element = $doc->createElement("SendDtmf", $this->digits);
$element = $doc->createElement("SendDtmf");

$element->appendChild($doc->createTextNode($this->digits));

if(isset($this->toneDuration)) {
$element->setattribute("toneDuration", $this->toneDuration);
Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/SipUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public function fallbackPassword($fallbackPassword) {
}

public function toBxml($doc) {
$element = $doc->createElement("SipUri", $this->sip);
$element = $doc->createElement("SipUri");

$element->appendChild($doc->createTextNode($this->sip));

if(isset($this->username)) {
$element->setAttribute("username", $this->username);
Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/SpeakSentence.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function gender($gender) {
}

public function toBxml($doc) {
$element = $doc->createElement("SpeakSentence", $this->sentence);
$element = $doc->createElement("SpeakSentence");

$element->appendChild($doc->createTextNode($this->sentence));

if(isset($this->locale)) {
$element->setAttribute("locale", $this->locale);
Expand Down
4 changes: 3 additions & 1 deletion src/Voice/Bxml/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function __construct($tag) {
}

public function toBxml($doc) {
$element = $doc->createElement("Tag", $this->tag);
$element = $doc->createElement("Tag");

$element->appendChild($doc->createTextNode($this->tag));

return $element;
}
Expand Down
34 changes: 34 additions & 0 deletions tests/BxmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ public function testGatherNoNestedTag() {
$this->assertEquals($expectedXml, $responseXml);
}

public function testGatherEncodedURL() {
$gather = new BandwidthLib\Voice\Bxml\Gather();
$gather->gatherUrl("https://test.com?param1=test1&param2=test2");
$gather->gatherMethod("GET");
$gather->username("user");
$gather->password("pass");
$gather->tag("tag");
$gather->terminatingDigits("123");
$gather->maxDigits(3);
$gather->interDigitTimeout(4);
$gather->firstDigitTimeout(5);
$gather->repeatCount(3);
$gather->gatherFallbackUrl("https://test.com");
$gather->gatherFallbackMethod("GET");
$gather->fallbackUsername("fuser");
$gather->fallbackPassword("fpass");
$response = new BandwidthLib\Voice\Bxml\Response();
$response->addVerb($gather);
$expectedXml = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather username="user" password="pass" tag="tag" gatherUrl="https://test.com?param1=test1&amp;param2=test2" gatherMethod="GET" terminatingDigits="123" maxDigits="3" interDigitTimeout="4" firstDigitTimeout="5" repeatCount="3" gatherFallbackUrl="https://test.com" gatherFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass"/></Response>';
$responseXml = $response->toBxml();
$this->assertEquals($expectedXml, $responseXml);
}

public function testGatherNestedSpeakSentence() {
$gather = new BandwidthLib\Voice\Bxml\Gather();
$speakSentence = new BandwidthLib\Voice\Bxml\SpeakSentence("Test");
Expand Down Expand Up @@ -210,6 +233,17 @@ public function testPlayAudio() {
$this->assertEquals($expectedXml, $responseXml);
}

public function testPlayAudioEncodedURL() {
$playAudio = new BandwidthLib\Voice\Bxml\PlayAudio("https://test.com?param1=test1&param2=test2");
$playAudio->username("user");
$playAudio->password("pass");
$response = new BandwidthLib\Voice\Bxml\Response();
$response->addVerb($playAudio);
$expectedXml = '<?xml version="1.0" encoding="UTF-8"?><Response><PlayAudio username="user" password="pass">https://test.com?param1=test1&amp;param2=test2</PlayAudio></Response>';
$responseXml = $response->toBxml();
$this->assertEquals($expectedXml, $responseXml);
}

public function testTransfer() {
$number1 = new BandwidthLib\Voice\Bxml\PhoneNumber("+17777777777");
$number1->transferAnswerUrl("https://test.com");
Expand Down

0 comments on commit f5647a1

Please sign in to comment.