Skip to content
Snippets Groups Projects
Unverified Commit d9e8af2b authored by eileen's avatar eileen :8ball: Committed by GitHub
Browse files

Merge pull request #13269 from eileenmcnaughton/acltesttrait

[REF] Minor Test clean up
parents 7bdfc943 2ed07c20
Branches
Tags
No related merge requests found
......@@ -50,6 +50,20 @@ trait CRMTraits_ACL_PermissionTrait {
$where = " (1) ";
}
/**
* 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) {
}
/**
* All but first results returned.
*
......
......@@ -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;
......@@ -685,8 +689,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
}
/**
* @param $expected
* @param $actual
* Assert the 2 arrays have the same values.
*
* @param array $array1
* @param array $array2
*/
public function assertArrayValuesEqual($array1, $array2) {
$array1 = array_values($array1);
......@@ -1724,27 +1730,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
return $result;
}
/**
* Delete a UF Join Entry.
*
* @param array $params
* with missing uf_group_id
*/
public function ufjoinDelete($params = NULL) {
if ($params === NULL) {
$params = array(
'is_active' => 1,
'module' => 'CiviEvent',
'entity_table' => 'civicrm_event',
'entity_id' => 3,
'weight' => 1,
'uf_group_id' => '',
);
}
crm_add_uf_join($params);
}
/**
* @param array $params
* Optional parameters.
......@@ -3575,20 +3560,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
......
......@@ -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.
*/
......
......@@ -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) ";
}
}
......@@ -33,6 +33,9 @@
* @group headless
*/
class api_v3_ReportTemplateTest extends CiviUnitTestCase {
use CRMTraits_ACL_PermissionTrait;
protected $_apiversion = 3;
protected $contactIDs = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment