From: Jaap Jansma Date: Sat, 21 Mar 2020 16:37:07 +0000 (+0100) Subject: Issue #1640 including a test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d7d878d2789192cc14aa3661b03b7fbf6c7a19e9;p=civicrm-core.git Issue #1640 including a test --- diff --git a/CRM/Contribute/Form/Task/Status.php b/CRM/Contribute/Form/Task/Status.php index 816fa6a485..09f1285c99 100644 --- a/CRM/Contribute/Form/Task/Status.php +++ b/CRM/Contribute/Form/Task/Status.php @@ -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); diff --git a/templates/CRM/Contribute/Form/Task/Status.tpl b/templates/CRM/Contribute/Form/Task/Status.tpl index 16f2ac55ce..635c4890d7 100644 --- a/templates/CRM/Contribute/Form/Task/Status.tpl +++ b/templates/CRM/Contribute/Form/Task/Status.tpl @@ -16,6 +16,11 @@ + + +
{$form.contribution_status_id.label}{$form.contribution_status_id.html}
{ts}Assign the selected status to all contributions listed below.{/ts}
{$form.is_email_receipt.label}{$form.is_email_receipt.html}
+ {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} +
diff --git a/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php b/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php index b75a963f94..502c05295b 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/StatusTest.php @@ -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(); } }