Skip to content
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

[NFC] Improve use of return parameters in ContributionPage test class #20648

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public function testSubmit(): void {
$this->setUpContributionPage();
$submitParams = $this->getBasicSubmitParams();

$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->callAPISuccess('ContributionPage', 'submit', $submitParams);
$contribution = $this->callAPISuccess('Contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page'], 'return' => ['non_deductible_amount']]);
//assert non-deductible amount
$this->assertEquals(5.00, $contribution['non_deductible_amount']);
}
Expand All @@ -199,7 +199,10 @@ public function testSubmitZeroDollar(): void {
];

$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
$contribution = $this->callAPISuccessGetSingle('Contribution', [
'contribution_page_id' => $this->_ids['contribution_page'],
'return' => ['non_deductible_amount', 'total_amount'],
]);

$this->assertEquals($this->formatMoneyInput(0), $contribution['non_deductible_amount']);
$this->assertEquals($this->formatMoneyInput(0), $contribution['total_amount']);
Expand Down Expand Up @@ -295,9 +298,10 @@ public function testSubmitRecurMultiProcessorInstantPayment(): void {
];

$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contribution = $this->callAPISuccess('contribution', 'getsingle', [
$contribution = $this->callAPISuccessGetSingle('Contribution', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
'return' => ['trxn_id', 'total_amount', 'fee_amount', 'net_amount'],
]);
$this->assertEquals('create_first_success', $contribution['trxn_id']);
$this->assertEquals(10, $contribution['total_amount']);
Expand Down Expand Up @@ -349,7 +353,7 @@ public function testSubmitMembershipBlockNotSeparatePaymentProcessorInstantRenew
$submitParams = $this->getSubmitParamsContributionPlusMembership(TRUE);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id'], 'return' => 'membership_id']);
$this->callAPISuccessGetCount('LineItem', [
'entity_table' => 'civicrm_membership',
'entity_id' => $membershipPayment['id'],
Expand Down Expand Up @@ -521,16 +525,16 @@ public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater(): void {
];

$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$contributions = $this->callAPISuccess('Contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page'], 'return' => 'contribution_status_id']);
$this->assertCount(2, $contributions['values']);
foreach ($contributions['values'] as $val) {
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), $val['contribution_status_id']);
}

//Membership should be in Pending state.
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', ['return' => ['membership_id', 'contribution_id']]);
$this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id'], 'return' => ['status_id', 'contact_id']]);
$pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['return' => ['id'], 'name' => 'Pending']);
$this->assertEquals($membership['status_id'], $pendingStatus['id']);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
Expand Down Expand Up @@ -584,11 +588,11 @@ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWit

$submitParams = $this->getSubmitParamsContributionPlusMembership();
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page');
$contributions = $this->callAPISuccess('Contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']])['values'];
$contributions = $this->callAPISuccess('Contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page'], 'return' => 'contact_id'])['values'];
$this->assertCount(2, $contributions);
$membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', []);
$membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', ['return' => ['contribution_id', 'membership_id']]);
$this->assertArrayKeyExists($membershipPayment['contribution_id'], $contributions);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$membership = $this->callAPISuccessGetSingle('Membership', ['id' => $membershipPayment['membership_id'], 'return' => 'contact_id']);
$this->assertEquals($membership['contact_id'], $contributions[$membershipPayment['contribution_id']]['contact_id']);
$mut->checkMailLog([
'Gruff',
Expand Down Expand Up @@ -618,9 +622,9 @@ public function testSubmitMembershipBlockTwoTypesIsSeparatePayment(): void {
$this->assertCount(2, $contributions);
$this->assertEquals('88.00', $contributions[0]['total_amount']);
$this->assertEquals('50.00', $contributions[1]['total_amount']);
$membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', []);
$membershipPayment = $this->callAPISuccessGetSingle('MembershipPayment', ['return' => ['membership_id', 'contribution_id']]);
$this->assertEquals($contributions[1]['id'], $membershipPayment['contribution_id']);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id'], 'return' => 'contact_id']);
$this->assertEquals($membership['contact_id'], $contributions[1]['contact_id']);
}

Expand All @@ -647,7 +651,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow():
'contribution_status_id' => 1,
]);
$this->assertCount(2, $contributions['values']);
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['return' => ['contribution_id', 'membership_id']]);
$this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
Expand Down Expand Up @@ -1779,18 +1783,21 @@ public function testSubmitContributionPageWithPriceSetQuantity(string $thousandS
$lineItem1 = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
'label' => 'Shoe-eating Goat',
'return' => ['line_total', 'tax_amount'],
]);

// Retrieve the lineItem that belongs to the Printing Rights and check the tax_amount CiviCRM Core calculated for it
$lineItem2 = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
'label' => 'Printing Rights',
'return' => ['line_total', 'tax_amount'],
]);

// Retrieve the lineItem that belongs to the Another Line Item and check the tax_amount CiviCRM Core calculated for it
$lineItem3 = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
'label' => 'Another Line Item',
'return' => ['line_total', 'tax_amount'],
]);

$this->assertEquals($lineItem1['line_total'] + $lineItem2['line_total'] + $lineItem3['line_total'], round(10 + 180 * 16.95 + 110 * 2.95, 2), 'Line Item Total is incorrect.');
Expand Down Expand Up @@ -1946,13 +1953,13 @@ protected function getSubmitParamsMembership(bool $isCardPayment = FALSE, string
* @throws \CRM_Core_Exception
*/
private function validateSeparateMembershipPaymentContributions(int $contributionPageID, $contributionAmount = 88): void {
$contributions = $this->callAPISuccess('Contribution', 'get', ['contribution_page_id' => $contributionPageID])['values'];
$contributions = $this->callAPISuccess('Contribution', 'get', ['contribution_page_id' => $contributionPageID, 'return' => 'contact_id'])['values'];
$this->assertCount(2, $contributions);
$lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1])['values'];
$lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1, 'return' => 'line_total'])['values'];
$this->assertEquals($contributionAmount, $lines[0]['line_total']);
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle');
$membershipPayment = $this->callAPISuccessGetSingle('MembershipPayment', ['return' => ['contribution_id', 'membership_id']]);
$this->assertArrayKeyExists($membershipPayment['contribution_id'], $contributions);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id'], 'return' => 'contact_id']);
$this->assertEquals($membership['contact_id'], $contributions[$membershipPayment['contribution_id']]['contact_id']);
}

Expand Down