(NFC) CRM-20238 Add in tests of the ProcessInbound function for SMS and replace depri...
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 14 May 2017 21:31:43 +0000 (07:31 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 14 May 2017 21:43:42 +0000 (07:43 +1000)
Rename test functions and extend the NoTo test

CRM/SMS/Provider.php
tests/phpunit/CRM/SMS/ProviderTest.php [new file with mode: 0644]

index 17a3baa2dd0ce2490f84a279aa0b135b9ead8d8f..9d914dce0d9cfcbcbb9f8041b77d1f9afbd15536 100644 (file)
@@ -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 (file)
index 0000000..217c071
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+/**
+ *  Test CRM_SMS_Provider functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_Contribution
+ * @group headless
+ */
+class CRM_SMS_ProviderTest extends CiviUnitTestCase {
+
+  /**
+   * Set Up Funtion
+   */
+  public function setUp() {
+    parent::setUp();
+    $option = $this->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);
+  }
+
+}