function PageNotFoundTest::testPageNotFound
Same name in other branches
- 9 core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFound()
- 10 core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFound()
- 11.x core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFound()
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ PageNotFoundTest.php, line 48
Class
- PageNotFoundTest
- Tests page not found functionality, including custom 404 pages.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testPageNotFound() {
$this->drupalLogin($this->adminUser);
$this->drupalGet($this->randomMachineName(10));
$this->assertText(t('Page not found'), 'Found the default 404 page');
// Set a custom 404 page without a starting slash.
$edit = [
'site_404' => 'user/' . $this->adminUser
->id(),
];
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this->assertRaw(new FormattableMarkup("The path '%path' has to start with a slash.", [
'%path' => $edit['site_404'],
]));
// Use a custom 404 page.
$edit = [
'site_404' => '/user/' . $this->adminUser
->id(),
];
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this->drupalGet($this->randomMachineName(10));
$this->assertText($this->adminUser
->getAccountName(), 'Found the custom 404 page');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.