From 3e4eb9aac933f0bc3f9615c50f016ab4f968db5d Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Mon, 9 Apr 2018 16:16:45 +0530 Subject: [PATCH] core-54 - Activity created for case role relationship is not assigned to correct contact --- CRM/Contact/Page/AJAX.php | 5 ++++- tests/phpunit/api/v3/CaseTest.php | 37 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index acd0d3d7a7..591a145b0e 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -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); } diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 65c0154e95..09fb4db9ce 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -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. */ -- 2.25.1