diff --git a/CRM/Contribute/Form/UpdateSubscription.php b/CRM/Contribute/Form/UpdateSubscription.php index 31e16f76cff9..135c1c18ac39 100644 --- a/CRM/Contribute/Form/UpdateSubscription.php +++ b/CRM/Contribute/Form/UpdateSubscription.php @@ -333,7 +333,7 @@ public function postProcess() { CRM_Utils_System::setUFMessage($status); } // keep result as 1, since we not displaying anything on the redirected page anyway - return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', "reset=1&task=update&result=1")); } } diff --git a/tests/phpunit/CRM/Contribute/Form/UpdateSubscriptionTest.php b/tests/phpunit/CRM/Contribute/Form/UpdateSubscriptionTest.php new file mode 100644 index 000000000000..d32b6decc8c1 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Form/UpdateSubscriptionTest.php @@ -0,0 +1,101 @@ +addContribution(); + /* @var CRM_Contribute_Form_UpdateSubscription $form */ + $form = $this->getFormObject('CRM_Contribute_Form_UpdateSubscription', ['is_notify' => TRUE]); + $form->set('crid', $this->getContributionRecurID()); + $form->buildForm(); + try { + $form->postProcess(); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + $mut->checkMailLog($this->getExpectedMailStrings()); + return; + } + $this->fail('should not be reachable'); + } + + /** + * Get the strings to check for. + * + * @return string[] + */ + public function getExpectedMailStrings(): array { + return [ + 'MIME-Version: 1.0', + 'From: FIXME ', + 'To: Anthony Anderson ', + 'Subject: Recurring Contribution Update Notification - Mr. Anthony Anderson II', + 'Return-Path: info@EXAMPLE.ORG', + 'Dear Anthony,', + 'Your recurring contribution has been updated as requested:', + 'Recurring contribution is for $ 10.00, every 1 month(s) for 12 installments.', + 'If you have questions please contact us at FIXME .', + ]; + } + + /** + * Get contact id. + * + * return int + */ + public function getContactID(): int { + if (!isset($this->ids['Contact'][0])) { + $this->ids['Contact'][0] = $this->individualCreate(); + } + return $this->ids['Contact'][0]; + } + + /** + * + */ + public function addContribution(): void { + $this->callAPISuccess('Order', 'create', [ + 'contact_id' => $this->getContactID(), + 'contribution_recur_id' => $this->getContributionRecurID(), + 'financial_type_id' => 'Donation', + 'total_amount' => 10, + 'api.Payment.create' => ['total_amount' => 10], + ]); + } + + /** + * Get contribution recur ID. + * + * return int + */ + public function getContributionRecurID(): int { + if (!isset($this->ids['ContributionRecur'][0])) { + $this->ids['ContributionRecur'][0] = $this->callAPISuccess('ContributionRecur', 'create', [ + 'contact_id' => $this->getContactID(), + 'amount' => 10, + 'installments' => 12, + 'frequency_interval' => 1, + 'frequency_unit' => 'month', + ])['id']; + } + return $this->ids['ContributionRecur'][0]; + } + +}