From 9c67047c70d7aff8e35b0c8891307be827a41238 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 18 Dec 2023 11:20:33 +1300 Subject: [PATCH] Fix tests to more standard setup method --- CRM/Contribute/Form/Contribution/Confirm.php | 4 --- CRM/Financial/BAO/Order.php | 3 ++- tests/phpunit/api/v3/ContributionPageTest.php | 25 ++++++------------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 6375776a4a..02db81ad49 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1860,10 +1860,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr // @todo deprecate receiving amount, calculate on the form. $form->order->setOverrideTotalAmount((float) $params['amount']); } - $amount = $form->order->getTotalAmount(); - if ($form->isSeparateMembershipPayment()) { - $amount -= $form->order->getMembershipTotalAmount(); - } // hack these in for test support. $form->_fields['billing_first_name'] = 1; $form->_fields['billing_last_name'] = 1; diff --git a/CRM/Financial/BAO/Order.php b/CRM/Financial/BAO/Order.php index caa68816b3..8272744f13 100644 --- a/CRM/Financial/BAO/Order.php +++ b/CRM/Financial/BAO/Order.php @@ -923,8 +923,9 @@ class CRM_Financial_BAO_Order { if ($valueID !== '') { $this->setPriceSetIDFromSelectedField($fieldID); $throwAwayArray = []; + $temporaryParams = $params; // @todo - still using getLine for now but better to bring it to this class & do a better job. - $newLines = CRM_Price_BAO_PriceSet::getLine($params, $throwAwayArray, $this->getPriceSetID(), $this->getPriceFieldSpec($fieldID), $fieldID)[1]; + $newLines = CRM_Price_BAO_PriceSet::getLine($temporaryParams, $throwAwayArray, $this->getPriceSetID(), $this->getPriceFieldSpec($fieldID), $fieldID)[1]; foreach ($newLines as $newLine) { $lineItems[$newLine['price_field_value_id']] = $newLine; } diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index fd2679a16d..149ea4e500 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -300,8 +300,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $this->setUpMembershipContributionPage(TRUE); $submitParams = [ - $this->getPriceFieldLabel('contribution') => 1, - $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'), + 'price_' . $this->ids['PriceField']['other_amount'] => 1, + $this->getPriceFieldLabel('membership_amount') => $this->getPriceFieldValue('general'), 'id' => $this->getContributionPageID(), 'billing_first_name' => 'Billy', 'billing_middle_name' => 'Goat', @@ -340,8 +340,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->ids['MembershipType'] = [$this->membershipTypeCreate(['minimum_fee' => 2])]; //Pay later $submitParams = [ - $this->getPriceFieldLabel('contribution') => 1, - $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'), + $this->getPriceFieldLabel('other_amount') => 1, + $this->getPriceFieldLabel('membership_amount') => $this->getPriceFieldValue('general'), 'id' => $this->getContributionPageID(), 'billing_first_name' => 'Billy', 'billing_middle_name' => 'Goat', @@ -998,22 +998,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { ], $membershipTypeParams); $this->ids['MembershipType'] = [$this->membershipTypeCreate($membershipTypeParams)]; } - $this->setUpMembershipBlockPriceSet(); - $this->setupPaymentProcessor(); $contributionPageParameters = !$isRecur ? [] : [ 'is_recur' => TRUE, 'recur_frequency_unit' => 'month', ]; - $this->setUpContributionPage($contributionPageParameters, ['id' => $this->getPriceSetID('membership_block')]); - - $this->callAPISuccess('MembershipBlock', 'create', [ - 'entity_id' => $this->getContributionPageID(), - 'entity_table' => 'civicrm_contribution_page', - 'is_required' => TRUE, - 'is_active' => TRUE, - 'is_separate_payment' => $isSeparatePayment, - 'membership_type_default' => $this->ids['MembershipType'], - ]); + $this->contributionPageQuickConfigCreate($contributionPageParameters, [], $isSeparatePayment, TRUE, TRUE, TRUE); } /** @@ -1520,7 +1509,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ private function getSubmitParamsContributionPlusMembership(bool $isCardPayment = FALSE, string $membershipType = 'general'): array { $params = $this->getSubmitParamsMembership($isCardPayment, $membershipType); - $params[$this->getPriceFieldLabel('contribution')] = 1; + $params['price_' . $this->ids['PriceField']['other_amount']] = 88; return $params; } @@ -1534,7 +1523,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ protected function getSubmitParamsMembership(bool $isCardPayment = FALSE, string $membershipType = 'general'): array { $params = [ - $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue($membershipType), + 'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_' . $membershipType], 'id' => $this->getContributionPageID(), 'billing_first_name' => 'Billy', 'billing_middle_name' => 'Goat', -- 2.25.1