From 5d2065af4fb314c06f843c06e778d0ddac07cd55 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 26 Nov 2021 16:48:57 -0500 Subject: [PATCH] Fix unit tests to enable components before using them --- CRM/Core/BAO/ConfigSetting.php | 17 +++++++++++++---- tests/phpunit/CRM/Batch/Form/EntryTest.php | 2 ++ tests/phpunit/api/v4/Entity/ConformanceTest.php | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index 972ad1260d..44b7178062 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -309,8 +309,8 @@ class CRM_Core_BAO_ConfigSetting { * true if valid component name and enabling succeeds, else false */ public static function enableComponent($componentName) { - $config = CRM_Core_Config::singleton(); - if (in_array($componentName, $config->enableComponents)) { + $enabledComponents = Civi::settings()->get('enable_components'); + if (in_array($componentName, $enabledComponents)) { // component is already enabled return TRUE; } @@ -321,14 +321,23 @@ class CRM_Core_BAO_ConfigSetting { } // get enabled-components from DB and add to the list - $enabledComponents = Civi::settings()->get('enable_components'); $enabledComponents[] = $componentName; - self::setEnabledComponents($enabledComponents); return TRUE; } + /** + * Ensure all components are enabled + * @throws CRM_Core_Exception + */ + public static function enableAllComponents() { + $allComponents = array_keys(CRM_Core_Component::getComponents()); + if (Civi::settings()->get('enable_components') != $allComponents) { + self::setEnabledComponents($allComponents); + } + } + /** * Disable specified component. * diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index 67a04ddb12..ba9bc9e80e 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -88,6 +88,8 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { */ public function setUp(): void { parent::setUp(); + \CRM_Core_BAO_ConfigSetting::enableComponent('CiviMember'); + \CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign'); $params = [ 'contact_type_a' => 'Individual', diff --git a/tests/phpunit/api/v4/Entity/ConformanceTest.php b/tests/phpunit/api/v4/Entity/ConformanceTest.php index 7060fbb7ba..85a069a180 100644 --- a/tests/phpunit/api/v4/Entity/ConformanceTest.php +++ b/tests/phpunit/api/v4/Entity/ConformanceTest.php @@ -53,6 +53,8 @@ class ConformanceTest extends UnitTestCase implements HookInterface { * Set up baseline for testing */ public function setUp(): void { + // Enable all components + \CRM_Core_BAO_ConfigSetting::enableAllComponents(); $this->setUpOptionCleanup(); $this->loadDataSet('CaseType'); $this->loadDataSet('ConformanceTest'); -- 2.25.1