From: Eileen McNaughton Date: Mon, 17 May 2021 06:56:40 +0000 (+1200) Subject: Add unit test for #20144 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d4cf41642e9eac0d687a2664fd7f6959c8b1d9d5;p=civicrm-core.git Add unit test for #20144 --- diff --git a/tests/phpunit/CRM/Core/ManagedEntitiesTest.php b/tests/phpunit/CRM/Core/ManagedEntitiesTest.php index 2a0b640efa..3246b90cc9 100644 --- a/tests/phpunit/CRM/Core/ManagedEntitiesTest.php +++ b/tests/phpunit/CRM/Core/ManagedEntitiesTest.php @@ -91,6 +91,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { 'parameters' => '', ], ]; + $this->fixtures['com.example.one-Contact'] = [ + 'module' => 'com.example.one', + 'name' => 'Contact', + 'entity' => 'Contact', + 'params' => [ + 'version' => 3, + 'first_name' => 'Daffy', + 'last_name' => 'Duck', + 'contact_type' => 'Individual', + 'update' => 'never', + ], + ]; $this->apiKernel = \Civi::service('civi_api_kernel'); $this->adhocProvider = new \Civi\API\Provider\AdhocProvider(3, 'CustomSearch'); @@ -373,13 +385,15 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { /** * Setup an active module with an entity -- then disable and re-enable the * module + * + * @throws \CRM_Core_Exception */ - public function testDeactivateReactivateModule() { + public function testDeactivateReactivateModule(): void { $manager = CRM_Extension_System::singleton()->getManager(); - - // create first managed entity ('foo') - $decls = []; - $decls[] = $this->fixtures['com.example.one-foo']; + // Register the hook so we can check there is no effort to de-activate contact. + $this->hookClass->setHook('civicrm_pre', [$this, 'preHook']); + // create first managed entities ('foo' & Contact) + $decls = [$this->fixtures['com.example.one-foo'], $this->fixtures['com.example.one-Contact']]; // Mock the contextual process info that would be added by CRM_Extension_Manager::install $manager->setProcessesForTesting(['com.example.one' => ['install']]); $me = new CRM_Core_ManagedEntities($this->modules, $decls); @@ -484,6 +498,20 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase { $manager->setProcessesForTesting([]); } + /** + * Pre hook to test contact is not called on disable. + * + * @param string $op + * @param string $objectName + * @param int|null $id + * @param array $params + */ + public function preHook($op, $objectName, $id, $params): void { + if ($op === 'edit' && $objectName === 'Individual') { + $this->assertArrayNotHasKey('is_active', $params); + } + } + /** * Setup an active module with an entity -- then entirely uninstall the * module diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index a6e5986b39..dfd7c3db30 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -158,11 +158,11 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * * This can be used to test hooks within tests. For example in the ACL_PermissionTrait: * - * $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults')); + * $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookAllResults']); * * @var \CRM_Utils_Hook_UnitTests */ - public $hookClass = NULL; + public $hookClass; /** * @var array