diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php index f2ded91ed7b32683e103ef46f8044de91261086d..a7df5b7e14fb19a0a3f4c3ebf12ba6aa83be9261 100644 --- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php +++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php @@ -7,7 +7,6 @@ use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\automatic_updates_test\StagedDatabaseUpdateValidator; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\ValidationResult; -use Drupal\package_manager_bypass\Beginner; use Drupal\package_manager_bypass\Stager; use Drupal\Tests\automatic_updates\Functional\AutomaticUpdatesFunctionalTestBase; use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait; @@ -78,10 +77,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ]); // We need this fixture as only projects installed via composer will show up // on the form. - $fixture_dir = __DIR__ . '/../../fixtures/two_projects'; - Beginner::setFixturePath($fixture_dir); - $this->container->get('package_manager.path_locator') - ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL); + $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/two_projects'); $this->drupalLogin($user); $this->drupalPlaceBlock('local_tasks_block', ['primary' => TRUE]); } @@ -306,10 +302,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ); // One module not installed through composer. - $fixture_dir = __DIR__ . '/../../fixtures/one_project'; - Beginner::setFixturePath($fixture_dir); - $this->container->get('package_manager.path_locator') - ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL); + $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/one_project'); $assert = $this->assertSession(); $user = $this->createUser( [ @@ -325,10 +318,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertUpdatesCount(1); // Both of the modules not installed through composer. - $fixture_dir = __DIR__ . '/../../fixtures/no_project'; - Beginner::setFixturePath($fixture_dir); - $this->container->get('package_manager.path_locator') - ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL); + $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/no_project'); $this->getSession()->reload(); $assert->pageTextContains('Updates were found, but they must be performed manually. See the list of available updates for more information.'); $this->assertNoUpdates(); diff --git a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php index 1d352dec7aef1b9e1460abc34db6fe6f461cf5b8..df4b249ab952552da937b4a512cebd9aea43d875 100644 --- a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php +++ b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php @@ -6,6 +6,7 @@ use Drupal\Core\Site\Settings; use Drupal\package_manager_bypass\Beginner; use Drupal\Tests\BrowserTestBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Filesystem\Filesystem; /** * Base class for functional tests of the Automatic Updates module. @@ -44,17 +45,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { protected function setUp(): void { parent::setUp(); $this->disableValidators($this->disableValidators); - - $fixture_dir = __DIR__ . '/../../fixtures/fake-site'; - // We cannot guarantee that the fixture directory will be writable in all - // testing situations, so to keep things consistent, fail the test if it - // isn't. Our build tests examine file system permissions more extensively. - // @see \Drupal\Tests\automatic_updates\Build\CoreUpdateTest::assertReadOnlyFileSystemError() - $this->assertDirectoryIsWritable($fixture_dir); - - Beginner::setFixturePath($fixture_dir); - $this->container->get('package_manager.path_locator') - ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL); + $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/fake-site'); } /** @@ -170,4 +161,36 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { $assert_session->pageTextContainsOnce('Drupal core will be updated to ' . $target_version); } + /** + * 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); + (new Filesystem())->mirror($fixture_directory, $temp_directory); + $this->assertDirectoryIsWritable($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); + Beginner::setFixturePath($active_dir); + $this->container->get('package_manager.path_locator') + ->setPaths($active_dir, $active_dir . '/vendor', '', NULL); + } + } diff --git a/tests/src/Functional/ReadinessValidationTest.php b/tests/src/Functional/ReadinessValidationTest.php index 463a72cee6099f9986676ce93fec74728590f234..e5a1d5c64430f462255032fca616107ea11e91b8 100644 --- a/tests/src/Functional/ReadinessValidationTest.php +++ b/tests/src/Functional/ReadinessValidationTest.php @@ -8,7 +8,6 @@ use Drupal\automatic_updates_test\Datetime\TestTime; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2; use Drupal\Core\Url; -use Drupal\package_manager_bypass\Beginner; use Drupal\system\SystemManager; use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait; use Drupal\Tests\Traits\Core\CronRunTrait; @@ -424,7 +423,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { // readiness check (without storing the results), and the checker is no // longer raising an error. $this->drupalGet('/admin/modules/automatic-update'); - Beginner::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1'); + $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/staged/9.8.1'); $assert_session->buttonExists('Update'); // Ensure that the previous results are still displayed on another admin // page, to confirm that the updater form is not discarding the previous