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