Commit | Line | Data |
---|---|---|
085823c1 TO |
1 | <?php |
2 | ||
aba1cd8b EM |
3 | /** |
4 | * Class CRM_Core_Permission_BaseTest | |
acb109b7 | 5 | * @group headless |
aba1cd8b | 6 | */ |
085823c1 TO |
7 | class CRM_Core_Permission_BaseTest extends CiviUnitTestCase { |
8 | ||
755a1835 | 9 | use CRMTraits_ACL_PermissionTrait; |
10 | ||
085823c1 | 11 | /** |
a6c01b45 CW |
12 | * @return array |
13 | * (0 => input to translatePermission, 1 => expected output from translatePermission) | |
085823c1 | 14 | */ |
ea54c6e5 | 15 | public function translateData(): array { |
9099cab3 | 16 | $cases = []; |
085823c1 | 17 | |
755a1835 | 18 | $cases[] = ['administer CiviCRM', 'administer CiviCRM']; |
19 | $cases[] = ['cms:universal name', 'local name']; | |
20 | $cases[] = ['cms:universal name2', 'local name2']; | |
21 | $cases[] = ['cms:unknown universal name', CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; | |
22 | $cases[] = ['myruntime:foo', 'foo']; | |
23 | $cases[] = ['otherruntime:foo', CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; | |
24 | $cases[] = ['otherruntime:foo:bar', CRM_Core_Permission::ALWAYS_DENY_PERMISSION]; | |
9099cab3 | 25 | $cases[] = [CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION]; |
085823c1 TO |
26 | |
27 | return $cases; | |
28 | } | |
29 | ||
30 | /** | |
31 | * @dataProvider translateData | |
755a1835 | 32 | * |
e16033b4 TO |
33 | * @param string $input |
34 | * The name of a permission which should be translated. | |
35 | * @param string $expected | |
36 | * The name of an actual permission (based on translation matrix for "runtime"). | |
085823c1 | 37 | */ |
ea54c6e5 | 38 | public function testTranslate(string $input, string $expected): void { |
085823c1 | 39 | $perm = new CRM_Core_Permission_Base(); |
755a1835 | 40 | $actual = $perm->translatePermission($input, 'myruntime', [ |
085823c1 TO |
41 | 'universal name' => 'local name', |
42 | 'universal name2' => 'local name2', | |
43 | 'gunk' => 'gunky', | |
9099cab3 | 44 | ]); |
085823c1 TO |
45 | $this->assertEquals($expected, $actual); |
46 | } | |
96025800 | 47 | |
755a1835 | 48 | /** |
49 | * Test that the user has the implied permission of administer CiviCRM data by virtue of having administer CiviCRM. | |
50 | */ | |
ea54c6e5 | 51 | public function testImpliedPermission(): void { |
755a1835 | 52 | $this->createLoggedInUser(); |
53 | CRM_Core_Config::singleton()->userPermissionClass->permissions = [ | |
54 | 'administer CiviCRM', | |
55 | ]; | |
56 | $this->assertTrue(CRM_Core_Permission::check('administer CiviCRM data')); | |
57 | } | |
58 | ||
ea54c6e5 | 59 | /** |
60 | * Test that the super permission gives the implied permission of the whole shebang. | |
61 | */ | |
62 | public function testImpliedPermissionSuperDuper(): void { | |
63 | $this->createLoggedInUser(); | |
64 | CRM_Core_Config::singleton()->userPermissionClass->permissions = [ | |
65 | 'all CiviCRM permissions and ACLs', | |
66 | ]; | |
67 | $this->assertTrue(CRM_Core_Permission::check('view all contacts')); | |
68 | } | |
69 | ||
085823c1 | 70 | } |