Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[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  * @group legacy
12  */
13 class UpdatePathTestJavaScriptTest extends UpdatePathTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setDatabaseDumpFiles() {
19     $this->databaseDumpFiles = [
20       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
21     ];
22   }
23
24   /**
25    * Test JavaScript loading at update.php.
26    *
27    * @see ::doPreUpdateTests
28    */
29   public function testJavaScriptLoading() {
30     $this->runUpdates();
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function doSelectionTest() {
37     // Ensure that at least one JS script has drupalSettings in there.
38     $scripts = $this->xpath('//script');
39     $found = FALSE;
40     foreach ($scripts as $script) {
41       if (!$script->getAttribute('src')) {
42         continue;
43       }
44       // Source is a root-relative URL. Transform it to an absolute URL to allow
45       // file_get_contents() to access the file.
46       $src = preg_replace('#^' . $GLOBALS['base_path'] . '(.*)#i', $GLOBALS['base_url'] . '/' . '${1}', $script->getAttribute('src'));
47       $file_content = file_get_contents($src);
48
49       if (strpos($file_content, 'window.drupalSettings =') !== FALSE) {
50         $found = TRUE;
51         break;
52       }
53     }
54
55     $this->assertTrue($found, 'Ensure that the drupalSettingsLoader.js was included in the JS files');
56   }
57
58 }