function PermissionsPerBundleTest::testGrantPermissionsPerBundle
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php \Drupal\KernelTests\Core\Recipe\PermissionsPerBundleTest::testGrantPermissionsPerBundle()
Tests granting multiple bundle-specific permissions.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ PermissionsPerBundleTest.php, line 72
Class
- PermissionsPerBundleTest
- @covers \Drupal\Core\Config\Action\Plugin\ConfigAction\PermissionsPerBundle @covers \Drupal\Core\Config\Action\Plugin\ConfigAction\Deriver\PermissionsPerBundleDeriver
Namespace
Drupal\KernelTests\Core\RecipeCode
public function testGrantPermissionsPerBundle() : void {
$recipe_data = <<<YAML
name: 'Multi permissions!'
config:
actions:
user.role.super_editor:
grantPermissionsForEachNodeType:
- create %bundle content
- edit own %bundle content
grantPermissionsForEachMediaType:
permissions:
- create %bundle media
- edit own %bundle media
grantPermissionsForEachTaxonomyVocabulary: create terms in %bundle
YAML;
$this->applyRecipeFromString($recipe_data);
$expected_permissions = [
'create article content',
'create blog content',
'create landing_page content',
'edit own article content',
'edit own blog content',
'edit own landing_page content',
'create beautiful media',
'create controversial media',
'create special media',
'edit own beautiful media',
'edit own controversial media',
'edit own special media',
'create terms in tags',
'create terms in categories',
];
$role = Role::load('super_editor');
assert($role instanceof RoleInterface);
foreach ($expected_permissions as $permission) {
$this->assertTrue($role->hasPermission($permission));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.