function RoleAccessCheckTest::roleAccessProvider

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php \Drupal\Tests\Core\Route\RoleAccessCheckTest::roleAccessProvider()
  2. 10 core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php \Drupal\Tests\Core\Route\RoleAccessCheckTest::roleAccessProvider()
  3. 11.x core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php \Drupal\Tests\Core\Route\RoleAccessCheckTest::roleAccessProvider()

Provides data for the role access test.

See also

\Drupal\Tests\Core\Route\RouterRoleTest::testRoleAccess

File

core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php, line 88

Class

RoleAccessCheckTest
@coversDefaultClass \Drupal\user\Access\RoleAccessCheck @group Access @group Route

Namespace

Drupal\Tests\Core\Route

Code

public function roleAccessProvider() {
    // Setup two different roles used in the test.
    $rid_1 = 'role_test_1';
    $rid_2 = 'role_test_2';
    // Setup one user with the first role, one with the second, one with both
    // and one final without any of these two roles.
    $account_1 = new UserSession([
        'uid' => 1,
        'roles' => [
            $rid_1,
        ],
    ]);
    $account_2 = new UserSession([
        'uid' => 2,
        'roles' => [
            $rid_2,
        ],
    ]);
    $account_12 = new UserSession([
        'uid' => 3,
        'roles' => [
            $rid_1,
            $rid_2,
        ],
    ]);
    $account_none = new UserSession([
        'uid' => 1,
        'roles' => [],
    ]);
    // Setup expected values; specify which paths can be accessed by which user.
    return [
        [
            'role_test_1',
            [
                $account_1,
                $account_12,
            ],
            [
                $account_2,
                $account_none,
            ],
        ],
        [
            'role_test_2',
            [
                $account_2,
                $account_12,
            ],
            [
                $account_1,
                $account_none,
            ],
        ],
        [
            'role_test_3',
            [
                $account_12,
            ],
            [
                $account_1,
                $account_2,
                $account_none,
            ],
        ],
        [
            'role_test_4',
            [
                $account_12,
            ],
            [
                $account_1,
                $account_2,
                $account_none,
            ],
        ],
        [
            'role_test_5',
            [
                $account_1,
                $account_2,
                $account_12,
            ],
            [],
        ],
        [
            'role_test_6',
            [
                $account_1,
                $account_2,
                $account_12,
            ],
            [],
        ],
    ];
}

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