dev/core#2344 fix regression affecting sending thank you letters when grouped
authoreileen <emcnaughton@wikimedia.org>
Mon, 1 Feb 2021 04:49:46 +0000 (17:49 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 1 Feb 2021 06:55:50 +0000 (19:55 +1300)
CRM/Utils/PDF/Utils.php
CRM/Utils/Token.php
tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php

index 730bbc3d4448f726e2ca30f87f221c4d478cd932..7ea2bcf12f04152756c7f39833f0207d24fe85f2 100644 (file)
@@ -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);
   }
 
   /**
index a836ab52110d790ed0eb9340461b37d33d9a5b41..9dd87146af915b6cfb024bbf3babf3076089acf5 100644 (file)
@@ -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';
index e1f9e8e93a8a7e7b7fc2189f0dc39fa6198b16c3..c48d6e768945f85b0125348c2d4cd95355a5e87c 100644 (file)
@@ -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;
+    }
+  }
+
 }