public function AccessDeniedTest::testAccessDeniedCustomPageWithAccessDenied in Drupal 8
Same name and namespace in other branches
- 9 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 125
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
->assertNoText('Admin-only 4xx response');
$this
->assertText('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
->assertText('Admin-only 4xx response');
$this
->assertSession()
->statusCodeEquals(403);
// Verify the access cacheability metadata for custom 403 is bubbled.
$this
->assertCacheContext('user.roles');
}