From 4002221620032f855d0c4f90cffcc4b5d7e1c024 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 1 Feb 2021 17:49:46 +1300 Subject: [PATCH] dev/core#2344 fix regression affecting sending thank you letters when grouped --- CRM/Utils/PDF/Utils.php | 12 ++-- CRM/Utils/Token.php | 2 +- .../Form/Task/PDFLetterCommonTest.php | 67 +++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index 730bbc3d44..7ea2bcf12f 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -191,11 +191,15 @@ class CRM_Utils_PDF_Utils { if ($output) { return $dompdf->output(); } - else { - // CRM-19183 remove .pdf extension from filename - $fileName = basename($fileName, ".pdf"); - $dompdf->stream($fileName); + // CRM-19183 remove .pdf extension from filename + $fileName = basename($fileName, ".pdf"); + if (CIVICRM_UF === 'UnitTests') { + throw new CRM_Core_Exception_PrematureExitException('_html2pdf_dompdf called', [ + 'html' => $html, + 'fileName' => $fileName, + ]); } + $dompdf->stream($fileName); } /** diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index a836ab5211..9dd87146af 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -169,7 +169,7 @@ class CRM_Utils_Token { * @return string * The processed string */ - public static function &token_replace($type, $var, $value, &$str, $escapeSmarty = FALSE) { + public static function token_replace($type, $var, $value, &$str, $escapeSmarty = FALSE) { $token = preg_quote('{' . "$type.$var") . '(\|([^\}]+?))?' . preg_quote('}'); if (!$value) { $value = '$3'; diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index e1f9e8e93a..c48d6e7689 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -50,6 +50,60 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { CRM_Utils_Hook::singleton()->reset(); } + /** + * Test thank you send with grouping. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + */ + public function testGroupedThankYous(): void { + $this->ids['Contact'][0] = $this->individualCreate(); + $this->createLoggedInUser(); + $contribution1ID = $this->callAPISuccess('Contribution', 'create', [ + 'contact_id' => $this->ids['Contact'][0], + 'total_amount' => '60', + 'financial_type_id' => 'Donation', + 'currency' => 'USD', + 'receive_date' => '2021-01-01 13:21', + ])['id']; + $contribution2ID = $this->callAPISuccess('Contribution', 'create', [ + 'contact_id' => $this->ids['Contact'][0], + 'total_amount' => '70', + 'financial_type_id' => 'Donation', + 'receive_date' => '2021-02-01 2:21', + 'currency' => 'USD', + ])['id']; + $form = $this->getFormObject('CRM_Contribute_Form_Task_PDFLetter', [ + 'campaign_id' => '', + 'subject' => '', + 'format_id' => '', + 'paper_size' => 'letter', + 'orientation' => 'portrait', + 'metric' => 'in', + 'margin_left' => '0.75', + 'margin_right' => '0.75', + 'margin_top' => '0.75', + 'margin_bottom' => '0.75', + 'document_type' => 'pdf', + 'html_message' => '{contribution.currency} * {contribution.total_amount} * {contribution.receive_date}', + 'template' => '', + 'saveTemplateName' => '', + 'from_email_address' => '185', + 'thankyou_update' => '1', + 'group_by' => 'contact_id', + 'group_by_separator' => 'comma', + 'email_options' => '', + ]); + $this->setSearchSelection([$contribution1ID, $contribution2ID], $form); + $form->preProcess(); + try { + $form->postProcess(); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + $this->assertContains('USD, USD * $ 60.00, $ 70.00 * January 1st, 2021 1:21 PM, February 1st, 2021 2:21 AM', $e->errorData['html']); + } + } + /** * Test the buildContributionArray function. * @@ -443,4 +497,17 @@ value=$contact_aggregate+$contribution.total_amount} ]; } + /** + * @param array $entities + * @param \CRM_Core_Form $form + */ + protected function setSearchSelection(array $entities, CRM_Core_Form $form): void { + $_SESSION['_' . $form->controller->_name . '_container']['values']['Search'] = [ + 'radio_ts' => 'ts_sel', + ]; + foreach ($entities as $entityID) { + $_SESSION['_' . $form->controller->_name . '_container']['values']['Search']['mark_x_' . $entityID] = TRUE; + } + } + } -- 2.25.1