function PermissionsPerBundleTest::testGrantPermissionsOnOneBundleThenAll

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php \Drupal\KernelTests\Core\Recipe\PermissionsPerBundleTest::testGrantPermissionsOnOneBundleThenAll()

Tests granting permissions for one bundle, then all of them.

File

core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php, line 134

Class

PermissionsPerBundleTest
@covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Config%21Action%21Plugin%21ConfigAction%21PermissionsPerBundle.php/class/PermissionsPerBundle/11.x" title="@internal This API is experimental." class="local">\Drupal\Core\Config\Action\Plugin\ConfigAction\PermissionsPerBundle</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Config%21Action%21Plugin%21ConfigAction%21Deriver%21PermissionsPerBundleDeriver.php/class/PermissionsPerBundleDeriver/11.x" title="@internal This API is experimental." class="local">\Drupal\Core\Config\Action\Plugin\ConfigAction\Deriver\PermissionsPerBundleDeriver</a>

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testGrantPermissionsOnOneBundleThenAll() : void {
    $recipe_data = <<<YAML
name: 'All bundles except one'
config:
  actions:
    user.role.super_editor:
      grantPermissions:
        - create beautiful media
        - edit own beautiful media
      grantPermissionsForEachMediaType:
        - create %bundle media
        - edit own %bundle media
YAML;
    $this->applyRecipeFromString($recipe_data);
    $role = Role::load('super_editor');
    $this->assertInstanceOf(Role::class, $role);
    $this->assertTrue($role->hasPermission('create beautiful media'));
    $this->assertTrue($role->hasPermission('edit own beautiful media'));
    $this->assertTrue($role->hasPermission('create controversial media'));
    $this->assertTrue($role->hasPermission('edit own beautiful media'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.