annotate core/modules/system/src/Tests/System/ShutdownFunctionsTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\system\Tests\System;
Chris@0 4
Chris@0 5 use Drupal\simpletest\WebTestBase;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Functional tests shutdown functions.
Chris@0 9 *
Chris@0 10 * @group system
Chris@0 11 */
Chris@0 12 class ShutdownFunctionsTest extends WebTestBase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Modules to enable.
Chris@0 16 *
Chris@0 17 * @var array
Chris@0 18 */
Chris@0 19 public static $modules = ['system_test'];
Chris@0 20
Chris@0 21 protected function tearDown() {
Chris@0 22 // This test intentionally throws an exception in a PHP shutdown function.
Chris@0 23 // Prevent it from being interpreted as an actual test failure.
Chris@0 24 // Not using File API; a potential error must trigger a PHP warning.
Chris@0 25 unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
Chris@0 26 parent::tearDown();
Chris@0 27 }
Chris@0 28
Chris@0 29 /**
Chris@0 30 * Test shutdown functions.
Chris@0 31 */
Chris@0 32 public function testShutdownFunctions() {
Chris@0 33 $arg1 = $this->randomMachineName();
Chris@0 34 $arg2 = $this->randomMachineName();
Chris@0 35 $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
Chris@0 36
Chris@0 37 // If using PHP-FPM then fastcgi_finish_request() will have been fired
Chris@0 38 // returning the response before shutdown functions have fired.
Chris@0 39 // @see \Drupal\system_test\Controller\SystemTestController::shutdownFunctions()
Chris@0 40 $server_using_fastcgi = strpos($this->getRawContent(), 'The function fastcgi_finish_request exists when serving the request.');
Chris@0 41 if ($server_using_fastcgi) {
Chris@0 42 // We need to wait to ensure that the shutdown functions have fired.
Chris@0 43 sleep(1);
Chris@0 44 }
Chris@0 45 $this->assertEqual(\Drupal::state()->get('_system_test_first_shutdown_function'), [$arg1, $arg2]);
Chris@0 46 $this->assertEqual(\Drupal::state()->get('_system_test_second_shutdown_function'), [$arg1, $arg2]);
Chris@0 47
Chris@0 48 if (!$server_using_fastcgi) {
Chris@0 49 // Make sure exceptions displayed through
Chris@0 50 // \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly
Chris@0 51 // escaped.
Chris@0 52 $this->assertRaw('Drupal is &lt;blink&gt;awesome&lt;/blink&gt;.');
Chris@0 53 }
Chris@0 54 }
Chris@0 55
Chris@0 56 }