From: Eileen McNaughton Date: Thu, 17 Jun 2021 03:43:18 +0000 (+1200) Subject: dev/core#2656 Add test to demonstrate issue / bug X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=da0c54bee659f5ca2f0a578bd2ef5006d294c65c;p=civicrm-core.git dev/core#2656 Add test to demonstrate issue / bug Fix enotice in test Why didn't this cause it to fail before --- diff --git a/tests/phpunit/CRM/Dedupe/MergerTest.php b/tests/phpunit/CRM/Dedupe/MergerTest.php index b7415be6cf..af107d21aa 100644 --- a/tests/phpunit/CRM/Dedupe/MergerTest.php +++ b/tests/phpunit/CRM/Dedupe/MergerTest.php @@ -32,6 +32,13 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { 'civicrm_group', 'civicrm_prevnext_cache', ]); + if ($this->hookClass) { + // Do this here to flush the entityTables cache on teardown. + // it might be a bit expensive to add to every single test + // so a bit selectively. + $this->hookClass->reset(); + CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE); + } parent::tearDown(); } @@ -1449,4 +1456,46 @@ WHERE return $cidRefs; } + /** + * Test that declaring a custom join for search kit does not break merge. + * + * @throws \CRM_Core_Exception + */ + public function testMergeWithDeclaredSearchJoin(): void { + $this->hookClass->setHook('civicrm_entityTypes', [ + $this, + 'hookEntityTypes', + ]); + CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE); + $contact1 = $this->individualCreate(); + $contact2 = $this->individualCreate(['api.Im.create' => ['name' => 'chat_handle']]); + $this->callAPISuccess('Contact', 'merge', ['to_keep_id' => $contact1, 'to_remove_id' => $contact2]); + } + + /** + * Implements hook_civicrm_entityTypes(). + * + * Declare a callback to hookLinkCallBack function. + */ + public function hookEntityTypes(&$entityTypes): void { + $entityTypes['CRM_Core_DAO_IM']['links_callback'][] = [$this, 'hookLinkCallBack']; + } + + /** + * Callback to alter the link to im + * + * Declare a pseudo-fk between name and IM.name + * so it can be joined in SearchKit. This is obviously + * artificial but is intended to mimic the pseudo-joins + * extensions might use to leverage search kit. + * + * @param string $className + * @param array $links + * + * @noinspection PhpUnusedParameterInspection + */ + public function hookLinkCallBack(string $className, array &$links): void { + $links[] = new CRM_Core_Reference_Basic('civicrm_im', 'name', 'civicrm_contact', 'first_name'); + } + } diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index 31ac105d66..57dc51f416 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -40,7 +40,6 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * @throws \CiviCRM_API3_Exception */ public function tearDown(): void { - $this->membershipStatusDelete($this->_membershipStatusID); $this->_membershipStatusID = $this->_membershipTypeID = NULL; $this->quickCleanUpFinancialEntities(); parent::tearDown(); @@ -906,10 +905,6 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $this->assertEquals(2, $relatedMembershipsCount, "Related membership count should still be 2, but found $relatedMembershipsCount"); $this->assertMembershipExists($relatedMembership1['id']); $this->assertMembershipExists($relatedMembership2['id']); - - // Clean up: Delete everything! - $this->membershipDelete($membership['id']); - $this->membershipStatusDelete($otherStatusID); } public function testRelatedMembershipWithContactReferenceCustomField() {