function ShutdownFunctionsTest::testShutdownFunctions

Same name in other branches
  1. 7.x modules/system/system.test \ShutdownFunctionsTest::testShutdownFunctions()
  2. 9 core/modules/system/tests/src/Functional/System/ShutdownFunctionsTest.php \Drupal\Tests\system\Functional\System\ShutdownFunctionsTest::testShutdownFunctions()
  3. 8.9.x core/modules/system/tests/src/Functional/System/ShutdownFunctionsTest.php \Drupal\Tests\system\Functional\System\ShutdownFunctionsTest::testShutdownFunctions()
  4. 11.x core/modules/system/tests/src/Functional/System/ShutdownFunctionsTest.php \Drupal\Tests\system\Functional\System\ShutdownFunctionsTest::testShutdownFunctions()

Tests shutdown functions.

File

core/modules/system/tests/src/Functional/System/ShutdownFunctionsTest.php, line 40

Class

ShutdownFunctionsTest
Functional tests shutdown functions.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testShutdownFunctions() : void {
    $arg1 = $this->randomMachineName();
    $arg2 = $this->randomMachineName();
    $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
    // If using PHP-FPM or output buffering, the response will be flushed to
    // the client before shutdown functions have fired.
    // @see \Drupal\system_test\Controller\SystemTestController::shutdownFunctions()
    $response_will_flush = strpos($this->getSession()
        ->getPage()
        ->getContent(), 'The response will flush before shutdown functions are called.');
    if ($response_will_flush) {
        // We need to wait to ensure that the shutdown functions have fired.
        sleep(1);
    }
    $this->assertEquals([
        $arg1,
        $arg2,
    ], \Drupal::state()->get('_system_test_first_shutdown_function'));
    $this->assertEquals([
        $arg1,
        $arg2,
    ], \Drupal::state()->get('_system_test_second_shutdown_function'));
    if (!$response_will_flush) {
        // Make sure exceptions displayed through
        // \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly
        // escaped.
        $this->assertSession()
            ->responseContains('Drupal is <blink>awesome</blink>.');
    }
}

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