From 49f03de906a2551ceff42b25b7e11aaa2cbe0678 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 30 Jul 2021 18:33:02 +1200 Subject: [PATCH] Fix Membership.create in BAO to respect passed in status_id --- CRM/Contribute/BAO/Contribution.php | 28 ++- CRM/Member/BAO/Membership.php | 2 +- Civi/Test/ContactTestTrait.php | 3 +- api/v3/Order.php | 4 +- tests/phpunit/CRM/Export/BAO/ExportTest.php | 8 +- .../CRM/Member/Selector/SearchTest.php | 6 +- tests/phpunit/CiviTest/CiviUnitTestCase.php | 6 +- tests/phpunit/api/v3/ContributionTest.php | 206 +++++++++--------- tests/phpunit/api/v3/MembershipStatusTest.php | 31 ++- 9 files changed, 148 insertions(+), 146 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index a3259036da..9577dbfbbd 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4721,19 +4721,23 @@ LIMIT 1;"; ); $dates['join_date'] = $currentMembership['join_date']; } + if ('Pending' === CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membership['status_id'])) { + $membershipParams['skipStatusCal'] = ''; + } + else { + //get the status for membership. + $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], + $dates['end_date'], + $dates['join_date'], + 'now', + TRUE, + $membershipParams['membership_type_id'], + $membershipParams + ); - //get the status for membership. - $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], - $dates['end_date'], - $dates['join_date'], - 'now', - TRUE, - $membershipParams['membership_type_id'], - $membershipParams - ); - - unset($dates['end_date']); - $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New'); + unset($dates['end_date']); + $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New'); + } //we might be renewing membership, //so make status override false. $membershipParams['is_override'] = FALSE; diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 289d312c2d..edc63eda52 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -301,7 +301,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { $excludeIsAdmin = TRUE; } - if (empty($params['is_override'])) { + if (empty($params['status_id']) && empty($params['is_override'])) { $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($params['start_date'], $params['end_date'], $params['join_date'], 'now', $excludeIsAdmin, $params['membership_type_id'] ?? NULL, $params ); diff --git a/Civi/Test/ContactTestTrait.php b/Civi/Test/ContactTestTrait.php index 93e9264320..1aced05b67 100644 --- a/Civi/Test/ContactTestTrait.php +++ b/Civi/Test/ContactTestTrait.php @@ -77,7 +77,8 @@ trait ContactTestTrait { */ public function individualCreate(array $params = [], $seq = 0, $random = FALSE): int { $params = array_merge($this->sampleContact('Individual', $seq, $random), $params); - return $this->_contactCreate($params); + $this->ids['Contact']['individual_' . $seq] = $this->_contactCreate($params); + return $this->ids['Contact']['individual_' . $seq]; } /** diff --git a/api/v3/Order.php b/api/v3/Order.php index 5f4ef7ed73..93c4ddff56 100644 --- a/api/v3/Order.php +++ b/api/v3/Order.php @@ -139,7 +139,9 @@ function civicrm_api3_order_create(array $params): array { } if ($entityParams['entity'] === 'membership') { - $entityParams['status_id'] = 'Pending'; + if (empty($entityParams['id'])) { + $entityParams['status_id'] = 'Pending'; + } if (!empty($params['contribution_recur_id'])) { $entityParams['contribution_recur_id'] = $params['contribution_recur_id']; } diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 690bee2797..d52651acac 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -204,6 +204,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception * @throws \League\Csv\Exception + * @throws \API_Exception */ public function testExportComponentsMembership(): void { $this->setUpMembershipExportData(); @@ -305,7 +306,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 'Membership Start Date' => $membership['start_date'], 'Membership Expiration Date' => $membership['end_date'], 'Source' => 'Payment', - 'Membership Status' => 'New', + 'Membership Status' => 'Pending', 'Membership ID' => '2', 'Primary Member ID' => '', 'Max Related' => '', @@ -420,7 +421,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { * Set up some data for us to do testing on. * * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception + * @throws \API_Exception */ public function setUpMembershipExportData(): void { $this->setUpContactExportData(); @@ -472,9 +473,6 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { /** * Set up some data for us to do testing on. - * - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception */ public function setUpContactExportData(): void { $this->contactIDs[] = $contactA = $this->individualCreate(['gender_id' => 'Female']); diff --git a/tests/phpunit/CRM/Member/Selector/SearchTest.php b/tests/phpunit/CRM/Member/Selector/SearchTest.php index 55e50139b6..d9f946cb04 100644 --- a/tests/phpunit/CRM/Member/Selector/SearchTest.php +++ b/tests/phpunit/CRM/Member/Selector/SearchTest.php @@ -19,9 +19,9 @@ class CRM_Member_Selector_SearchTest extends CiviUnitTestCase { /** * Test results from getRows. * - * @throws \CRM_Core_Exception + * @throws \API_Exception */ - public function testSelectorGetRows() { + public function testSelectorGetRows(): void { $this->_contactID = $this->individualCreate(); $this->_invoiceID = 1234; $this->_contributionPageID = NULL; @@ -44,7 +44,7 @@ class CRM_Member_Selector_SearchTest extends CiviUnitTestCase { 'membership_source' => 'Payment', 'member_is_test' => '0', 'owner_membership_id' => NULL, - 'membership_status' => 'New', + 'membership_status' => 'Pending', 'member_campaign_id' => NULL, 'campaign' => NULL, 'campaign_id' => NULL, diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 3a8726c646..e9146279d4 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -514,7 +514,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { /** * Common teardown functions for all unit tests. * - * @throws \CiviCRM_API3_Exception * @throws \CRM_Core_Exception * @throws \API_Exception */ @@ -712,8 +711,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @param string $name * * @return mixed - * - * @throws \CRM_Core_Exception */ public function membershipStatusCreate($name = 'test member status') { $params['name'] = $name; @@ -825,7 +822,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @param array $params * * @return mixed - * @throws \CRM_Core_Exception */ public function paymentProcessorAuthorizeNetCreate($params = []) { $params = array_merge([ @@ -3169,7 +3165,7 @@ VALUES public function createPriceSetWithPage($entity = NULL, $params = []) { $membershipTypeID = $this->membershipTypeCreate(['name' => 'Special']); $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', [ - 'title' => "Test Contribution Page", + 'title' => 'Test Contribution Page', 'financial_type_id' => 1, 'currency' => 'NZD', 'goal_amount' => 50, diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 717ce48361..b2b84f8951 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -9,6 +9,7 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\ActivityContact; use Civi\Api4\Contribution; use Civi\Api4\PriceField; use Civi\Api4\PriceFieldValue; @@ -3423,40 +3424,38 @@ class api_v3_ContributionTest extends CiviUnitTestCase { /** * Test membership is renewed when transaction completed. + * + * @throws \API_Exception */ - public function testCompleteTransactionMembershipPriceSet() { + public function testCompleteTransactionMembershipPriceSet(): void { $this->createPriceSetWithPage('membership'); - $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', [ - 'name' => 'Grace', - 'return' => 'id', + $this->createInitialPaidMembership(); + $membership = $this->callAPISuccess('Membership', 'getsingle', [ + 'id' => $this->getMembershipID(), + 'status_id' => 'Grace', + 'return' => ['end_date'], ]); - $this->setUpPendingContribution($this->_ids['price_field_value'][0]); - $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); - $logs = $this->callAPISuccess('MembershipLog', 'get', [ - 'membership_id' => $this->_ids['membership'], + $this->assertEquals(date('Y-m-d', strtotime('yesterday')), $membership['end_date']); + + $this->createSubsequentPendingMembership(); + $this->callAPISuccess('Payment', 'create', [ + 'contribution_id' => $this->getContributionID('second'), + 'total_amount' => 20, ]); - $this->assertEquals(1, $logs['count']); - $this->assertEquals($stateOfGrace, $membership['status_id']); - $this->callAPISuccess('contribution', 'completetransaction', ['id' => $this->_ids['contribution']]); $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); - $this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']); - $this->callAPISuccessGetSingle('LineItem', [ - 'entity_id' => $this->_ids['membership'], - 'entity_table' => 'civicrm_membership', - ]); + $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 year')), $membership['end_date']); $logs = $this->callAPISuccess('MembershipLog', 'get', [ - 'membership_id' => $this->_ids['membership'], + 'membership_id' => $this->getMembershipID(), ]); - $this->assertEquals(2, $logs['count']); - $this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']); + $this->assertEquals(4, $logs['count']); //Assert only three activities are created. - $activities = CRM_Activity_BAO_Activity::getContactActivity($this->_ids['contact']); - $this->assertEquals(3, count($activities)); - $activityNames = array_flip(CRM_Utils_Array::collect('activity_name', $activities)); + $activityNames = (array) ActivityContact::get(FALSE) + ->addWhere('contact_id', '=', $this->_ids['contact']) + ->addSelect('activity.*') + ->addSelect('activity_id.activity_type_id:name')->execute()->indexBy('activity_id.activity_type_id:name'); $this->assertArrayHasKey('Contribution', $activityNames); $this->assertArrayHasKey('Membership Signup', $activityNames); $this->assertArrayHasKey('Change Membership Status', $activityNames); - $this->cleanUpAfterPriceSets(); } /** @@ -3483,7 +3482,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $form = new CRM_Contribute_Form_Contribution(); $form->_params = [ - 'id' => $this->_ids['contribution'], + 'id' => $this->getContributionID(), 'total_amount' => 20, 'net_amount' => 20, 'fee_amount' => 0, @@ -3493,7 +3492,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'billing_middle_name' => '', 'billing_last_name' => 'Adams', 'billing_street_address-5' => '790L Lincoln St S', - 'billing_city-5' => 'Maryknoll', + 'billing_city-5' => 'Mary knoll', 'billing_state_province_id-5' => 1031, 'billing_postal_code-5' => 10545, 'billing_country_id-5' => 1228, @@ -3517,14 +3516,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { // 2.a Update status of existing Scheduled Membership Signup (created in step 1) to Completed $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Membership Signup', - 'source_record_id' => $this->_ids['membership'], + 'source_record_id' => $this->getMembershipID(), 'status_id' => 'Completed', ]); $this->assertEquals(1, $activity['count']); // 2.b Contribution activity created to record successful payment $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Contribution', - 'source_record_id' => $this->_ids['contribution'], + 'source_record_id' => $this->getContributionID(), 'status_id' => 'Completed', ]); $this->assertEquals(1, $activity['count']); @@ -3532,64 +3531,24 @@ class api_v3_ContributionTest extends CiviUnitTestCase { // 2.c 'Change membership type' activity created to record Membership status change from Grace to Current $activity = $this->callAPISuccess('Activity', 'get', [ 'activity_type_id' => 'Change Membership Status', - 'source_record_id' => $this->_ids['membership'], + 'source_record_id' => $this->getMembershipID(), 'status_id' => 'Completed', ]); $this->assertEquals(1, $activity['count']); - $this->assertEquals('Status changed from Grace to Current', $activity['values'][$activity['id']]['subject']); + $this->assertEquals('Status changed from Pending to New', $activity['values'][$activity['id']]['subject']); $membershipLogs = $this->callAPISuccess('MembershipLog', 'get', ['sequential' => 1])['values']; - $this->assertEquals('Grace', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[0]['status_id'])); - $this->assertEquals('Current', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[1]['status_id'])); + $this->assertEquals('Pending', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[0]['status_id'])); + $this->assertEquals('New', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[1]['status_id'])); //Create another pending contribution for renewal - $contribution = $this->callAPISuccess('contribution', 'create', [ - 'domain_id' => 1, - 'contact_id' => $this->_ids['contact'], - 'receive_date' => date('Ymd'), - 'total_amount' => 20.00, - 'financial_type_id' => 1, - 'payment_instrument_id' => 'Credit Card', - 'non_deductible_amount' => 10.00, - 'trxn_id' => 'rdhfi88', - 'invoice_id' => 'dofhiewuyr', - 'source' => 'SSF', - 'contribution_status_id' => 2, - 'contribution_page_id' => $this->_ids['contribution_page'], - // We can't rely on contribution api to link line items correctly to membership - 'skipLineItem' => TRUE, - 'api.membership_payment.create' => ['membership_id' => $this->_ids['membership']], - ]); - - $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' => $this->_ids['price_field_value']['cont'], - ]); - $this->callAPISuccess('line_item', 'create', [ - 'entity_id' => $this->_ids['membership'], - 'entity_table' => 'civicrm_membership', - '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' => $this->_ids['price_field_value'][0], - 'membership_type_id' => $this->_ids['membership_type'], - ]); + $this->setUpPendingContribution($this->_ids['price_field_value'][0], 'second', [], ['entity_id' => $this->getMembershipID()], ['id' => $this->getMembershipID()]); //Update it to Failed. - $form->_params['id'] = $contribution['id']; + $form->_params['id'] = $this->getContributionID('second'); $form->_params['contribution_status_id'] = 4; $form->testSubmit($form->_params, CRM_Core_Action::UPDATE); //Existing membership should not get updated to expired. - $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]); + $membership = $this->callAPISuccess('Membership', 'getsingle', ['id' => $this->_ids['membership']]); $this->assertNotEquals(4, $membership['status_id']); } @@ -3598,19 +3557,25 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * Also check that altering the qty for the most recent contribution results in repeattransaction picking it up. */ - public function testCompleteTransactionMembershipPriceSetTwoTerms() { + public function testCompleteTransactionMembershipPriceSetTwoTerms(): void { $this->createPriceSetWithPage('membership'); - $this->setUpPendingContribution($this->_ids['price_field_value'][1]); - $this->callAPISuccess('contribution', 'completetransaction', ['id' => $this->_ids['contribution']]); - $membership = $this->callAPISuccessGetSingle('membership', ['id' => $this->_ids['membership']]); + $this->createInitialPaidMembership(); + $this->createSubsequentPendingMembership(); + + $this->callAPISuccess('Payment', 'create', [ + 'contribution_id' => $this->getContributionID('second'), + 'total_amount' => 20, + ]); + + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $this->getMembershipID()]); $this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']); $paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate(); $contributionRecurID = $this->callAPISuccess('ContributionRecur', 'create', ['contact_id' => $membership['contact_id'], 'payment_processor_id' => $paymentProcessorID, 'amount' => 20, 'frequency_interval' => 1])['id']; - $this->callAPISuccess('Contribution', 'create', ['id' => $this->_ids['contribution'], 'contribution_recur_id' => $contributionRecurID]); + $this->callAPISuccess('Contribution', 'create', ['id' => $this->getContributionID(), 'contribution_recur_id' => $contributionRecurID]); $this->callAPISuccess('contribution', 'repeattransaction', ['contribution_recur_id' => $contributionRecurID, 'contribution_status_id' => 'Completed']); - $membership = $this->callAPISuccessGetSingle('membership', ['id' => $this->_ids['membership']]); + $membership = $this->callAPISuccessGetSingle('membership', ['id' => $this->getMembershipID()]); $this->assertEquals(date('Y-m-d', strtotime('yesterday + 4 years')), $membership['end_date']); // Update the most recent contribution to have a qty of 1 in it's line item and then repeat, expecting just 1 year to be added. @@ -3619,8 +3584,6 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->callAPISuccess('contribution', 'repeattransaction', ['contribution_recur_id' => $contributionRecurID, 'contribution_status_id' => 'Completed']); $membership = $this->callAPISuccessGetSingle('membership', ['id' => $this->_ids['membership']]); $this->assertEquals(date('Y-m-d', strtotime('yesterday + 5 years')), $membership['end_date']); - - $this->cleanUpAfterPriceSets(); } public function cleanUpAfterPriceSets() { @@ -3632,13 +3595,23 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Set up a pending transaction with a specific price field id. * * @param int $priceFieldValueID - * @param array $contriParams - * - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception + * @param string $key + * @param array $contributionParams + * @param array $lineParams + * @param array $membershipParams */ - public function setUpPendingContribution(int $priceFieldValueID, $contriParams = []): void { + public function setUpPendingContribution(int $priceFieldValueID, string $key = 'first', array $contributionParams = [], array $lineParams = [], array $membershipParams = []): void { $contactID = $this->individualCreate(); + $membershipParams = array_merge([ + 'contact_id' => $contactID, + 'membership_type_id' => $this->_ids['membership_type'], + ], $membershipParams); + if ($key === 'first') { + // If we want these after the initial we will set them. + $membershipParams['start_date'] = 'yesterday - 1 year'; + $membershipParams['end_date'] = 'yesterday'; + $membershipParams['join_date'] = 'yesterday - 1 year'; + } $contribution = $this->callAPISuccess('Order', 'create', array_merge([ 'domain_id' => 1, 'contact_id' => $contactID, @@ -3647,15 +3620,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'payment_instrument_id' => 'Credit Card', 'non_deductible_amount' => 10.00, - 'trxn_id' => 'abcd', - 'invoice_id' => 'inv', 'source' => 'SSF', - 'contribution_status_id' => 2, 'contribution_page_id' => $this->_ids['contribution_page'], 'line_items' => [ [ 'line_item' => [ - [ + array_merge([ 'price_field_id' => $this->_ids['price_field'][0], 'qty' => 1, 'entity_table' => 'civicrm_membership', @@ -3663,21 +3633,15 @@ class api_v3_ContributionTest extends CiviUnitTestCase { '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', + ], $lineParams), ], + 'params' => $membershipParams, ], ], - ], $contriParams)); + ], $contributionParams)); $this->_ids['contact'] = $contactID; - $this->_ids['contribution'] = $contribution['id']; + $this->ids['contribution'][$key] = $contribution['id']; $this->_ids['membership'] = $this->callAPISuccessGetValue('MembershipPayment', ['return' => 'membership_id', 'contribution_id' => $contribution['id']]); } @@ -5165,4 +5129,44 @@ class api_v3_ContributionTest extends CiviUnitTestCase { return $contributionPageID; } + /** + * Get the created contribution ID. + * + * @param string $key + * + * @return int + */ + protected function getContributionID(string $key = 'first'): int { + return (int) $this->ids['contribution'][$key]; + } + + /** + * Get the created contribution ID. + * + * @return int + */ + protected function getMembershipID(): int { + return (int) $this->_ids['membership']; + } + + /** + * Create a paid membership for renewal tests. + */ + protected function createSubsequentPendingMembership(): void { + $this->setUpPendingContribution($this->_ids['price_field_value'][1], 'second', [], [], [ + 'id' => $this->getMembershipID(), + ]); + } + + /** + * Create a paid membership for renewal tests. + */ + protected function createInitialPaidMembership(): void { + $this->setUpPendingContribution($this->_ids['price_field_value'][1]); + $this->callAPISuccess('Payment', 'create', [ + 'contribution_id' => $this->getContributionID(), + 'total_amount' => 20, + ]); + } + } diff --git a/tests/phpunit/api/v3/MembershipStatusTest.php b/tests/phpunit/api/v3/MembershipStatusTest.php index c7f693c48b..1b08b8e7ac 100644 --- a/tests/phpunit/api/v3/MembershipStatusTest.php +++ b/tests/phpunit/api/v3/MembershipStatusTest.php @@ -37,9 +37,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception */ public function tearDown(): void { - $this->membershipStatusDelete($this->_membershipStatusID); - $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); - $this->contactDelete($this->_contactID); + $this->quickCleanUpFinancialEntities(); parent::tearDown(); } @@ -77,17 +75,17 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { $this->assertEquals(1, $result['count'], "Check only 1 retrieved " . __LINE__); } - public function testCreateDuplicateName() { + public function testCreateDuplicateName(): void { $params = ['name' => 'name']; - $result = $this->callAPISuccess('membership_status', 'create', $params); - $result = $this->callAPIFailure('membership_status', 'create', $params, + $this->callAPISuccess('MembershipStatus', 'create', $params); + $this->callAPIFailure('MembershipStatus', 'create', $params, 'A membership status with this name already exists.' ); } - public function testCreateWithMissingRequired() { + public function testCreateWithMissingRequired(): void { $params = ['title' => 'Does not make sense']; - $this->callAPIFailure('membership_status', 'create', $params, 'Mandatory key(s) missing from params array: name'); + $this->callAPIFailure('MembershipStatus', 'create', $params, 'Mandatory key(s) missing from params array: name'); } public function testCreate() { @@ -112,10 +110,9 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { 'id' => $id, 'name' => 'renamed', ]; - $result = $this->callAPISuccess('membership_status', 'create', $newParams); - $result = $this->callAPISuccess('membership_status', 'get', ['id' => $id]); + $this->callAPISuccess('MembershipStatus', 'create', $newParams); + $result = $this->callAPISuccess('MembershipStatus', 'get', ['id' => $id]); $this->assertEquals('renamed', $result['values'][$id]['name']); - $this->membershipStatusDelete($result['id']); } ///////////////// civicrm_membership_status_delete methods @@ -123,8 +120,8 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { /** * Attempt (and fail) to delete membership status without an parameters. */ - public function testDeleteEmptyParams() { - $result = $this->callAPIFailure('membership_status', 'delete', []); + public function testDeleteEmptyParams(): void { + $this->callAPIFailure('membership_status', 'delete', []); } public function testDeleteWithMissingRequired() { @@ -162,7 +159,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { /** * Test that trying to delete membership status while membership still exists creates error. */ - public function testDeleteWithMembershipError() { + public function testDeleteWithMembershipError(): void { $membershipStatusID = $this->membershipStatusCreate(); $this->_contactID = $this->individualCreate(); $this->_entity = 'membership'; @@ -177,18 +174,18 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { 'status_id' => $membershipStatusID, ]; - $result = $this->callAPISuccess('membership', 'create', $params); + $result = $this->callAPISuccess('Membership', 'create', $params); $membershipID = $result['id']; $params = [ 'id' => $membershipStatusID, ]; - $result = $this->callAPIFailure('membership_status', 'delete', $params); + $this->callAPIFailure('MembershipStatus', 'delete', $params); $this->callAPISuccess('Membership', 'Delete', [ 'id' => $membershipID, ]); - $result = $this->callAPISuccess('membership_status', 'delete', $params); + $this->callAPISuccess('membership_status', 'delete', $params); } } -- 2.25.1