Fast404Test.php in Drupal 10
File
core/tests/Drupal/FunctionalTests/EventSubscriber/Fast404Test.php
View source
<?php
namespace Drupal\FunctionalTests\EventSubscriber;
use Drupal\Tests\BrowserTestBase;
class Fast404Test extends BrowserTestBase {
protected $defaultTheme = 'stark';
public function testFast404() : void {
$this
->drupalGet('does-not-exist');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->responseContains('modules/system/css/');
$this
->drupalGet('does-not-exist.txt');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->responseNotContains('modules/system/css/');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache', 'Miss');
$this
->drupalGet('does-not-exist.txt');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache', 'Hit');
$this
->assertSession()
->pageTextNotContains('Oops I did it again!');
$this
->config('system.performance')
->set('fast_404.html', '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Oops I did it again!</h1><p>The requested URL "@path" was not found on this server.</p></body></html>')
->save();
$this
->drupalGet('does-not-exist.txt');
$this
->assertSession()
->responseNotContains('modules/system/css/');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache', 'Miss');
$this
->assertSession()
->pageTextContains('Oops I did it again!');
$this
->config('system.performance')
->set('fast_404.enabled', FALSE)
->save();
$this
->drupalGet('does-not-exist.txt');
$this
->assertSession()
->responseContains('modules/system/css/');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache', 'Miss');
$this
->assertSession()
->pageTextNotContains('Oops I did it again!');
$settings['config']['system.performance']['fast_404']['enabled'] = (object) [
'value' => TRUE,
'required' => TRUE,
];
$this
->writeSettings($settings);
$this
->rebuildAll();
$this
->drupalGet('does-not-exist.txt');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->responseNotContains('modules/system/css/');
$this
->assertSession()
->responseHeaderContains('X-Generator', 'Drupal');
}
}