From c0db4b225b86dd6a43415a6b98370a964601a904 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 17 Oct 2022 23:34:18 -0700 Subject: [PATCH] ContributionTest - Auto-disable all newly activated extensions --- .../Import/Parser/ContributionTest.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index e9f184d57a..032aeb0cea 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -32,6 +32,26 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { */ protected $entity = 'Contribution'; + /** + * These extensions are inactive at the start. They may be activated during the test. They should be deactivated at the end. + * + * For the moment, the test is simply hard-coded to cleanup in a specific order. It's tempting to auto-detect and auto-uninstall these. + * However, the shape of their dependencies makes it tricky to auto-uninstall (e.g. some exts have managed-entities that rely on other + * exts -- you need to fully disable+uninstall the downstream managed-entity-ext before disabling or uninstalling the upstream + * entity-provider-ext). + * + * You may need to edit `$toggleExts` whenever the dependency-graph changes. + * + * @var string[] + */ + protected $toggleExts = ['civiimport', 'org.civicrm.search_kit', 'org.civicrm.afform', 'authx']; + + protected function setUp(): void { + parent::setUp(); + $origExtensions = array_column(CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'fullName'); + $this->assertEquals([], array_intersect($origExtensions, $this->toggleExts), 'These extensions may be enabled and disabled during the test. The start-state and end-state should be the same. It appears that we have an unexpected start-state. Perhaps another test left us with a weird start-state?'); + } + /** * Cleanup function. * @@ -44,7 +64,10 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { DedupeRule::delete() ->addWhere('rule_table', '!=', 'civicrm_email') ->addWhere('dedupe_rule_group_id.name', '=', 'IndividualUnsupervised')->execute(); - $this->callAPISuccess('Extension', 'disable', ['key' => 'civiimport']); + foreach ($this->toggleExts as $ext) { + CRM_Extension_System::singleton()->getManager()->disable([$ext]); + CRM_Extension_System::singleton()->getManager()->uninstall([$ext]); + } parent::tearDown(); } -- 2.25.1