-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix test to use valid financials #20956
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,13 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { | |
use CRMTraits_Financial_FinancialACLTrait; | ||
use CRMTraits_Financial_PriceSetTrait; | ||
|
||
/** | ||
* Should financials be checked after the test but before tear down. | ||
* | ||
* @var bool | ||
*/ | ||
protected $isValidateFinancialsOnPostAssert = TRUE; | ||
|
||
/** | ||
* Clean up after tests. | ||
*/ | ||
|
@@ -666,7 +673,9 @@ public function checkItemValues($contribution) { | |
* @throws \CRM_Core_Exception | ||
* @throws \CiviCRM_API3_Exception | ||
*/ | ||
public function testAssignProportionalLineItems() { | ||
public function testAssignProportionalLineItems(): void { | ||
// This test doesn't seem to manage financials properly, possibly by design | ||
$this->isValidateFinancialsOnPostAssert = FALSE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this get reset for the tests that come after it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seamuslee001 yep - I just put in a break point in the next test & |
||
$contribution = $this->addParticipantWithContribution(); | ||
// Delete existing financial_trxns. This is because we are testing a code flow we | ||
// want to deprecate & remove & the test relies on bad data asa starting point. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,17 +22,11 @@ public function setUp(): void { | |
} | ||
|
||
/** | ||
* CHeck that all tests that have created payments have created them with the right financial entities. | ||
* Should financials be checked after the test but before tear down. | ||
* | ||
* Ideally this would be on CiviUnitTestCase but many classes would still fail. Also, it might | ||
* be good if it only ran on tests that created at least one contribution. | ||
* | ||
* @throws \CRM_Core_Exception | ||
* @var bool | ||
*/ | ||
protected function assertPostConditions(): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These asserts are now done by the parent if |
||
$this->validateAllPayments(); | ||
$this->validateAllContributions(); | ||
} | ||
protected $isValidateFinancialsOnPostAssert = TRUE; | ||
|
||
/** | ||
* Initial test of submit function. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3468,8 +3468,6 @@ public function testCompleteTransactionMembershipPriceSet() { | |
* @throws \CiviCRM_API3_Exception | ||
*/ | ||
public function testPendingToCompleteContribution(): void { | ||
// @todo - figure out why this test is not valid. | ||
$this->isValidateFinancialsOnPostAssert = FALSE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. works because of the fix below |
||
$this->createPriceSetWithPage('membership'); | ||
$this->setUpPendingContribution($this->_ids['price_field_value'][0]); | ||
$this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); | ||
|
@@ -3729,8 +3727,6 @@ public function testSendMail(): void { | |
*/ | ||
public function testSendConfirmationPayLater(): void { | ||
$mut = new CiviMailUtils($this, TRUE); | ||
// This probably needs to call the order api in order to generate valid financial entities. | ||
$this->isValidateFinancialsOnPostAssert = FALSE; | ||
// Create contribution page | ||
$pageParams = [ | ||
'title' => 'Webform Contributions', | ||
|
@@ -3741,30 +3737,30 @@ public function testSendConfirmationPayLater(): void { | |
'pay_later_text' => 'I will send payment by cheque', | ||
'pay_later_receipt' => 'Send your cheque payable to "CiviCRM LLC" to the office', | ||
]; | ||
$contributionPage = $this->callAPISuccess('contribution_page', 'create', $pageParams); | ||
$contributionPage = $this->callAPISuccess('ContributionPage', 'create', $pageParams); | ||
|
||
// Create pay later contribution | ||
$contribParams = [ | ||
$contribution = $this->callAPISuccess('Order', 'create', [ | ||
'contact_id' => $this->_individualId, | ||
'financial_type_id' => 1, | ||
'is_pay_later' => 1, | ||
'contribution_status_id' => 2, | ||
'contribution_page_id' => $contributionPage['id'], | ||
'total_amount' => '10.00', | ||
]; | ||
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams); | ||
|
||
// Create line item | ||
$lineItemParams = [ | ||
'contribution_id' => $contribution['id'], | ||
'entity_id' => $contribution['id'], | ||
'entity_table' => 'civicrm_contribution', | ||
'label' => 'My lineitem label', | ||
'qty' => 1, | ||
'unit_price' => '10.00', | ||
'line_total' => '10.00', | ||
]; | ||
$this->callAPISuccess('LineItem', 'create', $lineItemParams); | ||
'line_items' => [ | ||
[ | ||
'line_item' => [ | ||
[ | ||
'entity_table' => 'civicrm_contribution', | ||
'label' => 'My lineitem label', | ||
'qty' => 1, | ||
'unit_price' => '10.00', | ||
'line_total' => '10.00', | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
// Create email | ||
try { | ||
|
@@ -3785,7 +3781,7 @@ public function testSendConfirmationPayLater(): void { | |
// Retrieve mail & check it has the pay_later_receipt info | ||
$mut->getMostRecentEmail('raw'); | ||
$mut->checkMailLog([ | ||
(string) $contribParams['total_amount'], | ||
(string) 10, | ||
$pageParams['pay_later_receipt'], | ||
], [ | ||
'Event', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This opts in the whole class, and then we opt out the 1 test it doesn't work for