function PageNotFoundTest::testPageNotFound
File
- 
              core/modules/ system/ tests/ src/ Functional/ System/ PageNotFoundTest.php, line 50 
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->assertSession()
    ->pageTextContains('Page not found');
  // Set a custom 404 page without a starting slash.
  $edit = [
    'site_404' => 'user/' . $this->adminUser
      ->id(),
  ];
  $this->drupalGet('admin/config/system/site-information');
  $this->submitForm($edit, 'Save configuration');
  $this->assertSession()
    ->pageTextContains("The path '{$edit['site_404']}' has to start with a slash.");
  // Use a custom 404 page.
  $edit = [
    'site_404' => '/user/' . $this->adminUser
      ->id(),
  ];
  $this->drupalGet('admin/config/system/site-information');
  $this->submitForm($edit, 'Save configuration');
  $this->drupalGet($this->randomMachineName(10));
  $this->assertSession()
    ->pageTextContains($this->adminUser
    ->getAccountName());
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
