function PermissionsPerBundleTest::testGrantPermissionsToAllBundlesExceptSome
Same name in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php \Drupal\KernelTests\Core\Recipe\PermissionsPerBundleTest::testGrantPermissionsToAllBundlesExceptSome()
Tests granting permissions for all bundles except certain ones.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ PermissionsPerBundleTest.php, line 160
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 testGrantPermissionsToAllBundlesExceptSome() : void {
$recipe_data = <<<YAML
name: 'Bundle specific permissions with some exceptions'
config:
actions:
user.role.super_editor:
grantPermissionsForEachNodeType:
permissions:
- view %bundle revisions
except:
- article
- blog
grantPermissionsForEachMediaType:
permissions: view any %bundle media revisions
except:
- controversial
grantPermissionsForEachTaxonomyVocabulary:
permissions:
- view term revisions in %bundle
except: tags
YAML;
$this->applyRecipeFromString($recipe_data);
$role = Role::load('super_editor');
$this->assertInstanceOf(Role::class, $role);
$this->assertTrue($role->hasPermission('view landing_page revisions'));
$this->assertFalse($role->hasPermission('view article revisions'));
$this->assertFalse($role->hasPermission('view blog revisions'));
$this->assertTrue($role->hasPermission('view any beautiful media revisions'));
$this->assertTrue($role->hasPermission('view any special media revisions'));
$this->assertFalse($role->hasPermission('view any controversial media revisions'));
$this->assertTrue($role->hasPermission('view term revisions in categories'));
$this->assertFalse($role->hasPermission('view term revisions in tags'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.