CRM-9386 - Fix api saving inherited memberships
authorColeman Watts <coleman@civicrm.org>
Sun, 5 Jul 2015 18:42:51 +0000 (14:42 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 23 Jul 2015 19:58:00 +0000 (15:58 -0400)
CRM/Contact/BAO/Relationship.php
tests/phpunit/api/v3/MembershipTest.php

index c026062f0f08e945e32f39daf125a245bba783a5..c8f5362d5f9deb9dcb28416a993c48065818f426 100644 (file)
@@ -696,7 +696,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
   public static function disableEnableRelationship($id, $action, $params = array(), $ids = array(), $active = FALSE) {
     $relationship = self::clearCurrentEmployer($id, $action);
 
-    if (CRM_Core_Permission::access('CiviMember')) {
+    if ($id) {
       // create $params array which is required to delete memberships
       // of the related contacts.
       if (empty($params)) {
index 8c0fbdc6a725374c57d1844edd0ff2c99d0b2401..aa5d0937a20e895b0f81722d0c9924c1fa245864 100644 (file)
@@ -580,6 +580,11 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('membership', 'get', $params);
     $this->assertEquals(1, $result['count']);
 
+    // Delete relationship and assert membership is not inherited
+    $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $this->assertEquals(0, $result['count']);
+
     // Tear down - reverse of creation to be safe
     $this->contactDelete($memberContactId[2]);
     $this->contactDelete($memberContactId[1]);