function PageNotFoundTest::testPageNotFound

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

Class

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

Namespace

Drupal\Tests\system\Functional\System

Code

public function testPageNotFound() : void {
    $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.