Skip to content

Commit

Permalink
Add unit test for civicrm#20144
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 17, 2021
1 parent 72a1079 commit d4cf416
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
38 changes: 33 additions & 5 deletions tests/phpunit/CRM/Core/ManagedEntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ public function setUp(): void {
'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');
Expand Down Expand Up @@ -373,13 +385,15 @@ public function testMissingEntity() {
/**
* 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);
Expand Down Expand Up @@ -484,6 +498,20 @@ public function testDeactivateReactivateModule() {
$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
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4cf416

Please sign in to comment.