Merge pull request #19180 from civicrm/5.33
[civicrm-core.git] / CRM / Core / Permission / UnitTests.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 *
20 */
21 class CRM_Core_Permission_UnitTests extends CRM_Core_Permission_Base {
22
23 /**
24 * permission mapping to stub check() calls
25 * @var array
26 */
27 public $permissions = NULL;
28
29 /**
30 * Given a permission string, check for access requirements
31 *
32 * @param string $str
33 * The permission to check.
34 * @param int $userId
35 *
36 * @return bool
37 * true if yes, else false
38 */
39 public function check($str, $userId = NULL) {
40 if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
41 return FALSE;
42 }
43 if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
44 return TRUE;
45 }
46
47 // return the stubbed permission (defaulting to true if the array is missing)
48 return is_array($this->permissions) ? in_array($str, $this->permissions) : TRUE;
49 }
50
51 /**
52 * Get the permissioned where clause for the user.
53 *
54 * @param int $type
55 * The type of permission needed.
56 * @param array $tables
57 * (reference ) add the tables that are needed for the select clause.
58 * @param array $whereTables
59 * (reference ) add the tables that are needed for the where clause.
60 *
61 * @return string
62 * the group where clause for this user
63 */
64 public function whereClause($type, &$tables, &$whereTables) {
65 return '( 1 )';
66 }
67
68 }