You are here

public function SiteMaintenanceTest::testNonHtmlRequest in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php \Drupal\Tests\system\Functional\System\SiteMaintenanceTest::testNonHtmlRequest()

Tests responses to non-HTML requests when in maintenance mode.

File

core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php, line 159

Class

SiteMaintenanceTest
Tests access to site while in maintenance mode.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testNonHtmlRequest() {
  $this
    ->drupalLogout();
  \Drupal::state()
    ->set('system.maintenance_mode', TRUE);
  $formats = [
    'json',
    'xml',
    'non-existing',
  ];
  foreach ($formats as $format) {
    $this
      ->drupalGet('<front>', [
      'query' => [
        '_format' => $format,
      ],
    ]);
    $this
      ->assertSession()
      ->statusCodeEquals(503);
    $this
      ->assertRaw('Drupal is currently under maintenance. We should be back shortly. Thank you for your patience.');
    $this
      ->assertSession()
      ->responseHeaderEquals('Content-Type', 'text/plain; charset=UTF-8');
  }
}