From 4e465c120a7ad4f528ac38b17c959f2a774b68bd Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 21 May 2021 18:04:46 +1200 Subject: [PATCH] Fix internal group contact cache functions to be static These are not in git universe outside of core. In theory the tests should still work.... --- CRM/Contact/BAO/GroupContactCache.php | 4 ++-- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 2 +- tests/phpunit/CRM/Group/Page/AjaxTest.php | 18 +++++------------- tests/phpunit/api/v3/ReportTemplateTest.php | 14 ++++++++------ 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 5d7394428d..891ec57cea 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -190,7 +190,7 @@ AND ( * @param bool $processed * Whether the cache data was recently modified. */ - public static function updateCacheTime($groupID, $processed) { + protected static function updateCacheTime($groupID, $processed) { // only update cache entry if we had any values if ($processed) { // also update the group with cache date information @@ -216,7 +216,7 @@ WHERE id IN ( $groupIDs ) * @param int $groupID * */ - public static function clearGroupContactCache($groupID): void { + protected static function clearGroupContactCache($groupID): void { $transaction = new CRM_Core_Transaction(); $query = " DELETE g diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index e052b1d66c..a06fe35838 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -987,7 +987,7 @@ civicrm_relationship.is_active = 1 AND $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $householdID, 'status' => 'Added']); // Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache. - CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($groupID); + CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($groupID); $sql = CRM_Contact_BAO_Query::getQuery( [['group', 'IN', [$groupID], 0, 0]], diff --git a/tests/phpunit/CRM/Group/Page/AjaxTest.php b/tests/phpunit/CRM/Group/Page/AjaxTest.php index e2c3482d0f..438b3ff0d9 100644 --- a/tests/phpunit/CRM/Group/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Group/Page/AjaxTest.php @@ -596,8 +596,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->assertTrue($found, 'Smart group shows up on Manage Group page.'); $this->assertTrue($right_count, 'Smart group displays proper count when cache is loaded.'); - // Purge the group contact cache. - CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($group->id); + // Invalidate the group contact cache. + CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($group->id); // Load the Manage Group page code. $_GET = $this->_params; @@ -612,32 +612,24 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $count_is_unknown = FALSE; foreach ($groups['data'] as $returned_group) { if ($returned_group['group_id'] == $group->id) { - if ($returned_group['count'] == ts('unknown')) { + if ($returned_group['count'] === ts('unknown')) { $count_is_unknown = TRUE; } } } $this->assertTrue($count_is_unknown, 'Smart group shows up as unknown when cache is expired.'); - // Ensure we did not populate the cache. - $sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1'; - $params = [1 => [$group->id, 'Integer']]; - $dao = CRM_Core_DAO::executeQuery($sql, $params); - $test = 'Group contact cache should not be populated on Manage Groups ' . - 'when cache_date is null'; - $this->assertEquals($dao->N, 0, $test); - // Do it again, but this time don't clear group contact cache. Instead, // set it to expire. CRM_Contact_BAO_GroupContactCache::load($group); $params['name'] = 'smartGroupCacheTimeout'; $timeout = civicrm_api3('Setting', 'getvalue', $params); - $timeout = intval($timeout) * 60; + $timeout = (int) $timeout * 60; // Reset the cache_date to $timeout seconds ago minus another 60 // seconds for good measure. $cache_date = date('YmdHis', time() - $timeout - 60); - $sql = "UPDATE civicrm_group SET cache_date = %1 WHERE id = %2"; + $sql = 'UPDATE civicrm_group SET cache_date = %1 WHERE id = %2'; $update_params = [ 1 => [$cache_date, 'Timestamp'], 2 => [$group->id, 'Integer'], diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index a4f75257fb..589e175e3c 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -873,16 +873,18 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { /** * Set up a smart group for testing. * - * The smart group includes all Households by filter. In addition an individual - * is created and hard-added and an individual is created that is not added. + * The smart group includes all Households by filter. In addition an + * individual is created and hard-added and an individual is created that is + * not added. * * One household is hard-added as well as being in the filter. * - * This gives us a range of scenarios for testing contacts are included only once - * whenever they are hard-added or in the criteria. + * This gives us a range of scenarios for testing contacts are included only + * once whenever they are hard-added or in the criteria. * * @return int * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public function setUpPopulatedSmartGroup(): int { $household1ID = $this->householdCreate(); @@ -912,7 +914,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { } // Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache. - CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($groupID); + CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($groupID); return $groupID; } @@ -951,7 +953,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { } // Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache. - CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($groupID); + CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($groupID); if ($returnAddedContact) { return [$groupID, $individualID]; -- 2.25.1