Skip to content

Commit

Permalink
[REF] Move ACLPermission Trait into Civi Folder so that it can be acc…
Browse files Browse the repository at this point in the history
…essed by Extensions
  • Loading branch information
seamuslee001 committed May 3, 2021
1 parent 41ac307 commit 57a4d21
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -128,7 +130,7 @@ public function setupCoreACLPermittedAcl($permissionedEntities = [], $groupAllow

$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) {
Expand Down Expand Up @@ -160,7 +162,7 @@ public function setupScenarioCoreACLEveryonePermittedToGroup() {
$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']]);
}

Expand All @@ -180,18 +182,18 @@ public function setupScenarioCoreACLEveryonePermittedToEvent() {
$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');
}

/**
* 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');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
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().
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Core/Permission/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
class CRM_Core_Permission_BaseTest extends CiviUnitTestCase {

use CRMTraits_ACL_PermissionTrait;
use Civi\Test\ACLPermissionTrait;

/**
* @return array
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Event/BAO/EventPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ACLPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class api_v3_ACLPermissionTest extends CiviUnitTestCase {

use CRMTraits_ACL_PermissionTrait;
use Civi\Test\ACLPermissionTrait;

public $DBResetRequired = FALSE;
protected $_entity;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/EntityTagACLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class api_v3_EntityTagACLTest extends CiviUnitTestCase {

use CRMTraits_ACL_PermissionTrait;
use Civi\Test\ACLPermissionTrait;

/**
* API Version in use.
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 57a4d21

Please sign in to comment.