More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / modules / system / src / Tests / System / ShutdownFunctionsTest.php
1 <?php
2
3 namespace Drupal\system\Tests\System;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Functional tests shutdown functions.
9  *
10  * @group system
11  */
12 class ShutdownFunctionsTest extends WebTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['system_test'];
20
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');
26     parent::tearDown();
27   }
28
29   /**
30    * Test shutdown functions.
31    */
32   public function testShutdownFunctions() {
33     $arg1 = $this->randomMachineName();
34     $arg2 = $this->randomMachineName();
35     $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
36
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->getRawContent(), '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.
43       sleep(1);
44     }
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]);
47
48     if (!$server_using_fastcgi) {
49       // Make sure exceptions displayed through
50       // \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly
51       // escaped.
52       $this->assertRaw('Drupal is &lt;blink&gt;awesome&lt;/blink&gt;.');
53     }
54   }
55
56 }