function LegacyUserTest::testUserRolePermissions
Tests deprecation of user_role_permissions().
File
- 
              core/
modules/ user/ tests/ src/ Kernel/ LegacyUserTest.php, line 30  
Class
- LegacyUserTest
 - Tests deprecated user module functions.
 
Namespace
Drupal\Tests\user\KernelCode
public function testUserRolePermissions() : void {
  $this->expectDeprecation('user_role_permissions() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement beyond loading the roles and calling \\Drupal\\user\\Entity\\Role::getPermissions(). See https://www.drupal.org/node/3348138');
  $expected = [
    RoleInterface::ANONYMOUS_ID => [],
    RoleInterface::AUTHENTICATED_ID => [],
  ];
  $permissions = user_role_permissions(array_keys($expected));
  $this->assertSame($expected, $permissions);
  $permission = 'administer permissions';
  $role = Role::create([
    'id' => 'admin',
    'label' => 'Test',
    'is_admin' => TRUE,
    'permissions' => [
      $permission,
    ],
  ]);
  $role->save();
  $permissions = user_role_permissions([
    $role->id(),
  ]);
  $this->assertSame([
    $role->id() => [],
  ], $permissions);
  $role->setIsAdmin(FALSE)
    ->grantPermission($permission)
    ->save();
  $permissions = user_role_permissions([
    $role->id(),
  ]);
  $this->assertSame([
    $role->id() => [
      $permission,
    ],
  ], $permissions);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.