Skip to content
Snippets Groups Projects
Commit e33c2ce7 authored by Eileen McNaughton's avatar Eileen McNaughton
Browse files

#2814 Fix activity:sendSMS to use renderTemplate

parent b8aa9d78
No related branches found
No related tags found
No related merge requests found
......@@ -1327,8 +1327,7 @@ WHERE entity_id =%1 AND entity_table = %2";
unset($tokenDetails["{$contactId}"]['phone_type_id']);
$contact = array_merge($contact, $tokenDetails["{$contactId}"]);
}
$tokenText = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $messageToken, FALSE, FALSE);
$tokenText = CRM_Utils_Token::replaceHookTokens($tokenText, $contact, $categories, FALSE, FALSE);
$tokenText = CRM_Core_BAO_MessageTemplate::renderTemplate(['messageTemplate' => ['msg_text' => $text], 'contactId' => $contactId, 'disableSmarty' => TRUE])['text'];
// Only send if the phone is of type mobile
if ($contact['phone_type_id'] == CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile')) {
......
......@@ -1378,6 +1378,8 @@ $text
}
/**
* Test successful SMS send.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
......@@ -1385,7 +1387,10 @@ $text
*/
public function testSendSmsMobilePhoneNumber(): void {
$sent = $this->createSendSmsTest(TRUE, 2);
$this->assertEquals(TRUE, $sent[0], "Expected sent should be true");
$this->assertEquals(TRUE, $sent[0]);
/* @var CiviTestSMSProvider $provider $provider['id']*/
$providerObj = CRM_SMS_Provider::singleton(['provider_id' => $this->ids['SmsProvider'][0]]);
$this->assertEquals('text Anthony', $providerObj->getSentMessage());
}
/**
......@@ -1423,7 +1428,7 @@ $text
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function createSendSmsTest(bool $expectSuccess = TRUE, int $phoneType = 0, bool $passPhoneTypeInContactDetails = FALSE, array $additionalContactParams = []): array {
$provider = civicrm_api3('SmsProvider', 'create', [
$this->ids['SmsProvider'][0] = civicrm_api3('SmsProvider', 'create', [
'name' => 'CiviTestSMSProvider',
'api_type' => 1,
'username' => 1,
......@@ -1433,9 +1438,9 @@ $text
'is_default' => 1,
'is_active' => 1,
'domain_id' => 1,
]);
])['id'];
$smsProviderParams['provider_id'] = $provider['id'];
$smsProviderParams['provider_id'] = $this->ids['SmsProvider'][0];
// Create a contact
$contactId = $this->individualCreate();
......@@ -1450,7 +1455,7 @@ $text
$contactIds[] = $contact['contact_id'];
}
$activityParams['sms_text_message'] = 'text';
$activityParams['sms_text_message'] = 'text {contact.first_name}';
$activityParams['activity_subject'] = 'subject';
// Get a "logged in" user to set as source of Sms.
......@@ -2663,7 +2668,8 @@ $textValue
$this->assertEquals($outBoundSmsActivityId, $activity['activity_type_id'], 'Wrong activity type is set.');
$this->assertEquals($activityStatusCompleted, $activity['status_id'], 'Expected activity status Completed.');
$this->assertEquals('subject', $activity['subject'], 'Activity subject does not match.');
$this->assertEquals('text', $activity['details'], 'Activity details does not match.');
// Token is not resolved here.
$this->assertEquals('text {contact.first_name}', $activity['details'], 'Activity details does not match.');
}
/**
......
......@@ -13,7 +13,7 @@
* Test SMS provider to allow for testing
*/
class CiviTestSMSProvider extends CRM_SMS_Provider {
protected $_providerInfo = [];
protected $sentMessage;
protected $_id = 0;
static private $_singleton = [];
......@@ -44,6 +44,16 @@ class CiviTestSMSProvider extends CRM_SMS_Provider {
}
public function send($recipients, $header, $message, $dncID = NULL) {
$this->sentMessage = $message;
}
/**
* Get the message that was sent.
*
* @return string
*/
public function getSentMessage(): string {
return $this->sentMessage;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment