Merge branch 4.5 into master
[civicrm-core.git] / tests / phpunit / CRM / Core / Permission / BaseTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4
5 /**
6 * Class CRM_Core_Permission_BaseTest
7 */
8 class CRM_Core_Permission_BaseTest extends CiviUnitTestCase {
9
10 /**
11 * @return array
12 * (0 => input to translatePermission, 1 => expected output from translatePermission)
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
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").
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
46 }