From: Eileen McNaughton Date: Tue, 21 Apr 2015 22:53:49 +0000 (-0700) Subject: Add test to check related membership is created X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7a44a25533566b1edb5c3f8b5b74126a7dc7fcbd;p=civicrm-core.git Add test to check related membership is created --- diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 6330759c83..83316da013 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 { ); //CRM-16087 removed additional call to function relatedMemberships which is already called by disableEnableRelationship - //resulting in memership being created twice + //resulting in membership being created twice if (array_key_exists('is_active', $params) && empty($params['is_active'])) { $action = CRM_Core_Action::DISABLE; $active = FALSE; @@ -176,7 +176,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { } $relationshipIds = array(); foreach ($params['contact_check'] as $key => $value) { - $errors = ''; // check if the relationship is valid between contacts. // step 1: check if the relationship is valid if not valid skip and keep the count // step 2: check the if two contacts already have a relationship if yes skip and keep the count @@ -680,7 +679,10 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param int $id * Relationship id. * - * @param $action + * @param int $action + * @param array $params + * @param array $ids + * @param bool $active */ public static function disableEnableRelationship($id, $action, $params = array(), $ids = array(), $active = FALSE) { $relationship = self::clearCurrentEmployer($id, $action); diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index 82bf6c65eb..7e0da1bf46 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -567,7 +567,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { ); $result = $this->callAPISuccess('relationship', 'create', $params); - $params = array('id' => $params = array('id' => $result['id'])); + $params = array('id' => $result['id']); $this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__, __FILE__); $this->relationshipTypeDelete($this->_relTypeID); } @@ -1121,4 +1121,36 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', array('id' => $relationship['id'], 'is_active' => 1)); } + /** + * Test creating related memberships. + */ + public function testCreateRelatedMembership() { + $relatedMembershipType = $this->callAPISuccess('MembershipType', 'create', array( + 'name' => 'Membership with Related', + 'member_of_contact_id' => 1, + 'financial_type_id' => 1, + 'minimum_fee' => 0.00, + 'duration_unit' => 'year', + 'duration_interval' => 1, + 'period_type' => 'rolling', + 'relationship_type_id' => $this->_relTypeID, + 'relationship_direction' => 'b_a', + 'visibility' => 'Public', + 'auto_renew' => 0, + 'is_active' => 1, + 'domain_id' => CRM_Core_Config::domainID(), + )); + $originalMembership = $this->callAPISuccess('Membership', 'create', array( + 'membership_type_id' => $relatedMembershipType['id'], + 'contact_id' => $this->_cId_b, + )); + $this->callAPISuccess('Relationship', 'create', array( + 'relationship_type_id' => $this->_relTypeID, + 'contact_id_a' => $this->_cId_a, + 'contact_id_b' => $this->_cId_b, + )); + $contactAMembership = $this->callAPISuccessGetSingle('membership', array('contact_id' => $this->_cId_a)); + $this->assertEquals($originalMembership['id'], $contactAMembership['owner_membership_id']); + } + }