-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21282 from eileenmcnaughton/test_sub
Add test to UpdateSubscription form
- Loading branch information
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
tests/phpunit/CRM/Contribute/Form/UpdateSubscriptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
|
||
} |