From: Eileen McNaughton Date: Sun, 12 Sep 2021 23:38:57 +0000 (+1200) Subject: dev/core#2817 Remove last core calls to X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=662bee85002f779fca6aa32805afb98f824cd555;p=civicrm-core.git dev/core#2817 Remove last core calls to --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 4c25df0bed..6215dbcc2a 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -1131,18 +1131,13 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $tokenText = in_array($values['preferred_mail_format'], ['Both', 'Text'], TRUE) ? $text : ''; $tokenHtml = in_array($values['preferred_mail_format'], ['Both', 'HTML'], TRUE) ? $html : ''; - if ($caseId) { - $tokenSubject = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenSubject, $subjectToken, $escapeSmarty); - $tokenText = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenText, $messageToken, $escapeSmarty); - $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenHtml, $messageToken, $escapeSmarty); - } - $renderedTemplate = CRM_Core_BAO_MessageTemplate::renderTemplate([ 'messageTemplate' => [ 'msg_text' => $tokenText, 'msg_html' => $tokenHtml, 'msg_subject' => $tokenSubject, ], + 'tokenContext' => $caseId ? ['caseId' => $caseId] : [], 'contactId' => $contactId, 'disableSmarty' => !CRM_Utils_Constant::value('CIVICRM_MAIL_SMARTY'), 'tplParams' => ['contact' => $values], diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 46990bed09..05fffe01fe 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1586,6 +1586,8 @@ class CRM_Utils_Token { } /** + * @deprecated + * * @param int $caseId * @param string $str * @param array $knownTokens diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index a7c9750100..f615e8d892 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -1223,7 +1223,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { * @throws \CiviCRM_API3_Exception */ public function testSendEmailBasic(): void { - $contactId = $this->individualCreate(); + $contactId = $this->getContactID(); // create a logged in USER since the code references it for sendEmail user. $loggedInUser = $this->createLoggedInUser(); @@ -1255,8 +1255,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ]; $subject = __FUNCTION__ . ' subject'; - $html = __FUNCTION__ . ' html {contact.display_name}'; - $text = __FUNCTION__ . ' text {contact.display_name}'; + $html = __FUNCTION__ . ' html {contact.display_name} {case.case_type_id:label}'; + $text = __FUNCTION__ . ' text {contact.display_name} {case.case_type_id:label}'; $userID = $loggedInUser; $mut = new CiviMailUtils($this, TRUE); @@ -1271,24 +1271,66 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { NULL, NULL, NULL, - [$contactId] + [$contactId], + NULL, + NULL, + NULL, + $this->getCaseID() ); $activity = $this->callAPISuccessGetSingle('Activity', ['id' => $activity_ids[0], 'return' => ['details', 'subject']]); $details = '-ALTERNATIVE ITEM 0- -' . __FUNCTION__ . ' html ' . $contact['display_name'] . ' +' . __FUNCTION__ . ' html ' . $contact['display_name'] . ' Housing Support -ALTERNATIVE ITEM 1- -' . __FUNCTION__ . ' text ' . $contact['display_name'] . ' +' . __FUNCTION__ . ' text ' . $contact['display_name'] . ' Housing Support -ALTERNATIVE END- '; - $this->assertEquals($details, $activity['details'], 'Activity details does not match.'); - $this->assertEquals($subject, $activity['subject'], 'Activity subject does not match.'); + $this->assertEquals($details, $activity['details'], 'Activity details do not match.'); + $this->assertEquals($subject, $activity['subject'], 'Activity subject do not match.'); $mut->checkMailLog([ - 'Mr. Anthony Anderson', + 'Mr. Anthony Anderson II Housing Support', ]); $mut->stop(); } + /** + * Get case ID. + * + * @return int + */ + protected function getCaseID(): int { + if (!isset($this->ids['Case'][0])) { + CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); + $this->ids['Case'][0] = $this->callAPISuccess('Case', 'create', [ + 'case_type_id' => 'housing_support', + 'activity_subject' => 'Case Subject', + 'client_id' => $this->getContactID(), + 'status_id' => 1, + 'subject' => 'Case Subject', + 'start_date' => '2021-07-23 15:39:20', + // Note end_date is inconsistent with status Ongoing but for the + // purposes of testing tokens is ok. Creating it with status Resolved + // then ignores our known fixed end date. + 'end_date' => '2021-07-26 18:07:20', + 'medium_id' => 2, + 'details' => 'case details', + 'activity_details' => 'blah blah', + 'sequential' => 1, + ])['id']; + } + return $this->ids['Case'][0]; + } + + /** + * @return int + */ + protected function getContactID(): int { + if (!isset($this->ids['Contact'][0])) { + $this->ids['Contact'][0] = $this->individualCreate(); + } + return $this->ids['Contact'][0]; + } + /** * This is different from SentEmailBasic to try to help prevent code that * assumes an email always has tokens in it. diff --git a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php index a6bd772ab4..589bcdf2e7 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php @@ -67,7 +67,7 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { * @throws \CiviCRM_API3_Exception * @throws \Civi\API\Exception\UnauthorizedException */ - public function testPostProcessWithSignature() { + public function testPostProcessWithSignature(): void { $mut = new CiviMailUtils($this, TRUE); $bcc1 = $this->individualCreate(['email' => 'bcc1@example.com']); $bcc2 = $this->individualCreate(['email' => 'bcc2@example.com']);