public function UserPermissionsTest::testUserRoleChangePermissions in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/tests/src/Functional/UserPermissionsTest.php \Drupal\Tests\user\Functional\UserPermissionsTest::testUserRoleChangePermissions()
Verify proper permission changes by user_role_change_permissions().
File
- core/
modules/ user/ tests/ src/ Functional/ UserPermissionsTest.php, line 150
Class
- UserPermissionsTest
- Verify that role permissions can be added and removed via the permissions page.
Namespace
Drupal\Tests\user\FunctionalCode
public function testUserRoleChangePermissions() {
$permissions_hash_generator = $this->container
->get('user_permissions_hash_generator');
$rid = $this->rid;
$account = $this->adminUser;
$previous_permissions_hash = $permissions_hash_generator
->generate($account);
// Verify current permissions.
$this
->assertFalse($account
->hasPermission('administer users'), 'User does not have "administer users" permission.');
$this
->assertTrue($account
->hasPermission('access user profiles'), 'User has "access user profiles" permission.');
$this
->assertTrue($account
->hasPermission('administer site configuration'), 'User has "administer site configuration" permission.');
// Change permissions.
$permissions = [
'administer users' => 1,
'access user profiles' => 0,
];
user_role_change_permissions($rid, $permissions);
// Verify proper permission changes.
$this
->assertTrue($account
->hasPermission('administer users'), 'User now has "administer users" permission.');
$this
->assertFalse($account
->hasPermission('access user profiles'), 'User no longer has "access user profiles" permission.');
$this
->assertTrue($account
->hasPermission('administer site configuration'), 'User still has "administer site configuration" permission.');
// Verify the permissions hash has changed.
$current_permissions_hash = $permissions_hash_generator
->generate($account);
$this
->assertNotEqual($previous_permissions_hash, $current_permissions_hash, 'Permissions hash has changed.');
}