core-54 - Activity created for case role relationship is not assigned to correct...
authorJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 9 Apr 2018 10:46:45 +0000 (16:16 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 9 Apr 2018 10:50:54 +0000 (16:20 +0530)
CRM/Contact/Page/AJAX.php
tests/phpunit/api/v3/CaseTest.php

index acd0d3d7a72019b8e70518b930d4630cca304085..591a145b0ed37602a0062616b5e071b2f14b132b 100644 (file)
@@ -261,9 +261,12 @@ class CRM_Contact_Page_AJAX {
       }
       // Save activity only for the primary (first) client
       if ($i == 0 && empty($result['is_error'])) {
-        CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $result['id'], $relContactID);
+        CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $result['id'], $relContactID, $sourceContactID);
       }
     }
+    if (!empty($_REQUEST['is_unit_test'])) {
+      return $ret;
+    }
 
     CRM_Utils_JSON::output($ret);
   }
index 65c0154e9506f31b88c0ac194f2521d56d8f1dea..09fb4db9ce397a168b6b4cc20760b0a7f600bab2 100644 (file)
@@ -324,6 +324,43 @@ class api_v3_CaseTest extends CiviCaseTestCase {
     $this->assertEquals(0, $result['count']);
   }
 
+  /**
+   * Test Case role relationship is correctly created
+   * for contacts.
+   */
+  public function testCaseRoleRelationships() {
+    // Create Case
+    $case = $this->callAPISuccess('case', 'create', $this->_params);
+    $relType = $this->relationshipTypeCreate(array('name_a_b' => 'Test AB', 'name_b_a' => 'Test BA', 'contact_type_b' => 'Individual'));
+    $relContact = $this->individualCreate(array('first_name' => 'First', 'last_name' => 'Last'));
+
+    $_REQUEST = array(
+      'rel_type' => "{$relType}_b_a",
+      'rel_contact' => $relContact,
+      'case_id' => $case['id'],
+      'is_unit_test' => TRUE,
+    );
+    $ret = CRM_Contact_Page_AJAX::relationship();
+    $this->assertEquals(0, $ret['is_error']);
+    //Check if relationship exist for the case.
+    $relationship = $this->callAPISuccess('Relationship', 'get', array(
+      'sequential' => 1,
+      'relationship_type_id' => $relType,
+      'case_id' => $case['id'],
+    ));
+    $this->assertEquals($relContact, $relationship['values'][0]['contact_id_a']);
+    $this->assertEquals($this->_params['contact_id'], $relationship['values'][0]['contact_id_b']);
+
+    //Check if activity is assigned to correct contact.
+    $activity = $this->callAPISuccess('Activity', 'get', array(
+      'subject' => 'Test BA : Mr. First Last II',
+    ));
+    $activityContact = $this->callAPISuccess('ActivityContact', 'get', array(
+      'contact_id' => $relContact,
+      'activity_id' => $activity['id'],
+    ));
+  }
+
   /**
    * Test get function based on activity.
    */