From 4a009ccfb58d54b8ee2fc7190e5ab715124d2a81 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 28 Feb 2015 15:19:43 -0500 Subject: [PATCH] CRM-15889 - More specific condition and add test coverage --- CRM/Contact/BAO/Relationship.php | 2 +- tests/phpunit/api/v3/MembershipTest.php | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 58b05f78ee..f093f93f52 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -66,7 +66,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { } //alter related membership if the is_active param is changed - if (!empty($params['id'])) { + if (!empty($params['id']) && array_key_exists('is_active', $params)) { $action = CRM_Core_Action::DISABLE; if (!empty($params['is_active'])) { $action = CRM_Core_Action::ENABLE; diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index ed53da2ec1..468ac93190 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -553,6 +553,33 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); + // Set up params for enable/disable checks + $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1])); + $params = array( + 'contact_id' => $memberContactId[1], + 'membership_type_id' => $membershipTypeId, + ); + + // Deactivate relationship using create and assert membership is not inherited + $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0)); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(0, $result['count']); + + // Re-enable relationship using create and assert membership is inherited + $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1)); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(1, $result['count']); + + // Deactivate relationship using setvalue and assert membership is not inherited + $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0)); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(0, $result['count']); + + // Re-enable relationship using setvalue and assert membership is inherited + $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1)); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(1, $result['count']); + // Tear down - reverse of creation to be safe $this->contactDelete($memberContactId[2]); $this->contactDelete($memberContactId[1]); -- 2.25.1