You are here

public function PageNotFoundTest::testPageNotFoundCustomPageWithAccessDenied in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFoundCustomPageWithAccessDenied()

Tests that an inaccessible custom 404 page falls back to the default.

File

core/modules/system/tests/src/Functional/System/PageNotFoundTest.php, line 74

Class

PageNotFoundTest
Tests page not found functionality, including custom 404 pages.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testPageNotFoundCustomPageWithAccessDenied() {

  // Sets up a 404 page not accessible by the anonymous user.
  $this
    ->config('system.site')
    ->set('page.404', '/system-test/custom-4xx')
    ->save();
  $this
    ->drupalGet('/this-path-does-not-exist');
  $this
    ->assertSession()
    ->pageTextNotContains('Admin-only 4xx response');
  $this
    ->assertSession()
    ->pageTextContains('The requested page could not be found.');
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Verify the access cacheability metadata for custom 404 is bubbled.
  $this
    ->assertCacheContext('user.roles');
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('/this-path-does-not-exist');
  $this
    ->assertSession()
    ->pageTextContains('Admin-only 4xx response');
  $this
    ->assertSession()
    ->pageTextNotContains('The requested page could not be found.');
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Verify the access cacheability metadata for custom 404 is bubbled.
  $this
    ->assertCacheContext('user.roles');
}