UserRolesPermissionsTest.php

Same filename in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Session/UserRolesPermissionsTest.php

Namespace

Drupal\KernelTests\Core\Session

File

core/tests/Drupal/KernelTests/Core/Session/UserRolesPermissionsTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\KernelTests\Core\Session;

use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;

/**
 * Test case for getting permissions from user roles.
 *
 * @group Session
 */
class UserRolesPermissionsTest extends KernelTestBase {
    use UserCreationTrait;
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'system',
        'user',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->installEntitySchema('user');
    }
    
    /**
     * Tests that assigning a role grants that role's permissions.
     */
    public function testPermissionChange() : void {
        // Create two accounts to avoid dealing with user 1.
        $this->createUser();
        $account = $this->createUser();
        $this->assertFalse($account->hasPermission('administer modules'));
        $account->addRole($this->createRole([
            'administer modules',
        ]))
            ->save();
        $this->assertTrue($account->hasPermission('administer modules'));
    }

}

Classes

Title Deprecated Summary
UserRolesPermissionsTest Test case for getting permissions from user roles.

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