Add test for money format handling on Online Contribution flow
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 24 Nov 2023 22:15:23 +0000 (11:15 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 24 Nov 2023 22:15:25 +0000 (11:15 +1300)
Civi/Test/ContributionPageTestTrait.php
tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php

index 7d6a0d1cf63d774a821703d27678b96d8691c28d..13fe51fb3c80f295ccb2516e23e21735905f57d1 100644 (file)
@@ -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 {
index 461163b46d74c9be776bc7298a8926261ac48254..a488c2dd5e2545856f6afa1ce07decb3d7a1175c 100644 (file)
@@ -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) {