public function RoleAccessCheckTest::roleAccessProvider

Provides data for the role access test.

See also

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

File

drupal/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php, line 103
Contains \Drupal\Tests\Core\Route\RoleAccessCheckTest.

Class

RoleAccessCheckTest
Defines tests for role based access in routes.

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 = (object) array(
    'uid' => 1,
    'roles' => array(
      $rid_1,
    ),
  );
  $account_2 = (object) array(
    'uid' => 2,
    'roles' => array(
      $rid_2,
    ),
  );
  $account_12 = (object) array(
    'uid' => 3,
    'roles' => array(
      $rid_1,
      $rid_2,
    ),
  );
  $account_none = (object) array(
    'uid' => 1,
    'roles' => array(),
  );

  // Setup expected values; specify which paths can be accessed by which user.
  return array(
    array(
      'role_test_1',
      array(
        $account_1,
        $account_12,
      ),
      array(
        $account_2,
        $account_none,
      ),
    ),
    array(
      'role_test_2',
      array(
        $account_2,
        $account_12,
      ),
      array(
        $account_1,
        $account_none,
      ),
    ),
    array(
      'role_test_3',
      array(
        $account_12,
      ),
      array(
        $account_1,
        $account_2,
        $account_none,
      ),
    ),
    array(
      'role_test_4',
      array(
        $account_12,
      ),
      array(
        $account_1,
        $account_2,
        $account_none,
      ),
    ),
    array(
      'role_test_5',
      array(
        $account_1,
        $account_2,
        $account_12,
      ),
      array(),
    ),
    array(
      'role_test_6',
      array(
        $account_1,
        $account_2,
        $account_12,
      ),
      array(),
    ),
  );
}