PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/pago_orders/pago_twilio/vendor/twilio/sdk/tests/TwimlTest.php

https://gitlab.com/lankerd/paGO---Testing-Site
PHP | 377 lines | 321 code | 50 blank | 6 comment | 0 complexity | a4736d660b379db7308ba0e7fe7e10a6 MD5 | raw file
  1. <?php
  2. use \Mockery as m;
  3. require_once 'Twilio/Twiml.php';
  4. class TwimlTest extends PHPUnit_Framework_TestCase {
  5. function tearDown() {
  6. m::close();
  7. }
  8. function testEmptyResponse() {
  9. $r = new Services_Twilio_Twiml();
  10. $expected = '<Response></Response>';
  11. $this->assertXmlStringEqualsXmlString($expected, $r,
  12. "Should be an empty response");
  13. }
  14. public function testSayBasic() {
  15. $r = new Services_Twilio_Twiml();
  16. $r->say("Hello Monkey");
  17. $expected = '<Response><Say>Hello Monkey</Say></Response>';
  18. $this->assertXmlStringEqualsXmlString($expected, $r);
  19. }
  20. public function testSayLoopThree() {
  21. $r = new Services_Twilio_Twiml();
  22. $r->say("Hello Monkey", array("loop" => 3));
  23. $expected = '<Response><Say loop="3">Hello Monkey</Say></Response>';
  24. $this->assertXmlStringEqualsXmlString($expected, $r);
  25. }
  26. public function testSayLoopThreeWoman() {
  27. $r = new Services_Twilio_Twiml();
  28. $r->say("Hello Monkey", array("loop" => 3, "voice"=>"woman"));
  29. $expected = '<Response><Say loop="3" voice="woman">'
  30. . 'Hello Monkey</Say></Response>';
  31. $this->assertXmlStringEqualsXmlString($expected, $r);
  32. }
  33. public function testSayConvienceMethod() {
  34. $r = new Services_Twilio_Twiml();
  35. $r->say("Hello Monkey", array("language" => "fr"));
  36. $expected = '<Response><Say language="fr">'
  37. . 'Hello Monkey</Say></Response>';
  38. $this->assertXmlStringEqualsXmlString($expected, $r);
  39. }
  40. public function testSayUTF8() {
  41. $r = new Services_Twilio_Twiml();
  42. $r->say("é tü & må");
  43. $expected = '<Response><Say>'
  44. . '&#xE9; t&#xFC; &amp; m&#xE5;</Say></Response>';
  45. $this->assertXmlStringEqualsXmlString($expected, $r);
  46. }
  47. public function testSayNamedEntities() {
  48. $r = new Services_Twilio_Twiml();
  49. $r->say("&eacute; t&uuml; &amp; m&aring;");
  50. $expected = '<Response><Say>'
  51. . '&#xE9; t&#xFC; &amp; m&#xE5;</Say></Response>';
  52. $this->assertXmlStringEqualsXmlString($expected, $r);
  53. }
  54. public function testSayNumericEntities() {
  55. $r = new Services_Twilio_Twiml();
  56. $r->say("&#xE9; t&#xFC; &amp; m&#xE5;");
  57. $expected = '<Response><Say>'
  58. . '&#xE9; t&#xFC; &amp; m&#xE5;</Say></Response>';
  59. $this->assertXmlStringEqualsXmlString($expected, $r);
  60. }
  61. public function testPlayBasic() {
  62. $r = new Services_Twilio_Twiml();
  63. $r->play("hello-monkey.mp3");
  64. $expected = '<Response><Play>hello-monkey.mp3</Play></Response>';
  65. $this->assertXmlStringEqualsXmlString($expected, $r);
  66. }
  67. public function testPlayLoopThree() {
  68. $r = new Services_Twilio_Twiml();
  69. $r->play("hello-monkey.mp3", array("loop" => 3));
  70. $expected = '<Response><Play loop="3">'
  71. . 'hello-monkey.mp3</Play></Response>';
  72. $this->assertXmlStringEqualsXmlString($expected, $r);
  73. }
  74. public function testPlayConvienceMethod() {
  75. $r = new Services_Twilio_Twiml();
  76. $r->play("hello-monkey.mp3", array("loop" => 3));
  77. $expected = '<Response><Play loop="3">'
  78. . 'hello-monkey.mp3</Play></Response>';
  79. $this->assertXmlStringEqualsXmlString($expected, $r);
  80. }
  81. //Test Record Verb
  82. public function testRecord() {
  83. $r = new Services_Twilio_Twiml();
  84. $r->record();
  85. $expected = '<Response><Record></Record></Response>';
  86. $this->assertXmlStringEqualsXmlString($expected, $r);
  87. }
  88. public function testRecordActionMethod() {
  89. $r = new Services_Twilio_Twiml();
  90. $r->record(array("action" => "example.com", "method" => "GET"));
  91. $expected = '<Response><Record action="example.com" '
  92. . 'method="GET"></Record></Response>';
  93. $this->assertXmlStringEqualsXmlString($expected, $r);
  94. }
  95. public function testBooleanBecomesString() {
  96. $r = new Services_Twilio_Twiml();
  97. $r->record(array("transcribe" => true));
  98. $expected = '<Response><Record transcribe="true" '
  99. . '></Record></Response>';
  100. $this->assertXmlStringEqualsXmlString($expected, $r);
  101. }
  102. public function testRecordMaxLengthKeyTimeout(){
  103. $r = new Services_Twilio_Twiml();
  104. $r->record(array("timeout" => 4, "finishOnKey" => "#",
  105. "maxLength" => 30));
  106. $expected = '<Response><Record timeout="4" finishOnKey="#" '
  107. . 'maxLength="30"></Record></Response>';
  108. $this->assertXmlStringEqualsXmlString($expected, $r);
  109. }
  110. public function testRecordConvienceMethod(){
  111. $r = new Services_Twilio_Twiml();
  112. $r->record(array("transcribeCallback" => "example.com"));
  113. $expected = '<Response><Record '
  114. . 'transcribeCallback="example.com"></Record></Response>';
  115. $this->assertXmlStringEqualsXmlString($expected, $r);
  116. }
  117. public function testRecordAddAttribute(){
  118. $r = new Services_Twilio_Twiml();
  119. $r->record(array("foo" => "bar"));
  120. $expected = '<Response><Record foo="bar"></Record></Response>';
  121. $this->assertXmlStringEqualsXmlString($expected, $r);
  122. }
  123. //Test Redirect Verb
  124. public function testRedirect() {
  125. $r = new Services_Twilio_Twiml();
  126. $r->redirect();
  127. $expected = '<Response><Redirect></Redirect></Response>';
  128. $this->assertXmlStringEqualsXmlString($expected, $r);
  129. }
  130. public function testAmpersandEscaping() {
  131. $r = new Services_Twilio_Twiml();
  132. $test_amp = "test&two&amp;three";
  133. $r->redirect($test_amp);
  134. $expected = '<Response><Redirect>' .
  135. 'test&amp;two&amp;three</Redirect></Response>';
  136. $this->assertXmlStringEqualsXmlString($expected, $r);
  137. }
  138. public function testRedirectConvience() {
  139. $r = new Services_Twilio_Twiml();
  140. $r->redirect();
  141. $expected = '<Response><Redirect></Redirect></Response>';
  142. $this->assertXmlStringEqualsXmlString($expected, $r);
  143. }
  144. public function testRedirectAddAttribute(){
  145. $r = new Services_Twilio_Twiml();
  146. $r->redirect(array("foo" => "bar"));
  147. $expected = '<Response><Redirect foo="bar"></Redirect></Response>';
  148. $this->assertXmlStringEqualsXmlString($expected, $r);
  149. }
  150. //Test Hangup Verb
  151. public function testHangup() {
  152. $r = new Services_Twilio_Twiml();
  153. $r->hangup();
  154. $expected = '<Response><Hangup></Hangup></Response>';
  155. $this->assertXmlStringEqualsXmlString($expected, $r);
  156. }
  157. public function testHangupConvience() {
  158. $r = new Services_Twilio_Twiml();
  159. $r->hangup();
  160. $expected = '<Response><Hangup></Hangup></Response>';
  161. $this->assertXmlStringEqualsXmlString($expected, $r);
  162. }
  163. public function testHangupAddAttribute(){
  164. $r = new Services_Twilio_Twiml();
  165. $r->hangup(array("foo" => "bar"));
  166. $expected = '<Response><Hangup foo="bar"></Hangup></Response>';
  167. $this->assertXmlStringEqualsXmlString($expected, $r);
  168. }
  169. //Test Pause Verb
  170. public function testPause() {
  171. $r = new Services_Twilio_Twiml();
  172. $r->pause();
  173. $expected = '<Response><Pause></Pause></Response>';
  174. $this->assertXmlStringEqualsXmlString($expected, $r);
  175. }
  176. public function testPauseConvience() {
  177. $r = new Services_Twilio_Twiml();
  178. $r->pause();
  179. $expected = '<Response><Pause></Pause></Response>';
  180. $this->assertXmlStringEqualsXmlString($expected, $r);
  181. }
  182. public function testPauseAddAttribute(){
  183. $r = new Services_Twilio_Twiml();
  184. $r->pause(array("foo" => "bar"));
  185. $expected = '<Response><Pause foo="bar"></Pause></Response>';
  186. $this->assertXmlStringEqualsXmlString($expected, $r);
  187. }
  188. //Test Dial Verb
  189. public function testDial() {
  190. $r = new Services_Twilio_Twiml();
  191. $r->dial("1231231234");
  192. $expected = '<Response><Dial>1231231234</Dial></Response>';
  193. $this->assertXmlStringEqualsXmlString($expected, $r);
  194. }
  195. public function testDialConvience() {
  196. $r = new Services_Twilio_Twiml();
  197. $r->dial();
  198. $expected = '<Response><Dial></Dial></Response>';
  199. $this->assertXmlStringEqualsXmlString($expected, $r);
  200. }
  201. public function testDialAddNumber() {
  202. $r = new Services_Twilio_Twiml();
  203. $d = $r->dial();
  204. $d->number("1231231234");
  205. $expected = '<Response><Dial><Number>'
  206. . '1231231234</Number></Dial></Response>';
  207. $this->assertXmlStringEqualsXmlString($expected, $r);
  208. }
  209. public function testDialAddConference() {
  210. $r = new Services_Twilio_Twiml();
  211. $d = $r->dial();
  212. $d->conference("MyRoom");
  213. $expected = '<Response><Dial><Conference>'
  214. . 'MyRoom</Conference></Dial></Response>';
  215. $this->assertXmlStringEqualsXmlString($expected, $r);
  216. }
  217. public function testDialAddConferenceConvience() {
  218. $r = new Services_Twilio_Twiml();
  219. $d = $r->dial();
  220. $d->conference("MyRoom", array("startConferenceOnEnter" => "false"));
  221. $expected = '<Response><Dial><Conference startConferenceOnEnter='
  222. . '"false">MyRoom</Conference></Dial></Response>';
  223. $this->assertXmlStringEqualsXmlString($expected, $r);
  224. }
  225. public function testDialAddAttribute() {
  226. $r = new Services_Twilio_Twiml();
  227. $r->dial(array("foo" => "bar"));
  228. $expected = '<Response><Dial foo="bar"></Dial></Response>';
  229. $this->assertXmlStringEqualsXmlString($expected, $r);
  230. }
  231. //Test Gather Verb
  232. public function testGather() {
  233. $r = new Services_Twilio_Twiml();
  234. $r->gather();
  235. $expected = '<Response><Gather></Gather></Response>';
  236. $this->assertXmlStringEqualsXmlString($expected, $r);
  237. }
  238. public function testGatherMethodAction(){
  239. $r = new Services_Twilio_Twiml();
  240. $r->gather(array("action"=>"example.com", "method"=>"GET"));
  241. $expected = '<Response><Gather action="example.com" '
  242. . 'method="GET"></Gather></Response>';
  243. $this->assertXmlStringEqualsXmlString($expected, $r);
  244. }
  245. public function testGatherActionWithParams(){
  246. $r = new Services_Twilio_Twiml();
  247. $r->gather(array("action" => "record.php?action=recordPageNow"
  248. . "&id=4&page=3"));
  249. $expected = '<Response><Gather action="record.php?action='
  250. . 'recordPageNow&amp;id=4&amp;page=3"></Gather></Response>';
  251. $this->assertXmlStringEqualsXmlString($expected, $r);
  252. }
  253. public function testGatherNestedVerbs(){
  254. $r = new Services_Twilio_Twiml();
  255. $g = $r->gather(array("action"=>"example.com", "method"=>"GET"));
  256. $g->say("Hello World");
  257. $g->play("helloworld.mp3");
  258. $g->pause();
  259. $expected = '
  260. <Response>
  261. <Gather action="example.com" method="GET">
  262. <Say>Hello World</Say>
  263. <Play>helloworld.mp3</Play>
  264. <Pause></Pause>
  265. </Gather>
  266. </Response>';
  267. $this->assertXmlStringEqualsXmlString($expected, $r);
  268. }
  269. public function testGatherNestedVerbsConvienceMethods(){
  270. $r = new Services_Twilio_Twiml();
  271. $g = $r->gather(array("action"=>"example.com", "method"=>"GET"));
  272. $g->say("Hello World");
  273. $g->play("helloworld.mp3");
  274. $g->pause();
  275. $expected = '
  276. <Response>
  277. <Gather action="example.com" method="GET">
  278. <Say>Hello World</Say>
  279. <Play>helloworld.mp3</Play>
  280. <Pause></Pause>
  281. </Gather>
  282. </Response>';
  283. $this->assertXmlStringEqualsXmlString($expected, $r);
  284. }
  285. public function testGatherAddAttribute(){
  286. $r = new Services_Twilio_Twiml();
  287. $r->gather(array("foo" => "bar"));
  288. $expected = '<Response><Gather foo="bar"></Gather></Response>';
  289. $this->assertXmlStringEqualsXmlString($expected, $r);
  290. }
  291. public function testSms() {
  292. $r = new Services_Twilio_Twiml();
  293. $r->sms("Hello World");
  294. $expected = '<Response><Sms>Hello World</Sms></Response>';
  295. $this->assertXmlStringEqualsXmlString($expected, $r);
  296. }
  297. public function testSmsConvience() {
  298. $r = new Services_Twilio_Twiml();
  299. $r->sms("Hello World");
  300. $expected = '<Response><Sms>Hello World</Sms></Response>';
  301. $this->assertXmlStringEqualsXmlString($expected, $r);
  302. }
  303. public function testSmsAddAttribute() {
  304. $r = new Services_Twilio_Twiml();
  305. $r->sms(array("foo" => "bar"));
  306. $expected = '<Response><Sms foo="bar"></Sms></Response>';
  307. $this->assertXmlStringEqualsXmlString($expected, $r);
  308. }
  309. public function testReject() {
  310. $r = new Services_Twilio_Twiml();
  311. $r->reject();
  312. $expected = '<Response><Reject></Reject></Response>';
  313. $this->assertXmlStringEqualsXmlString($expected, $r);
  314. }
  315. function testGeneration() {
  316. $r = new Services_Twilio_Twiml();
  317. $r->say('hello');
  318. $r->dial()->number('123', array('sendDigits' => '456'));
  319. $r->gather(array('timeout' => 15));
  320. $doc = simplexml_load_string($r);
  321. $this->assertEquals('Response', $doc->getName());
  322. $this->assertEquals('hello', (string) $doc->Say);
  323. $this->assertEquals('456', (string) $doc->Dial->Number['sendDigits']);
  324. $this->assertEquals('123', (string) $doc->Dial->Number);
  325. $this->assertEquals('15', (string) $doc->Gather['timeout']);
  326. }
  327. }