From 14145505a50e01285d5ec67058fa4082ce424e4a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 12 Oct 2021 18:25:17 +1300 Subject: [PATCH] Remove call to getTokenDetails from Contribute pdf letter On digging this is just a glorifed api call. The parameters loaded are only used in emailLetter for filtering --- CRM/Contribute/Form/Task/PDFLetter.php | 15 ++++++--------- .../Contribute/Form/Task/PDFLetterCommonTest.php | 10 +++++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index b1a6e49f3b8f..6d0c932b5134 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -316,6 +316,7 @@ public function getTokenSchema(): array { * @param bool $isIncludeSoftCredits * * @return array + * @throws \CiviCRM_API3_Exception */ public function buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $isIncludeSoftCredits) { $contributions = $contacts = []; @@ -356,16 +357,12 @@ public function buildContributionArray($groupBy, $contributionIDs, $returnProper // CiviMail, with a big performance impact. // Hooks allow more nuanced smarty usage here. CRM_Core_Smarty::singleton()->assign('contributions', $contributions); + $resolvedContacts = civicrm_api3('Contact', 'get', [ + 'return' => array_keys($returnProperties), + 'id' => ['IN' => array_keys($contacts)], + ])['values']; foreach ($contacts as $contactID => $contact) { - [$tokenResolvedContacts] = CRM_Utils_Token::getTokenDetails(['contact_id' => $contactID], - $returnProperties, - $skipOnHold, - $skipDeceased, - NULL, - $messageToken, - $task - ); - $contacts[$contactID] = array_merge($tokenResolvedContacts[$contactID], $contact); + $contacts[$contactID] = array_merge($resolvedContacts[$contactID], $contact); } return [$contributions, $contacts]; } diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index 91e06ed8fb4b..de5c575cfa7e 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -161,7 +161,6 @@ public function testBuildContributionArray(): void { [$contributions, $contacts] = $form->buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE); $this->assertEquals('Anthony', $contacts[$this->_individualId]['first_name']); - $this->assertEquals('emo', $contacts[$this->_individualId]['favourite_emoticon']); $this->assertEquals('Donation', $contributions[$result['id']]['financial_type']); $this->assertEquals($campaignTitle, $contributions[$result['id']]['campaign']); $this->assertEquals('Check', $contributions[$result['id']]['payment_instrument']); @@ -261,14 +260,16 @@ public function testNoContributionTokens(): void { /** * Test all contribution tokens. * - * @throws \API_Exception * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ public function testAllContributionTokens(): void { + $this->hookClass->setHook('civicrm_tokenValues', [$this, 'hookTokenValues']); + $this->hookClass->setHook('civicrm_tokens', [$this, 'hook_tokens']); + $this->createLoggedInUser(); $this->createCustomGroupWithFieldsOfAllTypes(['extends' => 'Contribution']); - $this->campaignCreate(['name' => 'Big one', 'title' => 'Big one']); + $this->campaignCreate(['name' => 'Big one', 'title' => 'Big one'], FALSE); $tokens = $this->getAllContributionTokens(); $formValues = [ 'document_type' => 'pdf', @@ -277,6 +278,7 @@ public function testAllContributionTokens(): void { foreach (array_keys($this->getAllContributionTokens()) as $token) { $formValues['html_message'] .= "$token : {contribution.$token}\n"; } + $formValues['html_message'] .= '{emoji.favourite_emoticon}'; /* @var $form CRM_Contribute_Form_Task_PDFLetter */ $form = $this->getFormObject('CRM_Contribute_Form_Task_PDFLetter', $formValues); $form->setContributionIds([$this->createContribution(array_merge(['campaign_id' => $tokens['campaign_id:label']], $tokens))]); @@ -326,6 +328,7 @@ public function testAllContributionTokens(): void { ' . $this->getCustomFieldName('multi_state') . ' : Victoria, New South Wales ' . $this->getCustomFieldName('boolean') . ' : Yes ' . $this->getCustomFieldName('checkbox') . ' : Purple +emo ', $html); @@ -513,6 +516,7 @@ public function testPostProcessGroupByContact(): void { public function hook_tokens(&$tokens): void { $this->hookTokensCalled++; $tokens['aggregate'] = ['rendered_token' => 'rendered_token']; + $tokens['emoji'] = ['favourite_emoticon' => 'favourite_emoticon']; } /**