Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / UpdatePathTestJavaScriptTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6
7 /**
8  * Tests the presence of JavaScript at update.php.
9  *
10  * @group Update
11  */
12 class UpdatePathTestJavaScriptTest extends UpdatePathTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function setDatabaseDumpFiles() {
18     $this->databaseDumpFiles = [
19       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
20     ];
21   }
22
23   /**
24    * Test JavaScript loading at update.php.
25    *
26    * @see ::doPreUpdateTests
27    */
28   public function testJavaScriptLoading() {
29     $this->runUpdates();
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function doSelectionTest() {
36     // Ensure that at least one JS script has drupalSettings in there.
37     $scripts = $this->xpath('//script');
38     $found = FALSE;
39     foreach ($scripts as $script) {
40       if (!$script->getAttribute('src')) {
41         continue;
42       }
43       // Source is a root-relative URL. Transform it to an absolute URL to allow
44       // file_get_contents() to access the file.
45       $src = preg_replace('#^' . $GLOBALS['base_path'] . '(.*)#i', $GLOBALS['base_url'] . '/' . '${1}', $script->getAttribute('src'));
46       $file_content = file_get_contents($src);
47
48       if (strpos($file_content, 'window.drupalSettings =') !== FALSE) {
49         $found = TRUE;
50         break;
51       }
52     }
53
54     $this->assertTrue($found, 'Ensure that the drupalSettingsLoader.js was included in the JS files');
55   }
56
57 }