From ffeb4a7d20c2c9c4eca817ad216479dc7c166f65 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 1 Sep 2015 14:43:04 +0100 Subject: [PATCH] Issue #2560521 by dawehner, plach, larowlan, lauriii, Xano, Wim Leers, catch, jhedstrom: Javascript does not work on beta 12 => HEAD update.php --- core/lib/Drupal/Core/Update/UpdateKernel.php | 29 ++++++++++ .../Core/Update/UpdateServiceProvider.php | 42 ++++++++++++++ .../src/Tests/Update/UpdatePathTestBase.php | 10 ++++ .../Update/UpdatePathTestJavaScriptTest.php | 58 +++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 core/lib/Drupal/Core/Update/UpdateServiceProvider.php create mode 100644 core/modules/system/src/Tests/Update/UpdatePathTestJavaScriptTest.php diff --git a/core/lib/Drupal/Core/Update/UpdateKernel.php b/core/lib/Drupal/Core/Update/UpdateKernel.php index 6c5de739fcc6..80f243c8b4e8 100644 --- a/core/lib/Drupal/Core/Update/UpdateKernel.php +++ b/core/lib/Drupal/Core/Update/UpdateKernel.php @@ -26,6 +26,35 @@ */ class UpdateKernel extends DrupalKernel { + /** + * {@inheritdoc} + */ + public function discoverServiceProviders() { + parent::discoverServiceProviders(); + + $this->serviceProviderClasses['app']['update_kernel'] = 'Drupal\Core\Update\UpdateServiceProvider'; + } + + /** + * {@inheritdoc} + */ + protected function initializeContainer() { + // Always force a container rebuild, in order to be able to override some + // services, see \Drupal\Core\Update\UpdateServiceProvider. + $this->containerNeedsRebuild = TRUE; + $container = parent::initializeContainer(); + return $container; + } + + /** + * {@inheritdoc} + */ + protected function cacheDrupalContainer(array $container_definition) { + // Don't save this particular container to cache, so it does not leak into + // the main site at all. + return FALSE; + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Update/UpdateServiceProvider.php b/core/lib/Drupal/Core/Update/UpdateServiceProvider.php new file mode 100644 index 000000000000..510080a53bf6 --- /dev/null +++ b/core/lib/Drupal/Core/Update/UpdateServiceProvider.php @@ -0,0 +1,42 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Update\UpdateServiceProvider. + */ + +namespace Drupal\Core\Update; + +use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\DependencyInjection\ServiceModifierInterface; +use Drupal\Core\DependencyInjection\ServiceProviderInterface; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Ensures for some services that they don't cache. + */ +class UpdateServiceProvider implements ServiceProviderInterface, ServiceModifierInterface { + + /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container) { + $definition = new Definition('Drupal\Core\Cache\NullBackend', ['null']); + $container->setDefinition('cache.null', $definition); + } + + /** + * {@inheritdoc} + */ + public function alter(ContainerBuilder $container) { + $definition = $container->getDefinition('asset.resolver'); + $argument = new Reference('cache.null'); + $definition->replaceArgument(5, $argument); + + $definition = $container->getDefinition('library.discovery.collector'); + $argument = new Reference('cache.null'); + $definition->replaceArgument(0, $argument); + } + +} diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php index fbb6deecacab..2dd61e52aaa8 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php @@ -238,6 +238,7 @@ protected function runUpdates() { $this->drupalGet($this->updateUrl); $this->clickLink(t('Continue')); + $this->doSelectionTest(); // Run the update hooks. $this->clickLink(t('Apply pending updates')); @@ -273,4 +274,13 @@ protected function replaceUser1() { $account->save(); } + /** + * Tests the selection page. + */ + protected function doSelectionTest() { + // No-op. Tests wishing to do test the selection page or the general + // update.php environment before running update.php can override this method + // and implement their required tests. + } + } diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestJavaScriptTest.php b/core/modules/system/src/Tests/Update/UpdatePathTestJavaScriptTest.php new file mode 100644 index 000000000000..f3c82d0ebf15 --- /dev/null +++ b/core/modules/system/src/Tests/Update/UpdatePathTestJavaScriptTest.php @@ -0,0 +1,58 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Tests\Update\UpdatePathTestJavaScriptTest.php + */ + +namespace Drupal\system\Tests\Update; + +/** + * Tests the presence of JavaScript at update.php. + * + * @group Update + */ +class UpdatePathTestJavaScriptTest extends UpdatePathTestBase { + + /** + * {@inheritdoc} + */ + protected function setDatabaseDumpFiles() { + $this->databaseDumpFiles = [ + __DIR__ . '/../../../tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Test JavaScript loading at update.php. + * + * @see ::doPreUpdateTests + */ + public function testJavaScriptLoading() { + $this->runUpdates(); + } + + /** + * {@inheritdoc} + */ + protected function doSelectionTest() { + // Ensure that at least one JS script has drupalSettings in there. + $scripts = $this->xpath('//script'); + $found = FALSE; + foreach ($scripts as $script) { + if (!isset($script['src'])) { + continue; + } + $src = (string) $script['src']; + $file_content = file_get_contents($src); + + if (strpos($file_content, 'window.drupalSettings =') !== FALSE) { + $found = TRUE; + break; + } + } + + $this->assertTrue($found, 'Ensure that the drupalSettingsLoader.js was included in the JS files'); + } + +} -- GitLab