From 5d4c1098fef46f9515c1f583974b69071cacf465 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 28 Aug 2020 17:18:00 +1200 Subject: [PATCH] Fix test set up to call Order.create to create the correct line items This test is not creating valid line items - so when we expect them to be correct - they aren't --- tests/phpunit/api/v3/ContributionTest.php | 49 +++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index bf24317b88..7b2f64bf7b 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -179,7 +179,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution2 = $this->callAPISuccess('contribution', 'create', $p); // Now we have 2 - test getcount. - $contribution = $this->callAPISuccess('contribution', 'getcount', []); + $contribution = $this->callAPISuccess('contribution', 'getcount'); $this->assertEquals(2, $contribution); // Test id only format. $contribution = $this->callAPISuccess('contribution', 'get', [ @@ -3562,17 +3562,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * @param int $priceFieldValueID * @param array $contriParams + * + * @throws \CRM_Core_Exception */ public function setUpPendingContribution($priceFieldValueID, $contriParams = []) { $contactID = $this->individualCreate(); - $membership = $this->callAPISuccess('membership', 'create', [ - 'contact_id' => $contactID, - 'membership_type_id' => $this->_ids['membership_type'], - 'start_date' => 'yesterday - 1 year', - 'end_date' => 'yesterday', - 'join_date' => 'yesterday - 1 year', - ]); - $contribution = $this->callAPISuccess('contribution', 'create', array_merge([ + $contribution = $this->callAPISuccess('Order', 'create', array_merge([ 'domain_id' => 1, 'contact_id' => $contactID, 'receive_date' => date('Ymd'), @@ -3585,23 +3580,33 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 2, 'contribution_page_id' => $this->_ids['contribution_page'], - 'api.membership_payment.create' => ['membership_id' => $membership['id']], + 'line_items' => [ + [ + 'line_item' => [ + [ + 'price_field_id' => $this->_ids['price_field'][0], + 'qty' => 1, + 'entity_table' => 'civicrm_membership', + 'unit_price' => 20, + 'line_total' => 20, + 'financial_type_id' => 1, + 'price_field_value_id' => $priceFieldValueID, + ], + ], + 'params' => [ + 'contact_id' => $contactID, + 'membership_type_id' => $this->_ids['membership_type'], + 'start_date' => 'yesterday - 1 year', + 'end_date' => 'yesterday', + 'join_date' => 'yesterday - 1 year', + ], + ], + ], ], $contriParams)); - $this->callAPISuccess('line_item', 'create', [ - 'entity_id' => $contribution['id'], - 'entity_table' => 'civicrm_contribution', - 'contribution_id' => $contribution['id'], - 'price_field_id' => $this->_ids['price_field'][0], - 'qty' => 1, - 'unit_price' => 20, - 'line_total' => 20, - 'financial_type_id' => 1, - 'price_field_value_id' => $priceFieldValueID, - ]); $this->_ids['contact'] = $contactID; $this->_ids['contribution'] = $contribution['id']; - $this->_ids['membership'] = $membership['id']; + $this->_ids['membership'] = $this->callAPISuccessGetValue('MembershipPayment', ['return' => 'membership_id', 'contribution_id' => $contribution['id']]); } /** -- 2.25.1