function SiteMaintenanceTest::testNonHtmlRequest

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

Class

SiteMaintenanceTest
Tests access to site while in maintenance mode.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testNonHtmlRequest() : void {
    $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->assertSession()
            ->pageTextContains('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');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.