dev/core#2656 Add test to demonstrate issue / bug
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 17 Jun 2021 03:43:18 +0000 (15:43 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 20 Jun 2021 00:21:28 +0000 (12:21 +1200)
Fix enotice in test

Why didn't this cause it to fail before

tests/phpunit/CRM/Dedupe/MergerTest.php
tests/phpunit/CRM/Member/BAO/MembershipTest.php

index b7415be6cf5f4711568882d02641ca4d1f2d3564..af107d21aab2954f589bad065cd026756ecd8a58 100644 (file)
@@ -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');
+  }
+
 }
index 31ac105d66998be74a6b9e7b6f86cd2ec9017a1c..57dc51f4160fe828fec41be2516aa0a7f14763dd 100644 (file)
@@ -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() {