Specify tax when lines not being passed to contributon create
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 24 Nov 2023 04:32:52 +0000 (17:32 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 6 Dec 2023 21:57:58 +0000 (10:57 +1300)
tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php

index a5b96ead081784dbd892809ff0b97964e2067925..8c4d10910881b0fbc84fd4b4141e5cc7b5b5804c 100644 (file)
@@ -242,6 +242,27 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase {
     $this->assertEquals(127.5, $contribution['total_amount']);
   }
 
+  /**
+   * Test the tax calculation when using a quick config price set with a membership selection & a contribution (radio) selection.
+   *
+   * Expected amount is $100 non-tax deductible + $100 with an additional $10 tax.
+   */
+  public function testSeparatePaymentWithTaxOtherAmount(): void {
+    $this->enableTaxAndInvoicing();
+    $this->addTaxAccountToFinancialType(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'));
+    $this->contributionPageQuickConfigCreate([], [], FALSE, TRUE, TRUE, TRUE);
+    $this->submitOnlineContributionForm([
+        'payment_processor_id' => $this->ids['PaymentProcessor']['dummy'],
+        'price_' . $this->ids['PriceField']['other_amount'] => 100,
+        '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(10, $contribution['tax_amount']);
+    $this->assertEquals(210, $contribution['total_amount']);
+  }
+
   /**
    * Test the confirm form with a separate membership payment configured.
    */