From b062846d5fd33aff8486e9c59ca0c0811d30ed02 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 25 Nov 2023 11:15:23 +1300 Subject: [PATCH] Add test for money format handling on Online Contribution flow --- Civi/Test/ContributionPageTestTrait.php | 1 - .../Form/Contribution/ConfirmTest.php | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Civi/Test/ContributionPageTestTrait.php b/Civi/Test/ContributionPageTestTrait.php index 7d6a0d1cf6..13fe51fb3c 100644 --- a/Civi/Test/ContributionPageTestTrait.php +++ b/Civi/Test/ContributionPageTestTrait.php @@ -283,7 +283,6 @@ trait ContributionPageTestTrait { * - use false to suppress the creation of this field. * @param string $identifier * - * @throws \CRM_Core_Exception * @noinspection PhpUnhandledExceptionInspection */ public function contributionPageQuickConfigCreate(array $contributionPageParameters = [], array $priceSetParameters = [], bool $isSeparatePayment = FALSE, bool $membershipAmountField = TRUE, bool $contributionAmountField = TRUE, bool $otherAmountField = TRUE, string $identifier = 'QuickConfig'): void { diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php index 461163b46d..a488c2dd5e 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -195,6 +195,30 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { $this->assertFalse($assignedVariables['is_separate_payment']); } + /** + * Test that submitting other amount works with non-english currency formatting. + * + * @dataProvider getThousandSeparators + * + * @param string $thousandSeparator + * + * @throws \CRM_Core_Exception + */ + public function testOtherAmountConfirm(string $thousandSeparator) : void { + $this->setCurrencySeparators($thousandSeparator); + $this->contributionPageQuickConfigCreate([], [], FALSE, TRUE, TRUE, TRUE); + $processor = \Civi\Payment\System::singleton()->getById($this->ids['PaymentProcessor']['dummy']); + $processor->setDoDirectPaymentResult(['payment_status_id' => 1, 'fee_amount' => .72]); + $this->submitOnlineContributionForm([ + 'payment_processor_id' => $this->ids['PaymentProcessor']['dummy'], + 'price_' . $this->ids['PriceField']['other_amount'] => $this->formatMoneyInput(555.00), + 'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_general'], + 'id' => $this->getContributionPageID(), + ] + $this->getBillingSubmitValues(), $this->getContributionPageID()); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contribution_page_id' => $this->getContributionPageID(), 'version' => 4]); + $this->assertEquals(655, $contribution['total_amount']); + } + /** * Test the confirm form with a separate membership payment configured. */ @@ -282,6 +306,8 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { /** * @param bool $isSeparateMembershipPayment * + * @deprecated see testSeparatePaymentWithTax for preferred way to get valid config. + * * @return \Civi\Test\FormWrapper|\Civi\Test\FormWrappers\EventFormOnline|\Civi\Test\FormWrappers\EventFormParticipant|null */ private function submitFormWithMembershipAndContribution(bool $isSeparateMembershipPayment) { -- 2.25.1