You are here

public function ManagedRolePermissionsTest::testManagedRolePermissionCallbacks in farmOS 2.x

Test that managed roles get permissions provided by callbacks.

File

modules/core/role/tests/src/Kernel/ManagedRolePermissionsTest.php, line 91

Class

ManagedRolePermissionsTest
Tests for Managed Role permissions.

Namespace

Drupal\Tests\farm_role\Kernel

Code

public function testManagedRolePermissionCallbacks() {

  // Create a user.
  $user = $this
    ->setUpCurrentUser([], [], FALSE);

  // Ensure the user does not include permission callback.
  $this
    ->assertFalse($user
    ->hasPermission('default callback permission'));

  // Ensure the farm_test includes valid callbacks permissions.
  $user
    ->addRole('farm_test');
  $this
    ->assertTrue($user
    ->hasPermission('default callback permission'));
  $this
    ->assertFalse($user
    ->hasPermission('my manager permission'));
  $this
    ->assertFalse($user
    ->hasPermission('recover all permission'));

  // Ensure the farm_test_manager role includes valid callback perms.
  $user
    ->addRole('farm_test_manager');
  $this
    ->assertTrue($user
    ->hasPermission('default callback permission'));
  $this
    ->assertTrue($user
    ->hasPermission('my manager permission'));
  $this
    ->assertTrue($user
    ->hasPermission('recover all permission'));
}