Add test on status calculation
authoreileen <emcnaughton@wikimedia.org>
Sun, 2 Aug 2020 04:57:34 +0000 (16:57 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 2 Aug 2020 04:58:13 +0000 (16:58 +1200)
CRM/Contribute/BAO/Contribution.php
tests/phpunit/api/v3/ContributionTest.php

index 397409a668252d0a772d7ca8a85d1592d34bb146..7b0bf510ce205b50bf32ea5a8f31dc967acd321a 100644 (file)
@@ -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
index 70e9db32482330a45a5534740e6b262094297c73..d5c9659909f2737741b12766051d44cd50759cdc 100644 (file)
@@ -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
    *