Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#2864 Remove call to getTokenDetails from Contribute pdf letter #21816

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions CRM/Contribute/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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];
}
Expand Down
10 changes: 7 additions & 3 deletions tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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',
Expand All @@ -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))]);
Expand Down Expand Up @@ -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
</div>
</body>
</html>', $html);
Expand Down Expand Up @@ -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'];
}

/**
Expand Down