From: eileen Date: Sun, 2 Aug 2020 04:57:34 +0000 (+1200) Subject: Add test on status calculation X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4e6cd9409d8a373bce2be8f9c99a333115f555e5;p=civicrm-core.git Add test on status calculation --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 397409a668..7b0bf510ce 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5272,6 +5272,8 @@ LIMIT 1;"; * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status * when Contribution mode is notify and membership is for renewal ) */ + // Test cover for this is in testRepeattransactionRenewMembershipOldMembership + // Be afraid. CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate); // @todo - we should pass membership_type_id instead of null here but not diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 70e9db3248..d5c9659909 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2551,6 +2551,36 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']]); } + /** + * This is one of those tests that locks in existing behaviour. + * + * I feel like correct behaviour is arguable & has been discussed in the past. However, if the membership has + * a date which says it should be expired then the result of repeattransaction is to push that date + * to be one membership term from 'now' with status 'new'. + */ + public function testRepeattransactionRenewMembershipOldMembership() { + $entities = $this->setUpAutoRenewMembership(); + $newStatusID = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'New'); + $membership = $this->callAPISuccess('Membership', 'create', [ + 'id' => $entities[1]['id'], + 'join_date' => '4 months ago', + 'start_date' => '3 months ago', + 'end_date' => '2 months ago', + ]); + $membership = $membership['values'][$membership['id']]; + + // This status does not appear to be calculated at all and is set to 'new'. Feels like a bug. + $this->assertEquals($newStatusID, $membership['status_id']); + + // So it seems renewing this expired membership results in it's new status being current and it being pushed to a future date + $this->callAPISuccess('Contribution', 'repeattransaction', ['original_contribution_id' => $entities[0]['id'], 'contribution_status_id' => 'Completed']); + $membership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership['id']]); + // If this date calculation winds up being flakey the spirit of the test would be maintained by just checking + // date is greater than today. + $this->assertEquals(date('Y-m-d', strtotime('+ 1 month -1 day')), $membership['end_date']); + $this->assertEquals($newStatusID, $membership['membership_type_id']); + } + /** * CRM-19945 Tests that Contribute.repeattransaction DOES NOT renew a membership when contribution status=Failed *