From 67dfe9e4c1120bf100220f94d9d64b8f8e2e0b27 Mon Sep 17 00:00:00 2001 From: Ted Bowman <ted+git@tedbow.com> Date: Wed, 25 Oct 2023 09:02:50 -0400 Subject: [PATCH] Contrib: allow uncommetting lines in core MR - https://git.drupalcode.org/project/automatic_updates/-/commit/11f37000e2849556919aed65642d0af90427648d --- core/misc/cspell/dictionary.txt | 2 +- .../AutoUpdatesFunctionalTestBase.php | 77 +-------------- .../tests/src/Functional/StatusCheckTest.php | 6 +- .../src/Functional/UpdaterFormTestBase.php | 11 +-- .../UpdateSettingsFormTest.php | 3 + .../tests/src/Traits/TestSetUpTrait.php | 93 +++++++++++++++++++ .../package_manager/src/ComposerInspector.php | 15 +-- 7 files changed, 106 insertions(+), 101 deletions(-) create mode 100644 core/modules/auto_updates/tests/src/Traits/TestSetUpTrait.php diff --git a/core/misc/cspell/dictionary.txt b/core/misc/cspell/dictionary.txt index 2d99df874e4a..b956fc82cf0c 100644 --- a/core/misc/cspell/dictionary.txt +++ b/core/misc/cspell/dictionary.txt @@ -1255,4 +1255,4 @@ zzgroup Ã¥wesome èxample über -È…chÈ +È…chÈ \ No newline at end of file diff --git a/core/modules/auto_updates/tests/src/Functional/AutoUpdatesFunctionalTestBase.php b/core/modules/auto_updates/tests/src/Functional/AutoUpdatesFunctionalTestBase.php index baf84e1670a1..5ee3e794d500 100644 --- a/core/modules/auto_updates/tests/src/Functional/AutoUpdatesFunctionalTestBase.php +++ b/core/modules/auto_updates/tests/src/Functional/AutoUpdatesFunctionalTestBase.php @@ -8,13 +8,11 @@ use Drupal\auto_updates\CommandExecutor; use Drupal\auto_updates\UpdateStage; use Drupal\fixture_manipulator\StageFixtureManipulator; -use Drupal\package_manager\PathLocator; +use Drupal\Tests\auto_updates\Traits\TestSetUpTrait; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\package_manager\Traits\AssertPreconditionsTrait; use Drupal\Tests\package_manager\Traits\ComposerStagerTestTrait; use Drupal\Tests\package_manager\Traits\FixtureManipulatorTrait; -use Drupal\Tests\package_manager\Traits\FixtureUtilityTrait; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for functional tests of the Automatic Updates module. @@ -26,7 +24,7 @@ abstract class AutoUpdatesFunctionalTestBase extends BrowserTestBase { use AssertPreconditionsTrait; use ComposerStagerTestTrait; use FixtureManipulatorTrait; - use FixtureUtilityTrait; + use TestSetUpTrait; /** * {@inheritdoc} @@ -41,7 +39,6 @@ abstract class AutoUpdatesFunctionalTestBase extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); - $this->useFixtureDirectoryAsActive(__DIR__ . '/../../../../package_manager/tests/fixtures/fake_site'); // @todo Remove in https://www.drupal.org/project/auto_updates/issues/3284443 $this->config('auto_updates.settings') ->set('unattended.level', CronUpdateRunner::SECURITY) @@ -49,22 +46,6 @@ protected function setUp(): void { $this->mockActiveCoreVersion('9.8.0'); } - /** - * {@inheritdoc} - */ - protected function installModulesFromClassProperty(ContainerInterface $container): void { - $container->get('module_installer')->install([ - 'package_manager_test_release_history', - ]); - $this->container = $container->get('kernel')->getContainer(); - - // To prevent tests from making real requests to the Internet, use fake - // release metadata that exposes a pretend Drupal 9.8.2 release. - $this->setReleaseMetadata(__DIR__ . '/../../../../package_manager/tests/fixtures/release-history/drupal.9.8.2.xml'); - - parent::installModulesFromClassProperty($container); - } - /** * {@inheritdoc} */ @@ -98,30 +79,6 @@ protected function mockActiveCoreVersion(string $version): void { ->save(); } - /** - * Sets the release metadata file to use when fetching available updates. - * - * @todo Remove this function with use of the trait from the Update module in - * https://drupal.org/i/3348234. - * - * @param string $file - * The path of the XML metadata file to use. - */ - protected function setReleaseMetadata(string $file): void { - $this->assertFileIsReadable($file); - - $this->config('update.settings') - ->set('fetch.url', $this->baseUrl . '/test-release-history') - ->save(); - - [$project] = explode('.', basename($file, '.xml'), 2); - $xml_map = $this->config('update_test.settings')->get('xml_map') ?? []; - $xml_map[$project] = $file; - $this->config('update_test.settings') - ->set('xml_map', $xml_map) - ->save(); - } - /** * Checks for available updates. * @@ -147,36 +104,6 @@ protected function assertUpdateReady(string $target_version): void { $this->assertTrue($button->hasClass('button--primary')); } - /** - * Copies a fixture directory to a temporary directory. - * - * @param string $fixture_directory - * The fixture directory. - * - * @return string - * The temporary directory. - */ - protected function copyFixtureToTempDirectory(string $fixture_directory): string { - $temp_directory = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . DIRECTORY_SEPARATOR . $this->randomMachineName(20); - static::copyFixtureFilesTo($fixture_directory, $temp_directory); - return $temp_directory; - } - - /** - * Sets a fixture directory to use as the active directory. - * - * @param string $fixture_directory - * The fixture directory. - */ - protected function useFixtureDirectoryAsActive(string $fixture_directory): void { - // Create a temporary directory from our fixture directory that will be - // unique for each test run. This will enable changing files in the - // directory and not affect other tests. - $active_dir = $this->copyFixtureToTempDirectory($fixture_directory); - $this->container->get(PathLocator::class) - ->setPaths($active_dir, $active_dir . '/vendor', '', NULL); - } - /** * Runs the console update command, which will trigger status checks. */ diff --git a/core/modules/auto_updates/tests/src/Functional/StatusCheckTest.php b/core/modules/auto_updates/tests/src/Functional/StatusCheckTest.php index 2037bf9c105c..4769134173f6 100644 --- a/core/modules/auto_updates/tests/src/Functional/StatusCheckTest.php +++ b/core/modules/auto_updates/tests/src/Functional/StatusCheckTest.php @@ -103,10 +103,8 @@ public function testModuleFormInstallDisplay(int $results_severity): void { $page = $this->getSession()->getPage(); $page->checkField('modules[auto_updates][enable]'); $page->pressButton('Install'); - if ($page->hasButton('Continue')) { - $page->pressButton('Continue'); - } - + // Confirm installing the experimental module. + $page->pressButton('Continue'); // Cron Updates will always be disabled on installation as per // auto_updates.settings.yml . $session = $this->assertSession(); diff --git a/core/modules/auto_updates/tests/src/Functional/UpdaterFormTestBase.php b/core/modules/auto_updates/tests/src/Functional/UpdaterFormTestBase.php index f4054d9c0bd9..edbbb9413e55 100644 --- a/core/modules/auto_updates/tests/src/Functional/UpdaterFormTestBase.php +++ b/core/modules/auto_updates/tests/src/Functional/UpdaterFormTestBase.php @@ -45,21 +45,16 @@ protected function setUp(): void { parent::setUp(); $this->setReleaseMetadata(__DIR__ . '/../../../../package_manager/tests/fixtures/release-history/drupal.9.8.1-security.xml'); - $permissions = [ + $user = $this->createUser([ 'administer site configuration', 'administer software updates', 'access administration pages', 'access site in maintenance mode', 'administer modules', 'access site reports', + 'view update notifications', 'access help pages', - ]; - // Check for permission that was added in Drupal core 9.4.x. - $available_permissions = array_keys($this->container->get('user.permissions')->getPermissions()); - if (in_array('view update notifications', $available_permissions, TRUE)) { - array_push($permissions, 'view update notifications'); - } - $user = $this->createUser($permissions); + ]); $this->drupalLogin($user); $this->checkForUpdates(); } diff --git a/core/modules/auto_updates/tests/src/FunctionalJavascript/UpdateSettingsFormTest.php b/core/modules/auto_updates/tests/src/FunctionalJavascript/UpdateSettingsFormTest.php index e7cf7a3abcad..3f0896400a6f 100644 --- a/core/modules/auto_updates/tests/src/FunctionalJavascript/UpdateSettingsFormTest.php +++ b/core/modules/auto_updates/tests/src/FunctionalJavascript/UpdateSettingsFormTest.php @@ -4,12 +4,15 @@ use Drupal\auto_updates\CronUpdateRunner; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\Tests\auto_updates\Traits\TestSetUpTrait; /** * @group auto_updates */ class UpdateSettingsFormTest extends WebDriverTestBase { + use TestSetUpTrait; + /** * {@inheritdoc} */ diff --git a/core/modules/auto_updates/tests/src/Traits/TestSetUpTrait.php b/core/modules/auto_updates/tests/src/Traits/TestSetUpTrait.php new file mode 100644 index 000000000000..bac575e1b854 --- /dev/null +++ b/core/modules/auto_updates/tests/src/Traits/TestSetUpTrait.php @@ -0,0 +1,93 @@ +<?php + +namespace Drupal\Tests\auto_updates\Traits; + +use Drupal\package_manager\PathLocator; +use Drupal\Tests\package_manager\Traits\FixtureUtilityTrait; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Common functions to set up tests correctly. + */ +trait TestSetUpTrait { + + use FixtureUtilityTrait; + + /** + * {@inheritdoc} + */ + protected function installModulesFromClassProperty(ContainerInterface $container): void { + $container->get('module_installer')->install([ + 'package_manager_test_release_history', + 'package_manager_bypass', + ]); + $this->container = $container->get('kernel')->getContainer(); + + // To prevent tests from using the real codebase for Composer we must set + // the fixture path as early as possible. Automatic Updates will run + // readiness checks when the module is installed so this must be done before + // the parent class installs the modules needed for the test. + $this->useFixtureDirectoryAsActive(__DIR__ . '/../../../../package_manager/tests/fixtures/fake_site'); + + // To prevent tests from making real requests to the Internet, use fake + // release metadata that exposes a pretend Drupal 9.8.2 release. + $this->setReleaseMetadata(__DIR__ . '/../../../../package_manager/tests/fixtures/release-history/drupal.9.8.2.xml'); + + parent::installModulesFromClassProperty($container); + } + + /** + * Copies a fixture directory to a temporary directory. + * + * @param string $fixture_directory + * The fixture directory. + * + * @return string + * The temporary directory. + */ + protected function copyFixtureToTempDirectory(string $fixture_directory): string { + $temp_directory = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . DIRECTORY_SEPARATOR . $this->randomMachineName(20); + static::copyFixtureFilesTo($fixture_directory, $temp_directory); + return $temp_directory; + } + + /** + * Sets a fixture directory to use as the active directory. + * + * @param string $fixture_directory + * The fixture directory. + */ + protected function useFixtureDirectoryAsActive(string $fixture_directory): void { + // Create a temporary directory from our fixture directory that will be + // unique for each test run. This will enable changing files in the + // directory and not affect other tests. + $active_dir = $this->copyFixtureToTempDirectory($fixture_directory); + $this->container->get(PathLocator::class) + ->setPaths($active_dir, $active_dir . '/vendor', '', NULL); + } + + /** + * Sets the release metadata file to use when fetching available updates. + * + * @todo Remove this function with use of the trait from the Update module in + * https://drupal.org/i/3348234. + * + * @param string $file + * The path of the XML metadata file to use. + */ + protected function setReleaseMetadata(string $file): void { + $this->assertFileIsReadable($file); + + $this->config('update.settings') + ->set('fetch.url', $this->baseUrl . '/test-release-history') + ->save(); + + [$project] = explode('.', basename($file, '.xml'), 2); + $xml_map = $this->config('update_test.settings')->get('xml_map') ?? []; + $xml_map[$project] = $file; + $this->config('update_test.settings') + ->set('xml_map', $xml_map) + ->save(); + } + +} diff --git a/core/modules/package_manager/src/ComposerInspector.php b/core/modules/package_manager/src/ComposerInspector.php index 70347ccc9d91..2d8eac506fb0 100644 --- a/core/modules/package_manager/src/ComposerInspector.php +++ b/core/modules/package_manager/src/ComposerInspector.php @@ -328,22 +328,11 @@ public function getInstalledPackagesList(string $working_dir): InstalledPackages // same as the working directory, in which case InstalledPackage::$path // should be NULL. For all other package types, we consider it invalid // if the install path is the same as the working directory. - // @todo Remove this handling of metapackage paths when Composer 2.5.7 or - // later is required, in https://drupal.org/i/3365133. if (isset($package['type']) && $package['type'] === 'metapackage') { - // TRICKY: until Composer 2.5.6, metapackages returned the current - // working directory instead of NULL. - // @see https://github.com/composer/composer/commit/3a48e393756e8b0387925aa327f45a30128b4556 - $packages_data[$name]['path'] = NULL; - // @todo Remove the if-branch when the minimum Composer version is raised to >=2.5.6. - if (Semver::satisfies($this->getVersion(), '<2.5.6')) { - if ($path !== $working_dir) { - throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected '$working_dir'"); - } - } - elseif ($path !== NULL) { + if ($path !== NULL) { throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected NULL"); } + $packages_data[$name]['path'] = $path; } elseif ($path === $working_dir) { throw new \UnexpectedValueException("Package '$name' cannot be installed at path: '$path'"); -- GitLab