From: eileen Date: Mon, 31 Aug 2020 01:00:14 +0000 (+1200) Subject: Add test to check, remove unnecessary lines X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f816b68fc866414c929a90d4c67b8df6e3862fec;p=civicrm-core.git Add test to check, remove unnecessary lines Per the code comment it was likely the removed lines were not needed but tests were required to confirm. This does that --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0e8ba3d61c..7fa1f8dcb5 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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); diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index f37ae9d2da..0302284241 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -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( diff --git a/tests/phpunit/CiviTest/CiviMailUtils.php b/tests/phpunit/CiviTest/CiviMailUtils.php index d7836fc8ab..b502273e83 100644 --- a/tests/phpunit/CiviTest/CiviMailUtils.php +++ b/tests/phpunit/CiviTest/CiviMailUtils.php @@ -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. */ diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8f4550ec44..decd2f21fc 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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([ diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 046f1f6058..4ae47f9200 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -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(); }