CiviMember: excluding Expired memberships by name, not label
authorAndrew Hunt <andrew@aghstrategies.com>
Mon, 18 Mar 2019 16:03:38 +0000 (12:03 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Mon, 18 Mar 2019 16:03:38 +0000 (12:03 -0400)
CRM/Member/BAO/Membership.php
tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php

index d16175821c629dbd8d8f68a521a6b1b0d20f5cfd..bce4b15e5419e2e54f2fb66762a907d29a498225 100644 (file)
@@ -2241,7 +2241,11 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
     // Tests for this function are in api_v3_JobTest. Please add tests for all updates.
 
     $updateCount = $processCount = self::updateDeceasedMembersStatuses();
-    $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get');
+
+    // We want all of the statuses as id => name, even the disabled ones (cf.
+    // CRM-15475), to identify which are Pending, Deceased, Cancelled, and
+    // Expired.
+    $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'validate');
     $allTypes = CRM_Member_PseudoConstant::membershipType();
 
     // This query retrieves ALL memberships of active types.
@@ -2267,11 +2271,7 @@ WHERE      civicrm_membership.is_test = 0
 
     $deceaseStatusId = array_search('Deceased', $allStatus);
     $pendingStatusId = array_search('Pending', $allStatus);
-    // CRM-15475
-    $cancelledStatusId = array_search(
-      'Cancelled',
-      CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)
-    );
+    $cancelledStatusId = array_search('Cancelled', $allStatus);
     // Expired is not reserved so might not exist.  A value of `0` won't break.
     $expiredStatusId = array_search('Expired', $allStatus) ?: 0;
 
index 5128a5ccfe3b0e7b82585dac890cbc34fcf3114f..fa118e13735563ee0c8583d5c57ad89af582087b 100644 (file)
@@ -132,7 +132,7 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase {
 
   public function testExpiredDisabled() {
     $result = civicrm_api3('MembershipStatus', 'get', [
-      'label' => "Expired",
+      'name' => "Expired",
       'api.MembershipStatus.create' => ['is_active' => 0],
     ]);
 
@@ -140,7 +140,7 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('job', 'process_membership', []);
 
     $result = civicrm_api3('MembershipStatus', 'get', [
-      'label' => "Expired",
+      'name' => "Expired",
       'api.MembershipStatus.delete' => [],
     ]);