Skip to content

Commit

Permalink
Add test to UpdateSubscription form
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 29, 2021
1 parent 246f96f commit 91b773b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/UpdateSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Expand Down
101 changes: 101 additions & 0 deletions tests/phpunit/CRM/Contribute/Form/UpdateSubscriptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| Use of this source code is governed by the AGPL license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Class CRM_Contribute_Form_UpdateSubscriptionTest
*/
class CRM_Contribute_Form_UpdateSubscriptionTest extends CiviUnitTestCase {

/**
* Test the mail sent on update.
*
* @throws \CRM_Core_Exception
*/
public function testMail(): void {
$mut = new CiviMailUtils($this, TRUE);
$this->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 <info@EXAMPLE.ORG>',
'To: Anthony Anderson <anthony_anderson@civicrm.org>',
'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 <info@EXAMPLE.ORG>.',
];
}

/**
* 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];
}

}

0 comments on commit 91b773b

Please sign in to comment.