From cb47d0530e9bb090852344ea4dcacd2135989c9f Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 1 Oct 2020 18:39:34 +1300 Subject: [PATCH] [REF] Fix some more calls to getTokens to make it clear only the first return value is used --- api/v3/Mailing.php | 4 ++-- tests/phpunit/CRM/Utils/TokenTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 756cf75ab8..653fdcd2b2 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -567,8 +567,8 @@ function civicrm_api3_mailing_preview($params) { $details = $details[0][0] ?? NULL; } else { - $details = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens()); - $details = $details[0][$contactID]; + [$details] = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens()); + $details = $details[$contactID]; } $mime = $mailing->compose(NULL, NULL, NULL, $contactID, $fromEmail, $fromEmail, diff --git a/tests/phpunit/CRM/Utils/TokenTest.php b/tests/phpunit/CRM/Utils/TokenTest.php index 450397298c..dfb3532ce6 100644 --- a/tests/phpunit/CRM/Utils/TokenTest.php +++ b/tests/phpunit/CRM/Utils/TokenTest.php @@ -11,8 +11,8 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { */ public function testGetTokenDetails() { $contactID = $this->individualCreate(['preferred_communication_method' => ['Phone', 'Fax']]); - $resolvedTokens = CRM_Utils_Token::getTokenDetails([$contactID]); - $this->assertEquals('Phone, Fax', $resolvedTokens[0][$contactID]['preferred_communication_method']); + [$resolvedTokens] = CRM_Utils_Token::getTokenDetails([$contactID]); + $this->assertEquals('Phone, Fax', $resolvedTokens[$contactID]['preferred_communication_method']); } /** @@ -49,8 +49,8 @@ class CRM_Utils_TokenTest extends CiviUnitTestCase { $contactIDs = [$contactID]; // when we are fetching contact details ON basis of primary address fields - $contactDetails = CRM_Utils_Token::getTokenDetails($contactIDs); - $this->assertEquals($primaryEmail, $contactDetails[0][$contactID]['email']); + [$contactDetails] = CRM_Utils_Token::getTokenDetails($contactIDs); + $this->assertEquals($primaryEmail, $contactDetails[$contactID]['email']); // restore setting Civi::settings()->set('searchPrimaryDetailsOnly', '1'); -- 2.25.1