You are here

public function PageNotFoundTest::testPageNotFound in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/PageNotFoundTest.php \Drupal\Tests\system\Functional\System\PageNotFoundTest::testPageNotFound()
  2. 9 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 47

Class

PageNotFoundTest
Tests page not found functionality, including custom 404 pages.

Namespace

Drupal\Tests\system\Functional\System

Code

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());
}