Add test to check related membership is created
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 21 Apr 2015 22:53:49 +0000 (15:53 -0700)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sat, 25 Apr 2015 15:05:04 +0000 (09:05 -0600)
CRM/Contact/BAO/Relationship.php
tests/phpunit/api/v3/RelationshipTest.php

index 6330759c83a5db30cd571c099ffd44041659b6bb..83316da013289cc7726cd4e8c314fafe2020d7d1 100644 (file)
@@ -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);
index 82bf6c65eb0e41f40afab343ff8b5b3f0e3ff84f..7e0da1bf46d1eef59c61e98941a321565b4c972b 100644 (file)
@@ -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']);
+  }
+
 }