[REF] Move ACLPermission Trait into Civi Folder so that it can be accessed by Extensions
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 3 May 2021 03:25:58 +0000 (13:25 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 3 May 2021 11:25:33 +0000 (21:25 +1000)
Civi/Test/ACLPermissionTrait.php [moved from tests/phpunit/CRMTraits/ACL/PermissionTrait.php with 92% similarity]
ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php
tests/phpunit/CRM/Core/Permission/BaseTest.php
tests/phpunit/CRM/Event/BAO/EventPermissionsTest.php
tests/phpunit/api/v3/ACLPermissionTest.php
tests/phpunit/api/v3/EntityTagACLTest.php
tests/phpunit/api/v3/ReportTemplateTest.php

similarity index 92%
rename from tests/phpunit/CRMTraits/ACL/PermissionTrait.php
rename to Civi/Test/ACLPermissionTrait.php
index 7622d4c8446dd783a44b12ab897cf4712a893633..91b6681cf6d79ce32e2d51d900bd0370b76d282a 100644 (file)
@@ -9,12 +9,14 @@
  +--------------------------------------------------------------------+
  */
 
+namespace Civi\Test;
+
 /**
- * Trait ACL_Permission_Trait.
+ * Trait Civi\Test\ACLPermissionTrait.
  *
  * Trait for working with ACLs in tests
  */
-trait CRMTraits_ACL_PermissionTrait {
+trait ACLPermissionTrait {
 
   /**
    * ContactID of allowed Contact
@@ -128,7 +130,7 @@ trait CRMTraits_ACL_PermissionTrait {
 
     $permittedRoleID = ($groupAllowedAccess === 'Everyone') ? 0 : $groupAllowedAccess;
     if ($permittedRoleID !== 0) {
-      throw new CRM_Core_Exception('only handling everyone group as yet');
+      throw new \CRM_Core_Exception('only handling everyone group as yet');
     }
 
     foreach ($permissionedEntities as $permissionedEntityID) {
@@ -160,7 +162,7 @@ trait CRMTraits_ACL_PermissionTrait {
     $this->scenarioIDs['Contact']['permitted_contact'] = $this->individualCreate();
     $result = $this->callAPISuccess('GroupContact', 'create', ['group_id' => $this->scenarioIDs['Group']['permitted_group'], 'contact_id' => $this->scenarioIDs['Contact']['permitted_contact'], 'status' => 'Added']);
     $this->scenarioIDs['Contact']['non_permitted_contact'] = $this->individualCreate();
-    CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
+    \CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
     $this->setupCoreACLPermittedAcl([$this->scenarioIDs['Group']['permitted_group']]);
   }
 
@@ -180,7 +182,7 @@ trait CRMTraits_ACL_PermissionTrait {
     $this->quickCleanup(['civicrm_acl_cache', 'civicrm_acl_contact_cache']);
     $this->scenarioIDs['Event']['permitted_event'] = $this->eventCreate()['id'];
     $this->scenarioIDs['Contact']['permitted_contact'] = $this->individualCreate();
-    CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view event info'];
+    \CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view event info'];
     $this->setupCoreACLPermittedAcl([$this->scenarioIDs['Event']['permitted_event']], 'Everyone', 'View', 'Event');
   }
 
@@ -188,10 +190,10 @@ trait CRMTraits_ACL_PermissionTrait {
    * Clean up places where permissions get cached.
    */
   protected function cleanupCachedPermissions() {
-    if (isset(Civi::$statics['CRM_Contact_BAO_Contact_Permission'])) {
-      unset(Civi::$statics['CRM_Contact_BAO_Contact_Permission']);
+    if (isset(\Civi::$statics['CRM_Contact_BAO_Contact_Permission'])) {
+      unset(\Civi::$statics['CRM_Contact_BAO_Contact_Permission']);
     }
-    CRM_Core_DAO::executeQuery('TRUNCATE civicrm_acl_contact_cache');
+    \CRM_Core_DAO::executeQuery('TRUNCATE civicrm_acl_contact_cache');
   }
 
 }
index 02506e6a8f129912dad90cc79cc9f3134f28db17..c1c2c2e19f90d32b53b0e1374f495699910232b0 100644 (file)
@@ -8,14 +8,11 @@ use Civi\Api4\UFMatch;
 use Civi\Test\HeadlessInterface;
 use Civi\Test\TransactionalInterface;
 
-// FIXME: This shouldn't be needed but the core classLoader doesn't seem present when this file loads
-require_once 'tests/phpunit/CRMTraits/ACL/PermissionTrait.php';
-
 /**
  * @group headless
  */
 class SearchRunTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, TransactionalInterface {
-  use \CRMTraits_ACL_PermissionTrait;
+  use \Civi\Test\ACLPermissionTrait;
 
   public function setUpHeadless() {
     // Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
index 08d930defad4ed37286bc2a8a7e8ae97d8d8dede..63ddc5fee4533420ec45211747f8abaf4a8309c2 100644 (file)
@@ -6,7 +6,7 @@
  */
 class CRM_Core_Permission_BaseTest extends CiviUnitTestCase {
 
-  use CRMTraits_ACL_PermissionTrait;
+  use Civi\Test\ACLPermissionTrait;
 
   /**
    * @return array
index 8179347aa61c7b7cd7ad2680f94404856bf8ae70..dd353013ddaa9abbb61e9a0c1530fa8b560f3f7b 100644 (file)
@@ -15,7 +15,7 @@
  */
 class CRM_Event_BAO_EventPermissionsTest extends CiviUnitTestCase {
 
-  use CRMTraits_ACL_PermissionTrait;
+  use Civi\Test\ACLPermissionTrait;
 
   public function setUp(): void {
     parent::setUp();
index 61887fcabc7d59c5273f47fae6523d933560d93f..8641e253b25080f2ccf0b5606215e2c1d8bd844c 100644 (file)
@@ -23,7 +23,7 @@ use Civi\Api4\CustomValue;
  */
 class api_v3_ACLPermissionTest extends CiviUnitTestCase {
 
-  use CRMTraits_ACL_PermissionTrait;
+  use Civi\Test\ACLPermissionTrait;
 
   public $DBResetRequired = FALSE;
   protected $_entity;
index 2227f3b749d7670f55e923b75b7eaf79d6a7f28f..b7c06fa651216bb3f5b17f999c14d518e09cafc3 100644 (file)
@@ -26,7 +26,7 @@
  */
 class api_v3_EntityTagACLTest extends CiviUnitTestCase {
 
-  use CRMTraits_ACL_PermissionTrait;
+  use Civi\Test\ACLPermissionTrait;
 
   /**
    * API Version in use.
index 7d1d3b7a4d312e5a0dde39e8a588423389078664..597d31873d3f9f0cfeef1d26403a7965d0850cfe 100644 (file)
@@ -18,7 +18,7 @@
  */
 class api_v3_ReportTemplateTest extends CiviUnitTestCase {
 
-  use CRMTraits_ACL_PermissionTrait;
+  use Civi\Test\ACLPermissionTrait;
   use CRMTraits_PCP_PCPTestTrait;
   use CRMTraits_Custom_CustomDataTrait;