function PageNotFoundTest::testPageNotFoundCustomPageWithAccessDenied

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFoundCustomPageWithAccessDenied()
  2. 8.9.x core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFoundCustomPageWithAccessDenied()
  3. 10 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 79

Class

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

Namespace

Drupal\Tests\system\Functional\System

Code

public function testPageNotFoundCustomPageWithAccessDenied() : void {
    // 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');
}

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