Issue #1640 including a test
authorJaap Jansma <jaap.jansma@civicoop.org>
Sat, 21 Mar 2020 16:37:07 +0000 (17:37 +0100)
committerJaap Jansma <jaap.jansma@civicoop.org>
Sat, 21 Mar 2020 16:37:07 +0000 (17:37 +0100)
CRM/Contribute/Form/Task/Status.php
templates/CRM/Contribute/Form/Task/Status.tpl
tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php

index 816fa6a485bf9091a4b4c46f607a8f0f528a54be..09f1285c99b43ffa64a42b0fb6396d172b6f6a45 100644 (file)
@@ -83,6 +83,8 @@ AND    {$this->_componentClause}";
       $status,
       TRUE
     );
+    $this->add('checkbox', 'is_email_receipt', ts('Send e-mail receipt'));
+    $this->setDefaults(['is_email_receipt' => 1]);
 
     $contribIDs = implode(',', $this->_contributionIds);
     $query = "
@@ -278,6 +280,7 @@ AND    co.id IN ( $contribIDs )";
         $input['trxn_id'] = $contribution->invoice_id;
       }
       $input['trxn_date'] = $params["trxn_date_{$row['contribution_id']}"] . ' ' . date('H:i:s');
+      $input['is_email_receipt'] = !empty($params['is_email_receipt']);
 
       // @todo calling baseIPN like this is a pattern in it's last gasps. Call contribute.completetransaction api.
       $baseIPN->completeTransaction($input, $ids, $objects, $transaction, FALSE);
index 16f2ac55ce92bca3c8c671be64c354784e69c74b..635c4890d754714b33b4f0cd98b697a7a999e0e6 100644 (file)
      <table class="form-layout-compressed">
      <tr class="crm-contribution-form-block-contribution_status_id"><td class="label">{$form.contribution_status_id.label}</td><td class="html-adjust">{$form.contribution_status_id.html}<br />
             <span class="description">{ts}Assign the selected status to all contributions listed below.{/ts}</td></tr>
+       <tr class="crm-contribution-form-block-is_email_receipt"><td class="label">{$form.is_email_receipt.label}</td>
+         <td class="html-adjust">{$form.is_email_receipt.html}<br />
+           <span class="description">{ts}When checked CiviCRM will send an e-mail receipt to the donor. Leave unchecked when you don't want to send an e-mail.{/ts}
+         </td>
+       </tr>
      </table>
 <table>
 <tr class="columnheader">
index b75a963f9446417b7acfb21d2fb79e20f864b71b..502c05295bc75e689df9d401f409fb9dfaf001a9 100644 (file)
@@ -25,12 +25,63 @@ class CRM_Contribute_Form_Task_StatusTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test update pending contribution
+   * Test update pending contribution with sending a confirmation mail.
    */
-  public function testUpdatePendingContribution() {
+  public function testUpdatePendingContributionWithSendingEmail() {
     $this->_individualId = $this->individualCreate();
     $form = new CRM_Contribute_Form_Task_Status();
 
+    $mut = new CiviMailUtils($this, TRUE);
+    $mut->clearMessages();
+
+    // create a pending contribution
+    $contributionParams = [
+      'contact_id' => $this->_individualId,
+      'total_amount' => 100,
+      'financial_type_id' => 'Donation',
+      'contribution_status_id' => 2,
+    ];
+    $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+    $contributionId = $contribution['id'];
+    $form->setContributionIds([$contributionId]);
+
+    $form->buildQuickForm();
+
+    $params = [
+      "is_email_receipt" => '1',
+      "contribution_status_id" => 1,
+      "trxn_id_{$contributionId}" => NULL,
+      "check_number_{$contributionId}" => NULL,
+      "fee_amount_{$contributionId}" => 0,
+      "trxn_date_{$contributionId}" => date('m/d/Y'),
+      "payment_instrument_id_{$contributionId}" => 4,
+    ];
+
+    CRM_Contribute_Form_Task_Status::processForm($form, $params);
+
+    $contribution = $this->callAPISuccess('Contribution', 'get', ['id' => $contributionId]);
+    $updatedContribution = $contribution['values'][1];
+
+    $this->assertEquals('', $updatedContribution['contribution_source']);
+    $this->assertEquals(date("Y-m-d"), date("Y-m-d", strtotime($updatedContribution['receive_date'])));
+    $this->assertNotEquals("00:00:00", date("H:i:s", strtotime($updatedContribution['receive_date'])));
+    $this->assertEquals('Completed', $updatedContribution['contribution_status']);
+
+    $msg = $mut->getMostRecentEmail();
+    $this->assertNotEmpty($msg);
+    $mut->stop();
+  }
+
+  /**
+   * Test update pending contribution without sending a confirmation mail.
+   */
+  public function testUpdatePendingContributionWithoutSendingEmail() {
+    $this->_individualId = $this->individualCreate();
+    $form = new CRM_Contribute_Form_Task_Status();
+
+    $mut = new CiviMailUtils($this, TRUE);
+    $mut->clearMessages();
+
     // create a pending contribution
     $contributionParams = [
       'contact_id' => $this->_individualId,
@@ -45,6 +96,7 @@ class CRM_Contribute_Form_Task_StatusTest extends CiviUnitTestCase {
     $form->buildQuickForm();
 
     $params = [
+      "is_email_receipt" => '0',
       "contribution_status_id" => 1,
       "trxn_id_{$contributionId}" => NULL,
       "check_number_{$contributionId}" => NULL,
@@ -62,6 +114,9 @@ class CRM_Contribute_Form_Task_StatusTest extends CiviUnitTestCase {
     $this->assertEquals(date("Y-m-d"), date("Y-m-d", strtotime($updatedContribution['receive_date'])));
     $this->assertNotEquals("00:00:00", date("H:i:s", strtotime($updatedContribution['receive_date'])));
     $this->assertEquals('Completed', $updatedContribution['contribution_status']);
+
+    $mut->assertMailLogEmpty();
+    $mut->stop();
   }
 
 }