Skip to content

Commit

Permalink
ContributionTest - Auto-disable all newly activated extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
totten authored and eileenmcnaughton committed Oct 20, 2022
1 parent 7ad97da commit 1ce27f0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -44,7 +64,10 @@ public function tearDown(): void {
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();
}

Expand Down

0 comments on commit 1ce27f0

Please sign in to comment.