From 75a33ee8e58f22c523c3bcc6a7b1e84ae2d0ebfd Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 6 May 2021 12:29:58 +1200 Subject: [PATCH] Add test for data from Haystack --- tests/phpunit/api/v3/OrderTest.php | 78 +++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/api/v3/OrderTest.php b/tests/phpunit/api/v3/OrderTest.php index da18b34c0c..24af7808cc 100644 --- a/tests/phpunit/api/v3/OrderTest.php +++ b/tests/phpunit/api/v3/OrderTest.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Contribution; + /** * Test APIv3 civicrm_contribute_* functions * @@ -18,6 +20,8 @@ */ class api_v3_OrderTest extends CiviUnitTestCase { + use CRMTraits_Financial_TaxTrait; + protected $_individualId; protected $_financialTypeId = 1; @@ -594,7 +598,8 @@ class api_v3_OrderTest extends CiviUnitTestCase { } /** - * Test that a contribution can be added in pending mode with a chained payment. + * Test that a contribution can be added in pending mode with a chained + * payment. * * We have just deprecated creating an order with a status other than * pending. It makes sense to support adding a payment straight away by @@ -607,4 +612,75 @@ class api_v3_OrderTest extends CiviUnitTestCase { $this->assertEquals('Completed', $this->callAPISuccessGetValue('Contribution', ['id' => $contributionID, 'return' => 'contribution_status'])); } + /** + * Test creating an order with a mixture of taxable & non-taxable. + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception + * @throws \API_Exception + */ + public function testOrderWithMixedTax(): void { + $this->enableTaxAndInvoicing(); + $this->createFinancialTypeWithSalesTax('woo', [], ['tax_rate' => 19.3791]); + $membershipTypeID = $this->membershipTypeCreate(); + $contactID = $this->individualCreate(); + $this->callAPISuccess('Order', 'create', [ + 'contact_id' => $contactID, + 'financial_type_id' => $this->ids['FinancialType']['woo'], + 'payment_instrument_id' => 4, + 'trxn_id' => 'WooCommerce Order - 1859', + 'invoice_id' => '1859_woocommerce', + 'receive_date' => '2021-05-05 23:24:02', + 'contribution_status_id' => 'Pending', + 'total_amount' => 109.69, + 'source' => 'Shop', + 'note' => 'Fundraiser Dinner Ticket x 1, Student Membership x 1', + 'line_items' => [ + [ + 'line_item' => [ + [ + 'price_field_id' => 1, + 'unit_price' => 50.00, + 'qty' => 1, + 'line_total' => 50.00, + 'tax_amount' => 9.69, + 'label' => 'Fundraiser Dinner Ticket', + 'financial_type_id' => $this->ids['FinancialType']['woo'], + ], + ], + ], + [ + 'line_item' => [ + [ + 'price_field_id' => 1, + 'unit_price' => 50.00, + 'qty' => 1, + 'line_total' => 50.00, + 'tax_amount' => 0.00, + 'label' => 'Student Membership', + 'financial_type_id' => 2, + 'entity_table' => 'civicrm_membership', + 'membership_type_id' => $membershipTypeID, + ], + ], + 'params' => [ + 'membership_type_id' => $membershipTypeID, + 'source' => 'Shop', + 'contact_id' => $contactID, + 'skipStatusCal' => 1, + 'status_id' => 'Pending', + ], + ], + ], + 'tax_amount' => 9.69, + ]); + + $contribution = Contribution::get(FALSE) + ->addWhere('trxn_id', '=', 'WooCommerce Order - 1859') + ->setSelect(['tax_amount', 'total_amount'])->execute()->first(); + + $this->assertEquals('9.69', $contribution['tax_amount']); + $this->assertEquals('109.69', $contribution['total_amount']); + } + } -- 2.25.1