From c1e73b271d54ea6b37c17288eedcc000dfd99e68 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 15 Nov 2022 20:26:48 -0500 Subject: [PATCH] SearchKit - Fix unit tests to work with SearchKit enabled --- CRM/Core/Config.php | 6 +++++- .../CRM/Contribute/Import/Parser/ContributionTest.php | 2 +- tests/phpunit/api/v4/Action/AutocompleteTest.php | 4 ---- tests/phpunit/api/v4/Entity/ConformanceTest.php | 2 +- tests/phpunit/api/v4/Entity/ManagedEntityTest.php | 3 +++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 7bee954f04..795f95576e 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -293,7 +293,7 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { CRM_Core_Permission::basicPermissions() ); } - else { + elseif (get_class($this->userPermissionClass) !== 'CRM_Core_Permission_UnitTests') { // Cannot store permissions -- warn if any modules require them $modules_with_perms = []; foreach ($module_files as $module_file) { @@ -302,6 +302,10 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { $modules_with_perms[] = $module_file['prefix']; } } + // FIXME: Setting a session status message here is probably wrong. + // For starters we are not necessarily in the context of a user-facing form + // for another thing this message will show indiscriminately to non-admin users + // and finally, this message contains nothing actionable for the person reading it to do. if (!empty($modules_with_perms)) { CRM_Core_Session::setStatus( ts('Some modules define permissions, but the CMS cannot store them: %1', [1 => implode(', ', $modules_with_perms)]), diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 6fd3735a29..9f46ee1330 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -51,7 +51,7 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { * * @var string[] */ - protected $toggleExts = ['civiimport', 'org.civicrm.search_kit', 'org.civicrm.afform', 'authx']; + protected $toggleExts = ['civiimport', 'org.civicrm.afform', 'authx']; protected function setUp(): void { parent::setUp(); diff --git a/tests/phpunit/api/v4/Action/AutocompleteTest.php b/tests/phpunit/api/v4/Action/AutocompleteTest.php index 9c5c7d5c92..96a5f70c9d 100644 --- a/tests/phpunit/api/v4/Action/AutocompleteTest.php +++ b/tests/phpunit/api/v4/Action/AutocompleteTest.php @@ -38,10 +38,6 @@ class AutocompleteTest extends Api4TestBase implements HookInterface, Transactio */ private $hookCallback; - public function setUpHeadless(): void { - \Civi\Test::headless()->install('org.civicrm.search_kit')->apply(); - } - /** * Listens for civi.api4.entityTypes event to manually add this nonstandard entity * diff --git a/tests/phpunit/api/v4/Entity/ConformanceTest.php b/tests/phpunit/api/v4/Entity/ConformanceTest.php index 9cdce6f5b1..e667c893f8 100644 --- a/tests/phpunit/api/v4/Entity/ConformanceTest.php +++ b/tests/phpunit/api/v4/Entity/ConformanceTest.php @@ -102,7 +102,7 @@ class ConformanceTest extends Api4TestBase implements HookInterface { * @return array */ public function getEntitiesLotech(): array { - $manual['add'] = []; + $manual['add'] = ['SearchDisplay', 'SearchSegment']; $manual['remove'] = ['CustomValue']; $manual['transform'] = ['CiviCase' => 'Case']; diff --git a/tests/phpunit/api/v4/Entity/ManagedEntityTest.php b/tests/phpunit/api/v4/Entity/ManagedEntityTest.php index 47105a2593..1cdad916dd 100644 --- a/tests/phpunit/api/v4/Entity/ManagedEntityTest.php +++ b/tests/phpunit/api/v4/Entity/ManagedEntityTest.php @@ -517,6 +517,7 @@ class ManagedEntityTest extends Api4TestBase implements TransactionalInterface, // managed entities & the test will fail if we pretend it doesn't exist // here but still let it declare entities. new CRM_Core_Module('legacycustomsearches', TRUE), + new CRM_Core_Module('org.civicrm.search_kit', TRUE), ]; (new CRM_Core_ManagedEntities($allModules))->reconcile(); @@ -565,6 +566,7 @@ class ManagedEntityTest extends Api4TestBase implements TransactionalInterface, // managed entities & the test will fail if we pretend it doesn't exist // here but still let it declare entities. new CRM_Core_Module('legacycustomsearches', TRUE), + new CRM_Core_Module('org.civicrm.search_kit', TRUE), ]; // If module is disabled it will not run hook_civicrm_managed. $this->_managedEntities = []; @@ -592,6 +594,7 @@ class ManagedEntityTest extends Api4TestBase implements TransactionalInterface, // managed entities & the test will fail if we pretend it doesn't exist // here but still let it declare entities. new CRM_Core_Module('legacycustomsearches', TRUE), + new CRM_Core_Module('org.civicrm.search_kit', TRUE), ]; $this->_managedEntities = $managedEntities; (new CRM_Core_ManagedEntities($allModules))->reconcile(); -- 2.25.1