From fd2068b12e27aea3c11c33823487d41997f561db Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 3 Dec 2020 23:35:06 -0800 Subject: [PATCH] APIv4 - Add "Permission.get" test. Include BD/D7/D8/WP variants. --- tests/phpunit/E2E/Api4/PermissionTest.php | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/phpunit/E2E/Api4/PermissionTest.php diff --git a/tests/phpunit/E2E/Api4/PermissionTest.php b/tests/phpunit/E2E/Api4/PermissionTest.php new file mode 100644 index 0000000000..9de532e000 --- /dev/null +++ b/tests/phpunit/E2E/Api4/PermissionTest.php @@ -0,0 +1,59 @@ + 'Drupal:post comments', + 'Drupal' => 'Drupal:post comments', + 'Drupal8' => 'Drupal:post comments', + 'WordPress' => 'WordPress:list_users', + ]; + + $perms = \civicrm_api4('Permission', 'get')->indexBy('name'); + $this->assertTrue(isset($perms['administer CiviCRM'])); + + $isOptionalString = function($arr, $key) { + return !array_key_exists($key, $arr) + || is_string($arr[$key]) + || $arr[$key] === NULL; + }; + + foreach ($perms as $permName => $perm) { + $ser = json_encode($perm, JSON_UNESCAPED_SLASHES); + $this->assertTrue(is_string($permName), 'Permission name should be a string'); + $this->assertTrue($isOptionalString($perm, 'title'), "Permission \"$permName\" should have string \"title\" ($ser)"); + $this->assertTrue($isOptionalString($perm, 'description'), "Permission \"$permName\" should have string \"description\" ($ser)"); + $this->assertTrue($isOptionalString($perm, 'group'), "Permission \"$permName\" should have string \"group\" ($ser)"); + $this->assertTrue(is_bool($perm['is_active']), "Permission \"$permName\" should have boolean \"is_active\" ($ser)"); + $this->assertTrue(is_bool($perm['is_synthetic']), "Permission \"$permName\" should have boolean \"is_synthetic\" ($ser)"); + } + + $groups = array_unique(\CRM_Utils_Array::collect('group', $perms->getArrayCopy())); + $this->assertTrue(in_array('civicrm', $groups), 'There should be at least one permission in the "civicrm" group.'); + $this->assertTrue(in_array('cms', $groups), 'There should be at least one permission in the "cms" group.'); + $this->assertTrue(in_array('const', $groups), 'There should be at least one permission in the "const" group.'); + + if (isset($smokeTest[CIVICRM_UF])) { + $smokeTestPerm = $smokeTest[CIVICRM_UF]; + $this->assertTrue(isset($perms[$smokeTestPerm])); + $this->assertTrue(is_bool($perm['is_active']), "Smoke-test permission \"$smokeTestPerm\" should have boolean \"is_active\""); + } + } + +} -- 2.25.1