Merge pull request #16359 from jensschuppe/dev_core_1547
[civicrm-core.git] / tests / phpunit / CRM / Core / ManagedEntitiesTest.php
index da9da77bca7f4a6d30de6d4a4bbcba875a2f0f97..dc73e15f4afbf27f3d8792094475a72f96329bac 100644 (file)
@@ -16,7 +16,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
   protected $adhocProvider;
 
   /**
-   * @var array(string $shortName => CRM_Core_Module $module)
+   * @var String[]
    */
   protected $modules;
 
@@ -25,58 +25,58 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
   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');
@@ -94,7 +94,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    * entity
    */
   public function testAddRemoveEntitiesModule_UpdateAlways_DeleteAlways() {
-    $decls = array();
+    $decls = [];
 
     // create first managed entity ('foo')
     $decls[] = $this->fixtures['com.example.one-foo'];
@@ -143,7 +143,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    * 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'];
@@ -169,12 +169,13 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    * 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');
@@ -199,12 +200,12 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    * 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');
@@ -212,7 +213,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
     $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');
@@ -228,12 +229,12 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    * 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');
@@ -242,17 +243,17 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
 
     // 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');
@@ -262,11 +263,11 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
 
     // 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');
@@ -279,17 +280,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    */
   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();
@@ -305,17 +307,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    */
   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();
@@ -331,17 +334,18 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    */
   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();
@@ -358,7 +362,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    */
   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();
@@ -369,7 +373,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
 
     // 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']);
@@ -392,7 +396,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
    */
   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();
@@ -402,7 +406,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
 
     // 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);
@@ -412,7 +416,7 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
   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);