* 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
$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
*