public function AccessDeniedTest::testAccessDeniedCustomPageWithAccessDenied in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/System/AccessDeniedTest.php \Drupal\Tests\system\Functional\System\AccessDeniedTest::testAccessDeniedCustomPageWithAccessDenied()
- 10 core/modules/system/tests/src/Functional/System/AccessDeniedTest.php \Drupal\Tests\system\Functional\System\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 128
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');
}