PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/OpenVBX/tests/applets/voicemailGroupSayTest.php

http://github.com/twilio/OpenVBX
PHP | 81 lines | 62 code | 15 blank | 4 comment | 0 complexity | ac689e6e69d5ccab48d7e13fd2f1f8db MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. <?php
  2. include_once dirname(__FILE__).'/../CIUnit.php';
  3. class voicemailGroupSayTest extends OpenVBX_Applet_TestCase
  4. {
  5. private $group_id = 1;
  6. private $prompt_message = 'I am group email. Please leave a message.';
  7. public function setUp()
  8. {
  9. parent::setUp();
  10. $this->setFlow(array(
  11. 'id' => 1,
  12. 'user_id' => 1,
  13. 'created' => NULL,
  14. 'updated' => NULL,
  15. 'data' => '{"start":{"name":"Call Start","data":{"next":"start/f274cd"},"id":"start","type":"standard---start"},"f274cd":{"name":"Voicemail","data":{"prompt_say":"'.$this->prompt_message.'","prompt_play":"","prompt_mode":"say","prompt_tag":"global","number":"","library":"","permissions_id":"'.$this->group_id.'","permissions_type":"group"},"id":"f274cd","type":"standard---voicemail"}}',
  16. 'sms_data' => NULL,
  17. 'tenant_id' => 1
  18. ));
  19. // set up our request
  20. $this->setPath('/twiml/applet/voice/1/f1e974');
  21. $this->setRequestMethod('POST');
  22. // prepare the header token for request validation
  23. $this->setRequestToken();
  24. }
  25. public function tearDown()
  26. {
  27. $this->CI->db->truncate('group_messages');
  28. $this->CI->db->truncate('group_annotations');
  29. $this->CI->db->truncate('user_messages');
  30. $this->CI->db->truncate('messages');
  31. parent::tearDown();
  32. }
  33. public function testVoicemailGroupPrompt()
  34. {
  35. ob_start();
  36. $this->CI->voice(1, 'f274cd');
  37. $out = ob_get_clean();
  38. $xml = simplexml_load_string($out);
  39. $this->assertInstanceOf('SimpleXMLElement', $xml);
  40. // this regex match is cheap, need better reg-fu to match possible
  41. // language and voice attributes that could appear in any order
  42. $this->assertRegExp('|(<Say(.*?)>'.$this->prompt_message.'</Say>)|', $out);
  43. }
  44. public function testVoicemailGroupMessage()
  45. {
  46. $message_data = array(
  47. 'CallSid' => 'CA123',
  48. 'From' => '+15148675309',
  49. 'To' => '+13038675309',
  50. 'RecordingUrl' => 'http://foo.com/my/group_recording.wav',
  51. 'RecordingDuration' => 10
  52. );
  53. $this->setRequest($message_data);
  54. ob_start();
  55. $this->CI->voice(1, 'f274cd');
  56. $out = ob_get_clean();
  57. $result = $this->CI->db->get_where('messages', array('content_url' => $message_data['RecordingUrl']))->result();
  58. $this->assertEquals(1, count($result));
  59. $message = current($result);
  60. $this->assertEquals($message_data['CallSid'], $message->call_sid);
  61. $this->assertEquals($message_data['From'], $message->caller);
  62. $this->assertEquals($message_data['To'], $message->called);
  63. $this->assertEquals($message_data['RecordingUrl'], $message->content_url);
  64. $this->assertEquals($message_data['RecordingDuration'], $message->size);
  65. }
  66. }