From 77c76ff7431c4a1d04b4da24e3f9325931a2e22e Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 8 Oct 2020 17:28:26 +0530 Subject: [PATCH] Unit test for #18158 --- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index b4fc988a67..5c3415a953 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -721,6 +721,14 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { * Test case for createProfileContact. */ public function testCreateProfileContact() { + //Create 3 groups. + foreach (['group1', 'group2', 'group3'] as $key => $title) { + $this->groups["id{$key}"] = $this->callAPISuccess('Group', 'create', [ + 'title' => $title, + 'visibility' => "Public Pages", + ])['id']; + } + $fields = CRM_Contact_BAO_Contact::exportableFields('Individual'); //current employer field for individual @@ -773,12 +781,18 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { '4' => '1', '1' => '1', ], + 'group' => [ + $this->groups["id0"] => '1', + ], ]; $createParams = array_merge($contactParams, $profileParams); //create the contact using create profile contact. $contactId = CRM_Contact_BAO_Contact::createProfileContact($createParams, $fields, NULL, NULL, NULL, NULL, TRUE); + //Make sure contact is added to the group. + $this->assertTrue(CRM_Contact_BAO_GroupContact::isContactInGroup($contactId, $this->groups["id0"])); + //get the parameters to compare. $params = $this->contactParams(); @@ -976,6 +990,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { '2' => '1', '5' => '1', ], + //Remove the contact from group1 and add to other 2 groups. + 'group' => [ + $this->groups["id0"] => '', + $this->groups["id1"] => '1', + $this->groups["id2"] => '1', + ], ]; $createParams = array_merge($updateCParams, $updatePfParams); @@ -985,6 +1005,16 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { NULL, NULL, NULL, TRUE ); + //Verify if contact is correctly removed from group1 + $groups = array_keys(CRM_Contact_BAO_GroupContact::getContactGroup($contactID, 'Removed')); + $expectedGroups = [$this->groups["id0"]]; + $this->checkArrayEquals($expectedGroups, $groups); + + //Verify if contact is correctly added to group1 and group2 + $groups = array_keys(CRM_Contact_BAO_GroupContact::getContactGroup($contactID, 'Added')); + $expectedGroups = [$this->groups["id1"], $this->groups["id2"]]; + $this->checkArrayEquals($expectedGroups, $groups); + //check the contact ids $this->assertEquals($contactId, $contactID, 'check for Contact ids'); -- 2.25.1