From: eileen Date: Thu, 13 Dec 2018 02:48:54 +0000 (+1300) Subject: Use trait rather than parent class for acl test functions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2af6f0c0e027a078d6b4f6382ac0c05d50b9c6cb;p=civicrm-core.git Use trait rather than parent class for acl test functions This got separated out over a few recent commits (the first one seems to have somewhat accidentally included the trait & then some others added using it. Am just pushing in this tidy up --- diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 0a167c6b5c..57236d2dbb 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -114,9 +114,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { private $tx = NULL; /** - * @var CRM_Utils_Hook_UnitTests hookClass - * example of setting a method for a hook + * Class used for hooks during tests. + * + * This can be used to test hooks within tests. For example in the ACL_PermissionTrait: + * * $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults')); + * + * @var CRM_Utils_Hook_UnitTests hookClass */ public $hookClass = NULL; @@ -3575,20 +3579,6 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $this->_ids['membership_type'] = $membershipTypeID; } - /** - * No results returned. - * - * @implements CRM_Utils_Hook::aclWhereClause - * - * @param string $type - * @param array $tables - * @param array $whereTables - * @param int $contactID - * @param string $where - */ - public function aclWhereHookNoResults($type, &$tables, &$whereTables, &$contactID, &$where) { - } - /** * Only specified contact returned. * @implements CRM_Utils_Hook::aclWhereClause diff --git a/tests/phpunit/api/v3/ACLPermissionTest.php b/tests/phpunit/api/v3/ACLPermissionTest.php index edadb0fbb4..aeb56c316a 100644 --- a/tests/phpunit/api/v3/ACLPermissionTest.php +++ b/tests/phpunit/api/v3/ACLPermissionTest.php @@ -33,11 +33,12 @@ * @group headless */ class api_v3_ACLPermissionTest extends CiviUnitTestCase { + + use CRMTraits_ACL_PermissionTrait; + protected $_apiversion = 3; public $DBResetRequired = FALSE; protected $_entity; - protected $allowedContactId = 0; - protected $allowedContacts = array(); public function setUp() { parent::setUp(); @@ -442,47 +443,6 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase { ); } - /** - * All results returned. - * - * @implements CRM_Utils_Hook::aclWhereClause - * - * @param string $type - * @param array $tables - * @param array $whereTables - * @param int $contactID - * @param string $where - */ - public function aclWhereHookAllResults($type, &$tables, &$whereTables, &$contactID, &$where) { - $where = " (1) "; - } - - /** - * All but first results returned. - * @implements CRM_Utils_Hook::aclWhereClause - * @param $type - * @param $tables - * @param $whereTables - * @param $contactID - * @param $where - */ - public function aclWhereOnlySecond($type, &$tables, &$whereTables, &$contactID, &$where) { - $where = " contact_a.id > 1"; - } - - /** - * Only specified contact returned. - * @implements CRM_Utils_Hook::aclWhereClause - * @param $type - * @param $tables - * @param $whereTables - * @param $contactID - * @param $where - */ - public function aclWhereOnlyOne($type, &$tables, &$whereTables, &$contactID, &$where) { - $where = " contact_a.id = " . $this->allowedContactId; - } - /** * Basic check that an unpermissioned call keeps working and permissioned call fails. */ diff --git a/tests/phpunit/api/v3/EntityTagACLTest.php b/tests/phpunit/api/v3/EntityTagACLTest.php index 15dd6d1cb1..d2aec0f845 100644 --- a/tests/phpunit/api/v3/EntityTagACLTest.php +++ b/tests/phpunit/api/v3/EntityTagACLTest.php @@ -42,6 +42,8 @@ */ class api_v3_EntityTagACLTest extends CiviUnitTestCase { + use CRMTraits_ACL_PermissionTrait; + /** * API Version in use. * @@ -212,19 +214,4 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase { ), ($entity == 'Contacts' ? 1 : 0)); } - /** - * All results returned. - * - * @implements CRM_Utils_Hook::aclWhereClause - * - * @param string $type - * @param array $tables - * @param array $whereTables - * @param int $contactID - * @param string $where - */ - public function aclWhereHookAllResults($type, &$tables, &$whereTables, &$contactID, &$where) { - $where = " (1) "; - } - } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 91dec1b956..6039fea003 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -33,6 +33,9 @@ * @group headless */ class api_v3_ReportTemplateTest extends CiviUnitTestCase { + + use CRMTraits_ACL_PermissionTrait; + protected $_apiversion = 3; protected $contactIDs = [];