From: Eileen McNaughton Date: Sun, 19 Nov 2023 21:26:29 +0000 (+1300) Subject: Move & improve test for Membership only, not separate payment X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=24493508d140a60eaee8541aade06e37a4c39300;p=civicrm-core.git Move & improve test for Membership only, not separate payment --- diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 0b2ee65d92..90d939c4b1 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -551,7 +551,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } /** - * Get the idea of the other amount field if the form is configured to offer it. + * Get the ID of the other amount field if the form is configured to offer it. * * The other amount field is an alternative to the configured radio options, * specific to this form. @@ -571,7 +571,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } /** - * Get the idea of the other amount field if the form is configured to offer an other amount. + * Get the ID of the main amount field if the form is configured to offer an other amount. * * The other amount field is an alternative to the configured radio options, * specific to this form. diff --git a/Civi/Test/FormTrait.php b/Civi/Test/FormTrait.php index 77beefcc90..56944e05c7 100644 --- a/Civi/Test/FormTrait.php +++ b/Civi/Test/FormTrait.php @@ -65,7 +65,7 @@ trait FormTrait { */ protected function assertMailSentContainingString(string $string, int $mailIndex = 0): void { $mail = $this->form->getMail()[$mailIndex]; - $this->assertStringContainsString($string, $mail['body']); + $this->assertStringContainsString(preg_replace('/\s+/', '', $string), preg_replace('/\s+/', '', $mail['body'])); } /** diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php index 47e0a3abbb..facd0f11cc 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -500,4 +500,33 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { ], 1); } + /** + * Test submit opting for the membership and not the contribution. + * + * @throws \CRM_Core_Exception + */ + public function testSubmitMembershipBlockNotSeparatePaymentMembershipOnly(): void { + $this->contributionPageQuickConfigCreate([], [], FALSE, TRUE, TRUE, TRUE); + $this->submitOnlineContributionForm([ + 'payment_processor_id' => $this->ids['PaymentProcessor']['dummy'], + 'price_' . $this->ids['PriceField']['contribution_amount'] => -1, + 'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_general'], + 'id' => $this->getContributionPageID(), + ] + $this->getBillingSubmitValues(), + $this->getContributionPageID()); + + $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['contribution_page_id' => $this->getContributionPageID()]); + $membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', ['contribution_id' => $contribution['id']]); + $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]); + $this->assertMailSentContainingStrings([ + 'Dear Dave,', + 'Membership Information', + 'Membership Type General', + 'Membership Start Date', + 'Membership Expiration', + 'Membership Fee', + 'Amount $100.00', + ]); + } + } diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 557152140c..bdf9d9a9e4 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -271,25 +271,6 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { ], 'online'); } - /** - * Test submit with a membership block in place. - */ - public function testSubmitMembershipBlockNotSeparatePayment(): void { - $this->setUpMembershipContributionPage(FALSE, FALSE, ['minimum_fee' => 0]); - $submitParams = [ - $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'), - 'id' => $this->getContributionPageID(), - 'billing_first_name' => 'Billy', - 'billing_middle_name' => 'Goat', - 'billing_last_name' => 'Gruff', - ]; - - $this->callAPISuccess('ContributionPage', 'submit', $submitParams); - $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['contribution_page_id' => $this->getContributionPageID()]); - $membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', ['contribution_id' => $contribution['id']]); - $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]); - } - /** * Test submit with a membership block in place works with renewal. *