Add test to check, remove unnecessary lines
authoreileen <emcnaughton@wikimedia.org>
Mon, 31 Aug 2020 01:00:14 +0000 (13:00 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 31 Aug 2020 06:48:26 +0000 (18:48 +1200)
Per the code comment it was likely the removed lines were not needed but tests were required to confirm.

This does that

CRM/Contribute/BAO/Contribution.php
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
tests/phpunit/CiviTest/CiviMailUtils.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/PaymentTest.php

index 0e8ba3d61c1a9d224811a6242648d8c9e929c1ba..7fa1f8dcb52860d92e0d962861358956181ca314 100644 (file)
@@ -4527,10 +4527,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     }
     else {
       if (empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) {
-        if ($event->is_email_confirm) {
-          // @todo this should be set by the function that sends the mail after sending.
-          $contributionParams['receipt_date'] = $changeDate;
-        }
         $participantParams['id'] = $participant->id;
         $participantParams['status_id'] = 'Registered';
         civicrm_api3('Participant', 'create', $participantParams);
index f37ae9d2da8a129b79e6aae527c010574c44b93e..030228424165b1bca969399207d2884c793a0030 100644 (file)
@@ -92,9 +92,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    *
    * @param string $thousandSeparator
    *
-   * @dataProvider getThousandSeparators
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    *
-   * @throws \Exception
+   * @dataProvider getThousandSeparators
    */
   public function testPaidSubmit($thousandSeparator) {
     $this->setCurrencySeparators($thousandSeparator);
@@ -165,6 +166,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     $this->assertEquals(8000.67, $contribution['total_amount']);
     $this->assertEquals(1.67, $contribution['fee_amount']);
     $this->assertEquals(7999, $contribution['net_amount']);
+    $this->assertNotEmpty($contribution['receipt_date']);
     $this->assertNotContains(' (multiple participants)', $contribution['amount_level']);
     $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
     $financialTrxn = $this->callAPISuccessGetSingle(
index d7836fc8ab5e4517700ac15bc1ee3f11e7ddf2ed..b502273e837372ef8ecd35a6b63b7cef1bb84acb 100644 (file)
@@ -62,6 +62,16 @@ class CiviMailUtils extends PHPUnit\Framework\TestCase {
     }
   }
 
+  /**
+   * Clean up after test.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function __destruct() {
+    $this->stop();
+    $this->clearMessages();
+  }
+
   /**
    * Start writing emails to db instead of current option.
    */
index 8f4550ec440129b739d5af365374a7b2dbbea2ae..decd2f21fce137af2bcfe3cf570b7a8c45314a62 100644 (file)
@@ -729,6 +729,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    * @param array $params
    *
    * @return mixed
+   * @throws \CRM_Core_Exception
    */
   public function paymentProcessorAuthorizeNetCreate($params = []) {
     $params = array_merge([
index 046f1f6058dff34fac7e1ecd4ff056a93bfb0092..4ae47f92003d6e7237eac95582c07603d25d3fb3 100644 (file)
@@ -186,6 +186,33 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     $this->validateAllPayments();
   }
 
+  /**
+   * Test contribution receipts triggered by Payment.create with is_send_contribution_notification = TRUE.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testPaymentSendContributionReceipt() {
+    $mut = new CiviMailUtils($this);
+    $contribution = $this->createPartiallyPaidParticipantOrder();
+    $event = $this->callAPISuccess('Event', 'get', []);
+    $this->addLocationToEvent($event['id']);
+    $params = [
+      'contribution_id' => $contribution['id'],
+      'total_amount' => 150,
+      'check_number' => '345',
+      'trxn_date' => '2018-08-13 17:57:56',
+      'is_send_contribution_notification' => TRUE,
+    ];
+    $this->callAPISuccess('Payment', 'create', $params);
+    $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
+    $this->assertNotEmpty($contribution['receipt_date']);
+    $mut->checkMailLog([
+      'Price Field - Price Field 1        1   $ 100.00    $ 100.00',
+      'event place',
+      'streety street',
+    ]);
+  }
+
   /**
    * Test email receipt for partial payment.
    *
@@ -229,8 +256,6 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
       'event place',
       'streety street',
     ]);
-    $mut->stop();
-    $mut->clearMessages();
     $this->validateAllPayments();
   }
 
@@ -263,8 +288,6 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
       'Balance Owed: $ 0.00',
       'Thank you for completing this payment.',
     ]);
-    $mut->stop();
-    $mut->clearMessages();
     $this->validateAllPayments();
   }
 
@@ -319,8 +342,6 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
       'Transaction Date: November 13th, 2018 12:01 PM',
       'Total Paid: $ 170' . $decimalSeparator . '00',
     ]);
-    $mut->stop();
-    $mut->clearMessages();
     $this->validateAllPayments();
   }