protected $adhocProvider;
/**
- * @var array(string $shortName => CRM_Core_Module $module)
+ * @var String[]
*/
protected $modules;
public function setUp() {
$this->useTransaction(TRUE);
parent::setUp();
- $this->modules = array(
+ $this->modules = [
'one' => new CRM_Core_Module('com.example.one', TRUE),
'two' => new CRM_Core_Module('com.example.two', TRUE),
- );
+ ];
// Testing on drupal-demo fails because some extensions have mgd ents.
CRM_Core_DAO::singleValueQuery('DELETE FROM civicrm_managed');
- $this->fixtures['com.example.one-foo'] = array(
+ $this->fixtures['com.example.one-foo'] = [
'module' => 'com.example.one',
'name' => 'foo',
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
- $this->fixtures['com.example.one-bar'] = array(
+ ],
+ ];
+ $this->fixtures['com.example.one-bar'] = [
'module' => 'com.example.one',
'name' => 'bar',
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Bar',
'is_reserved' => 1,
- ),
- );
- $this->fixtures['com.example.one-CustomGroup'] = array(
+ ],
+ ];
+ $this->fixtures['com.example.one-CustomGroup'] = [
'module' => 'com.example.one',
'name' => 'CustomGroup',
'entity' => 'CustomGroup',
- 'params' => array(
+ 'params' => [
'version' => 3,
'name' => 'test_custom_group',
'title' => 'Test custom group',
'extends' => 'Individual',
- ),
- );
- $this->fixtures['com.example.one-CustomField'] = array(
+ ],
+ ];
+ $this->fixtures['com.example.one-CustomField'] = [
'module' => 'com.example.one',
'name' => 'CustomField',
'entity' => 'CustomField',
- 'params' => array(
+ 'params' => [
'version' => 3,
'name' => 'test_custom_field',
'label' => 'Test custom field',
'custom_group_id' => 'test_custom_group',
'data_type' => 'String',
'html_type' => 'Text',
- ),
- );
+ ],
+ ];
$this->apiKernel = \Civi::service('civi_api_kernel');
$this->adhocProvider = new \Civi\API\Provider\AdhocProvider(3, 'CustomSearch');
* entity
*/
public function testAddRemoveEntitiesModule_UpdateAlways_DeleteAlways() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
$decls[] = $this->fixtures['com.example.one-foo'];
* time, the content of the entity changes
*/
public function testModifyDeclaration_UpdateAlways() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
$decls[] = $this->fixtures['com.example.one-foo'];
* time, the content of the entity changes
*/
public function testModifyDeclaration_UpdateNever() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
- $decls[] = array_merge($this->fixtures['com.example.one-foo'], array(
- 'update' => 'never', // Policy is to never update after initial creation
- ));
+ $decls[] = array_merge($this->fixtures['com.example.one-foo'], [
+ // Policy is to never update after initial creation
+ 'update' => 'never',
+ ]);
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
* deleted).
*/
public function testRemoveDeclaration_CleanupNever() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
- $decls[] = array_merge($this->fixtures['com.example.one-foo'], array(
+ $decls[] = array_merge($this->fixtures['com.example.one-foo'], [
'cleanup' => 'never',
- ));
+ ]);
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"');
// later on, entity definition disappears; but we decide not to do any cleanup (per policy)
- $decls = array();
+ $decls = [];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo2 = $me->get('com.example.one', 'foo');
* deleted).
*/
public function testRemoveDeclaration_CleanupUnused() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
- $decls[] = array_merge($this->fixtures['com.example.one-foo'], array(
+ $decls[] = array_merge($this->fixtures['com.example.one-foo'], [
'cleanup' => 'unused',
- ));
+ ]);
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
// Override 'getrefcount' ==> The refcount is 1
$this->adhocProvider->addAction('getrefcount', 'access CiviCRM', function ($apiRequest) {
- return civicrm_api3_create_success(array(
- array(
+ return civicrm_api3_create_success([
+ [
'name' => 'mock',
'type' => 'mock',
'count' => 1,
- ),
- ));
+ ],
+ ]);
});
// Later on, entity definition disappears; but we decide not to do any cleanup (per policy)
- $decls = array();
+ $decls = [];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo2 = $me->get('com.example.one', 'foo');
// Override 'getrefcount' ==> The refcount is 0
$this->adhocProvider->addAction('getrefcount', 'access CiviCRM', function ($apiRequest) {
- return civicrm_api3_create_success(array());
+ return civicrm_api3_create_success([]);
});
// The entity definition disappeared and there's no reference; we decide to cleanup (per policy)
- $decls = array();
+ $decls = [];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo3 = $me->get('com.example.one', 'foo');
*/
public function testInvalidDeclarationModule() {
// create first managed entity ('foo')
- $decls = array();
- $decls[] = array(
- 'module' => 'com.example.unknown', // erroneous
+ $decls = [];
+ $decls[] = [
+ // erroneous
+ 'module' => 'com.example.unknown',
'name' => 'foo',
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
+ ],
+ ];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
try {
$me->reconcile();
*/
public function testMissingName() {
// create first managed entity ('foo')
- $decls = array();
- $decls[] = array(
+ $decls = [];
+ $decls[] = [
'module' => 'com.example.unknown',
- 'name' => NULL, // erroneous
+ // erroneous
+ 'name' => NULL,
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
+ ],
+ ];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
try {
$me->reconcile();
*/
public function testMissingEntity() {
// create first managed entity ('foo')
- $decls = array();
- $decls[] = array(
+ $decls = [];
+ $decls[] = [
'module' => 'com.example.unknown',
'name' => 'foo',
- 'entity' => NULL, // erroneous
- 'params' => array(
+ // erroneous
+ 'entity' => NULL,
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
+ ],
+ ];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
try {
$me->reconcile();
*/
public function testDeactivateReactivateModule() {
// create first managed entity ('foo')
- $decls = array();
+ $decls = [];
$decls[] = $this->fixtures['com.example.one-foo'];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
// now deactivate module, which has empty decls and which cascades to managed object
$this->modules['one']->is_active = FALSE;
- $me = new CRM_Core_ManagedEntities($this->modules, array());
+ $me = new CRM_Core_ManagedEntities($this->modules, []);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
$this->assertEquals(0, $foo['is_active']);
*/
public function testUninstallModule() {
// create first managed entity ('foo')
- $decls = array();
+ $decls = [];
$decls[] = $this->fixtures['com.example.one-foo'];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
// then destroy module; note that decls go away
unset($this->modules['one']);
- $me = new CRM_Core_ManagedEntities($this->modules, array());
+ $me = new CRM_Core_ManagedEntities($this->modules, []);
$me->reconcile();
$fooNew = $me->get('com.example.one', 'foo');
$this->assertTrue(NULL === $fooNew);
public function testDependentEntitiesUninstallCleanly() {
// Install a module with two dependent managed entities
- $decls = array();
+ $decls = [];
$decls[] = $this->fixtures['com.example.one-CustomGroup'];
$decls[] = $this->fixtures['com.example.one-CustomField'];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);