Merge pull request #14934 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / CRM / Core / Permission / BaseTest.php
1 <?php
2
3 /**
4 * Class CRM_Core_Permission_BaseTest
5 * @group headless
6 */
7 class CRM_Core_Permission_BaseTest extends CiviUnitTestCase {
8
9 /**
10 * @return array
11 * (0 => input to translatePermission, 1 => expected output from translatePermission)
12 */
13 public function translateData() {
14 $cases = [];
15
16 $cases[] = ["administer CiviCRM", "administer CiviCRM"];
17 $cases[] = ["cms:universal name", "local name"];
18 $cases[] = ["cms:universal name2", "local name2"];
19 $cases[] = ["cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
20 $cases[] = ["myruntime:foo", "foo"];
21 $cases[] = ["otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
22 $cases[] = ["otherruntime:foo:bar", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
23 $cases[] = [CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION];
24
25 return $cases;
26 }
27
28 /**
29 * @dataProvider translateData
30 * @param string $input
31 * The name of a permission which should be translated.
32 * @param string $expected
33 * The name of an actual permission (based on translation matrix for "runtime").
34 */
35 public function testTranslate($input, $expected) {
36 $perm = new CRM_Core_Permission_Base();
37 $actual = $perm->translatePermission($input, "myruntime", [
38 'universal name' => 'local name',
39 'universal name2' => 'local name2',
40 'gunk' => 'gunky',
41 ]);
42 $this->assertEquals($expected, $actual);
43 }
44
45 }