function AccessDeniedTest::testAccessDeniedCustomPageWithAccessDenied
Tests that an inaccessible custom 403 page falls back to the default.
File
- 
              core/modules/ system/ tests/ src/ Functional/ System/ AccessDeniedTest.php, line 131 
Class
- AccessDeniedTest
- Tests page access denied functionality, including custom 403 pages.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testAccessDeniedCustomPageWithAccessDenied() {
  // Sets up a 403 page not accessible by the anonymous user.
  $this->config('system.site')
    ->set('page.403', '/system-test/custom-4xx')
    ->save();
  $this->drupalGet('/system-test/always-denied');
  $this->assertSession()
    ->pageTextNotContains('Admin-only 4xx response');
  $this->assertSession()
    ->pageTextContains('You are not authorized to access this page.');
  $this->assertSession()
    ->statusCodeEquals(403);
  // Verify the access cacheability metadata for custom 403 is bubbled.
  $this->assertCacheContext('user.roles');
  $this->drupalLogin($this->adminUser);
  $this->drupalGet('/system-test/always-denied');
  $this->assertSession()
    ->pageTextContains('Admin-only 4xx response');
  $this->assertSession()
    ->statusCodeEquals(403);
  // Verify the access cacheability metadata for custom 403 is bubbled.
  $this->assertCacheContext('user.roles');
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
