Skip to content
Snippets Groups Projects
Commit d7246753 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3274858 by phenaproxima: CoreUpdateTest should test that...

Issue #3274858 by phenaproxima: CoreUpdateTest should test that default.settings.php and default.services.yml can be updated
parent 04013d23
No related branches found
No related tags found
1 merge request!266Issue #3274858: CoreUpdateTest should test that default.settings.php and default.services.yml can be updated
......@@ -36,43 +36,29 @@ class SiteConfigurationExcluder implements EventSubscriberInterface {
}
/**
* Excludes common paths from staging operations.
* Excludes site configuration files from staging operations.
*
* @param \Drupal\package_manager\Event\PreApplyEvent|\Drupal\package_manager\Event\PreCreateEvent $event
* The event object.
*
* @see \Drupal\package_manager\Event\ExcludedPathsTrait::excludePath()
*/
public function ignoreCommonPaths(StageEvent $event): void {
public function excludeSiteConfiguration(StageEvent $event): void {
// Site configuration files are always excluded relative to the web root.
$web = [];
$paths = [];
// Ignore site-specific settings files, which are always in the web root.
// By default, Drupal core will always try to write-protect these files.
$settings_files = [
'settings.php',
'settings.local.php',
'services.yml',
];
foreach ($settings_files as $settings_file) {
$web[] = $this->sitePath . '/' . $settings_file;
$web[] = 'sites/default/' . $settings_file;
$paths[] = $this->sitePath . '/' . $settings_file;
$paths[] = 'sites/default/' . $settings_file;
}
$this->excludeInWebRoot($event, $web);
}
/**
* Reacts before staged changes are committed the active directory.
*
* @param \Drupal\package_manager\Event\PreApplyEvent $event
* The event object.
*/
public function preApply(PreApplyEvent $event): void {
// Don't copy anything from the staging area's sites/default.
// @todo Make this a lot smarter in https://www.drupal.org/i/3228955.
$this->excludeInWebRoot($event, ['sites/default']);
$this->ignoreCommonPaths($event);
$this->excludeInWebRoot($event, $paths);
}
/**
......@@ -80,8 +66,8 @@ class SiteConfigurationExcluder implements EventSubscriberInterface {
*/
public static function getSubscribedEvents() {
return [
PreCreateEvent::class => 'ignoreCommonPaths',
PreApplyEvent::class => 'preApply',
PreCreateEvent::class => 'excludeSiteConfiguration',
PreApplyEvent::class => 'excludeSiteConfiguration',
];
}
......
......@@ -75,13 +75,12 @@ class SiteConfigurationExcluderTest extends PackageManagerKernelTestBase {
// Regular module files should be staged.
$this->assertFileExists("$stage_dir/modules/example/example.info.yml");
// A new file added to the staging area in an excluded directory, should not
// be copied to the active directory.
$file = "$stage_dir/sites/default/no-copy.txt";
// A new file added to the site directory in the staging area should be
// copied to the active directory.
$file = "$stage_dir/sites/default/new.txt";
touch($file);
$this->assertFileExists($file);
$stage->apply();
$this->assertFileDoesNotExist("$active_dir/sites/default/no-copy.txt");
$this->assertFileExists("$active_dir/sites/default/new.txt");
// The ignored files should still be in the active directory.
foreach ($ignore as $path) {
......
......@@ -51,6 +51,9 @@ class CoreUpdateTest extends UpdateTestBase {
$this->checkForUpdates();
$this->visit('/admin/modules/automatic-update');
$this->getMink()->assertSession()->pageTextContains('9.8.1');
// Ensure that Drupal has write-protected the site directory.
$this->assertDirectoryIsNotWritable($this->getWebRoot() . '/sites/default');
}
/**
......@@ -184,10 +187,20 @@ class CoreUpdateTest extends UpdateTestBase {
}
// Change the \Drupal::VERSION constant and put placeholder text in the
// README so we can ensure that we really updated to the correct version.
// README so we can ensure that we really updated to the correct version. We
// also change the default site configuration files so we can ensure that
// these are updated as well, despite `sites/default` being write-protected.
// @see ::assertUpdateSuccessful()
// @see ::createTestProject()
Composer::setDrupalVersion($workspace_dir, $version);
file_put_contents("$workspace_dir/core/README.txt", "Placeholder for Drupal core $version.");
foreach (['default.settings.php', 'default.services.yml'] as $file) {
$file = fopen("$workspace_dir/core/assets/scaffold/files/$file", 'a');
$this->assertIsResource($file);
fwrite($file, "# This is part of Drupal $version.\n");
fclose($file);
}
}
/**
......@@ -225,12 +238,23 @@ class CoreUpdateTest extends UpdateTestBase {
$this->getMink()->assertSession()->pageTextContains('No update available');
// The status page should report that we're running the expected version and
// the README should contain the placeholder text written by
// ::setUpstreamCoreVersion().
// the README and default site configuration files should contain the
// placeholder text written by ::setUpstreamCoreVersion(), even though
// `sites/default` is write-protected.
// @see ::createTestProject()
// @see ::setUpstreamCoreVersion()
$this->assertCoreVersion($expected_version);
$placeholder = file_get_contents($this->getWebRoot() . '/core/README.txt');
$web_root = $this->getWebRoot();
$placeholder = file_get_contents("$web_root/core/README.txt");
$this->assertSame("Placeholder for Drupal core $expected_version.", $placeholder);
foreach (['default.settings.php', 'default.services.yml'] as $file) {
$file = $web_root . '/sites/default/' . $file;
$this->assertFileIsReadable($file);
$this->assertStringContainsString("# This is part of Drupal $expected_version.", file_get_contents($file));
}
$this->assertDirectoryIsNotWritable("$web_root/sites/default");
$info = $this->runComposer('composer info --self --format json', 'project', TRUE);
// The production dependencies should have been updated.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment