3 namespace Drupal\Tests\system\Functional\System;
5 use Drupal\Tests\BrowserTestBase;
8 * Functional tests shutdown functions.
12 class ShutdownFunctionsTest extends BrowserTestBase {
19 public static $modules = ['system_test'];
21 protected function tearDown() {
22 // This test intentionally throws an exception in a PHP shutdown function.
23 // Prevent it from being interpreted as an actual test failure.
24 // Not using File API; a potential error must trigger a PHP warning.
25 unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
30 * Test shutdown functions.
32 public function testShutdownFunctions() {
33 $arg1 = $this->randomMachineName();
34 $arg2 = $this->randomMachineName();
35 $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
37 // If using PHP-FPM then fastcgi_finish_request() will have been fired
38 // returning the response before shutdown functions have fired.
39 // @see \Drupal\system_test\Controller\SystemTestController::shutdownFunctions()
40 $server_using_fastcgi = strpos($this->getSession()->getPage()->getContent(), 'The function fastcgi_finish_request exists when serving the request.');
41 if ($server_using_fastcgi) {
42 // We need to wait to ensure that the shutdown functions have fired.
45 $this->assertEqual(\Drupal::state()->get('_system_test_first_shutdown_function'), [$arg1, $arg2]);
46 $this->assertEqual(\Drupal::state()->get('_system_test_second_shutdown_function'), [$arg1, $arg2]);
48 if (!$server_using_fastcgi) {
49 // Make sure exceptions displayed through
50 // \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly
52 $this->assertRaw('Drupal is <blink>awesome</blink>.');