From 1370cab4fc85a0bf2cf9a0f2a231fc481f6f0b34 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 15 May 2017 07:31:43 +1000 Subject: [PATCH] (NFC) CRM-20238 Add in tests of the ProcessInbound function for SMS and replace depricated getValue function with the getKey as recommended Rename test functions and extend the NoTo test --- CRM/SMS/Provider.php | 2 +- tests/phpunit/CRM/SMS/ProviderTest.php | 93 ++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/SMS/ProviderTest.php diff --git a/CRM/SMS/Provider.php b/CRM/SMS/Provider.php index 17a3baa2dd..9d914dce0d 100644 --- a/CRM/SMS/Provider.php +++ b/CRM/SMS/Provider.php @@ -246,7 +246,7 @@ INNER JOIN civicrm_mailing_job mj ON mj.mailing_id = m.id AND mj.id = %1"; if ($fromContactID) { $actStatusIDs = array_flip(CRM_Core_OptionGroup::values('activity_status')); - $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Inbound SMS', 'name'); + $activityTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Inbound SMS'); // note: lets not pass status here, assuming status will be updated by callback $activityParams = array( diff --git a/tests/phpunit/CRM/SMS/ProviderTest.php b/tests/phpunit/CRM/SMS/ProviderTest.php new file mode 100644 index 0000000000..217c071ba2 --- /dev/null +++ b/tests/phpunit/CRM/SMS/ProviderTest.php @@ -0,0 +1,93 @@ +callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1)); + $this->option_value = $option['id']; + } + + /** + * Clean up after each test. + */ + public function tearDown() { + parent::tearDown(); + $this->quickCleanup(array('civicrm_email', 'civicrm_phone', 'civicrm_activity', 'civicrm_activity_contact')); + $this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value)); + } + + /** + * CRM-20238 Add test of the processInbound function for SMSs + */ + public function testProcessInbound() { + $testSourceContact = $this->individualCreate(array('phone' => array(1 => array('phone_type_id' => 'Phone', 'location_type_id' => 'Home', 'phone' => '+61487654321')))); + $provider = new testSMSProvider(); + $result = $provider->processInbound('+61412345678', 'This is a test message', '+61487654321'); + $this->assertEquals('This is a test message', $result->details); + $this->assertEquals('+61412345678', $result->phone_number); + } + + /** + * CRM-20238 Add test of processInbound function where no To is passed into the function + */ + public function testProcessInboundNoTo() { + $provider = new testSMSProvider(); + $result = $provider->processInbound('+61412345678', 'This is a test message', NULL, '12345'); + $this->assertEquals('This is a test message', $result->details); + $this->assertEquals('+61412345678', $result->phone_number); + $this->assertEquals('12345', $result->result); + $activity = $this->callAPISuccess('activity', 'getsingle', array('id' => $result->id, 'return' => array('source_contact_id', 'target_contact_id', 'assignee_contact_id'))); + $contact = $this->callAPISuccess('contact', 'getsingle', array('phone' => '61412345678')); + // Verify that when no to is passed in by default the same contact is used for the source and target. + $this->assertEquals($contact['id'], $activity['source_contact_id']); + $this->assertEquals($contact['id'], $activity['target_contact_id'][0]); + } + +} + +/** + * Test SMS provider to allow for testing + */ +class testSMSProvider extends CRM_SMS_Provider { + + public function send($recipients, $header, $message, $dncID = NULL) { + parent::send($recipients, $header, $message, $dncID); + } + +} -- 2.25.1