You are here

public function RouterPermissionTest::testPermissionAccess in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Routing/RouterPermissionTest.php \Drupal\Tests\system\Functional\Routing\RouterPermissionTest::testPermissionAccess()

Tests permission requirements on routes.

File

core/modules/system/tests/src/Functional/Routing/RouterPermissionTest.php, line 29

Class

RouterPermissionTest
Function Tests for the routing permission system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testPermissionAccess() {

  // Ensure 403 Access Denied for a route without permission.
  $this
    ->drupalGet('router_test/test7');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Ensure 403 Access Denied by default if no access specified.
  $this
    ->drupalGet('router_test/test8');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $user = $this
    ->drupalCreateUser([
    'access test7',
  ]);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('router_test/test7');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertNoRaw('Access denied');
  $this
    ->assertRaw('test7text', 'The correct string was returned because the route was successful.');
}