From 270437aade46cc52ee15ffe62700d6676b07b598 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 18 Dec 2023 11:02:49 +1300 Subject: [PATCH] Minor test simplification --- .../CRM/Contribute/Form/Contribution/ConfirmTest.php | 7 ++++++- tests/phpunit/CRMTraits/Financial/PriceSetTrait.php | 10 +--------- tests/phpunit/api/v3/ContributionPageTest.php | 8 +++++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php index 3fb9cd687c..685976417d 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -378,7 +378,12 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { 'is_test' => FALSE, ]); $contributionPageID = $this->createContributionPage(['payment_processor' => $paymentProcessorID], FALSE); - $this->setUpMembershipBlockPriceSet(['minimum_fee' => 1000]); + + if (empty($this->ids['MembershipType'])) { + $membershipTypeParams = ['minimum_fee' => 1000]; + $this->ids['MembershipType'] = [$this->membershipTypeCreate($membershipTypeParams)]; + } + $this->setUpMembershipBlockPriceSet(); $this->createTestEntity('PriceSetEntity', [ 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contributionPageID, diff --git a/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php b/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php index 53fb5f2196..47c789fb86 100644 --- a/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php +++ b/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php @@ -152,12 +152,10 @@ trait CRMTraits_Financial_PriceSetTrait { * page with non-quick config membership and an optional * additional contribution non-membership amount. * - * @param array $membershipTypeParams - * * @noinspection PhpDocMissingThrowsInspection * @noinspection PhpUnhandledExceptionInspection */ - protected function setUpMembershipBlockPriceSet(array $membershipTypeParams = []): void { + protected function setUpMembershipBlockPriceSet(): void { $this->ids['PriceSet']['membership_block'] = PriceSet::create(FALSE) ->setValues([ 'is_quick_config' => TRUE, @@ -167,12 +165,6 @@ trait CRMTraits_Financial_PriceSetTrait { ]) ->execute()->first()['id']; - if (empty($this->ids['MembershipType'])) { - $membershipTypeParams = array_merge([ - 'minimum_fee' => 2, - ], $membershipTypeParams); - $this->ids['MembershipType'] = [$this->membershipTypeCreate($membershipTypeParams)]; - } $priceField = $this->callAPISuccess('PriceField', 'create', [ 'price_set_id' => $this->ids['PriceSet']['membership_block'], 'name' => 'membership_amount', diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 28055fc315..fd2679a16d 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -992,7 +992,13 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * MembershipType.create API */ public function setUpMembershipContributionPage(bool $isSeparatePayment = FALSE, bool $isRecur = FALSE, array $membershipTypeParams = []): void { - $this->setUpMembershipBlockPriceSet($membershipTypeParams); + if (empty($this->ids['MembershipType'])) { + $membershipTypeParams = array_merge([ + 'minimum_fee' => 2, + ], $membershipTypeParams); + $this->ids['MembershipType'] = [$this->membershipTypeCreate($membershipTypeParams)]; + } + $this->setUpMembershipBlockPriceSet(); $this->setupPaymentProcessor(); $contributionPageParameters = !$isRecur ? [] : [ 'is_recur' => TRUE, -- 2.25.1