From: demeritcowboy Date: Fri, 29 Apr 2022 18:02:57 +0000 (-0400) Subject: Case Resources only returns 25 contacts X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=432cce683fe24b8a97e5593043a9de159cf40287;p=civicrm-core.git Case Resources only returns 25 contacts --- diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 8b0c90d5ad..b2a0db357b 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -1574,7 +1574,7 @@ HERESQL; $relatedContacts = self::getRelatedContacts($caseId); $groupInfo = []; - $globalContacts = self::getGlobalContacts($groupInfo); + $globalContacts = self::getGlobalContacts($groupInfo, NULL, FALSE, FALSE, 0, 0); //unset values which are not required. foreach ($globalContacts as $k => & $v) { diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index 362850d7ef..4315091d5a 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -11,6 +11,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { $this->tablesToTruncate = [ 'civicrm_activity', + 'civicrm_group_contact', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', @@ -1293,4 +1294,53 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { $this->assertEquals($clientId, $caseContact['contact_id']); } + /** + * Test getRelatedAndGlobalContacts() + */ + public function testGetRelatedAndGlobalContacts() { + $loggedInUserId = $this->createLoggedInUser(); + $clientId = $this->individualCreate(['first_name' => 'Cli', 'last_name' => 'Ent'], 0, TRUE); + $caseObj = $this->createCase($clientId, $loggedInUserId); + + $gid = $this->callAPISuccess('Group', 'getsingle', ['name' => 'Case_Resources'])['id']; + + // Create more than 25 contacts and add them to the group + $contacts = []; + for ($i = 1; $i <= 28; $i++) { + $contacts[$i] = []; + $contacts[$i]['id'] = $this->individualCreate([], 0, TRUE); + $contacts[$i]['sort_name'] = $this->callAPISuccess('Contact', 'getsingle', [ + 'id' => $contacts[$i]['id'], + 'return' => ['sort_name'], + ])['sort_name']; + $this->callAPISuccess('GroupContact', 'create', [ + 'group_id' => $gid, + 'contact_id' => $contacts[$i]['id'], + ]); + } + $retrievedContacts = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($caseObj->id); + // 29 because the case manager is also in the list + $this->assertCount(29, $retrievedContacts); + + // There's probably an easier way to do this but what I'm trying to do + // is for each contact we created, verify the id is in the list and the + // associated sort_name also matches. But the list is just sequentially + // keyed. + for ($i = 1; $i <= 28; $i++) { + $found = FALSE; + foreach ($retrievedContacts as $retrievedContact) { + // Note the retrieved contact_id is a string, so loose comparison + if ($retrievedContact['contact_id'] == $contacts[$i]['id']) { + if ($retrievedContact['sort_name'] !== $contacts[$i]['sort_name']) { + $this->fail("Contact id {$contacts[$i]['id']} found but expected sort_name {$contacts[$i]['sort_name']} != {$retrievedContact['sort_name']}"); + } + $found = TRUE; + } + } + if (!$found) { + $this->fail("Contact id {$contacts[$i]['id']} not found in list"); + } + } + } + }