Skip to content
Snippets Groups Projects
Commit c1ee3b55 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3307086 by tedbow: In functional tests copy fixtures directories into...

Issue #3307086 by tedbow: In functional tests copy fixtures directories into temporary directory that is writeable
parent 991088ee
No related branches found
No related tags found
1 merge request!451Issue #3307086: In functional tests copy copy fixtures directories into temporary directory that is writeable
...@@ -7,7 +7,6 @@ use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; ...@@ -7,7 +7,6 @@ use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test\StagedDatabaseUpdateValidator; use Drupal\automatic_updates_test\StagedDatabaseUpdateValidator;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\ValidationResult; use Drupal\package_manager\ValidationResult;
use Drupal\package_manager_bypass\Beginner;
use Drupal\package_manager_bypass\Stager; use Drupal\package_manager_bypass\Stager;
use Drupal\Tests\automatic_updates\Functional\AutomaticUpdatesFunctionalTestBase; use Drupal\Tests\automatic_updates\Functional\AutomaticUpdatesFunctionalTestBase;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait; use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
...@@ -78,10 +77,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -78,10 +77,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
]); ]);
// We need this fixture as only projects installed via composer will show up // We need this fixture as only projects installed via composer will show up
// on the form. // on the form.
$fixture_dir = __DIR__ . '/../../fixtures/two_projects'; $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/two_projects');
Beginner::setFixturePath($fixture_dir);
$this->container->get('package_manager.path_locator')
->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL);
$this->drupalLogin($user); $this->drupalLogin($user);
$this->drupalPlaceBlock('local_tasks_block', ['primary' => TRUE]); $this->drupalPlaceBlock('local_tasks_block', ['primary' => TRUE]);
} }
...@@ -306,10 +302,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -306,10 +302,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
); );
// One module not installed through composer. // One module not installed through composer.
$fixture_dir = __DIR__ . '/../../fixtures/one_project'; $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/one_project');
Beginner::setFixturePath($fixture_dir);
$this->container->get('package_manager.path_locator')
->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL);
$assert = $this->assertSession(); $assert = $this->assertSession();
$user = $this->createUser( $user = $this->createUser(
[ [
...@@ -325,10 +318,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -325,10 +318,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertUpdatesCount(1); $this->assertUpdatesCount(1);
// Both of the modules not installed through composer. // Both of the modules not installed through composer.
$fixture_dir = __DIR__ . '/../../fixtures/no_project'; $this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/no_project');
Beginner::setFixturePath($fixture_dir);
$this->container->get('package_manager.path_locator')
->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL);
$this->getSession()->reload(); $this->getSession()->reload();
$assert->pageTextContains('Updates were found, but they must be performed manually. See the list of available updates for more information.'); $assert->pageTextContains('Updates were found, but they must be performed manually. See the list of available updates for more information.');
$this->assertNoUpdates(); $this->assertNoUpdates();
......
...@@ -6,6 +6,7 @@ use Drupal\Core\Site\Settings; ...@@ -6,6 +6,7 @@ use Drupal\Core\Site\Settings;
use Drupal\package_manager_bypass\Beginner; use Drupal\package_manager_bypass\Beginner;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
/** /**
* Base class for functional tests of the Automatic Updates module. * Base class for functional tests of the Automatic Updates module.
...@@ -44,17 +45,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { ...@@ -44,17 +45,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->disableValidators($this->disableValidators); $this->disableValidators($this->disableValidators);
$this->useFixtureDirectoryAsActive(__DIR__ . '/../../fixtures/fake-site');
$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);
} }
/** /**
...@@ -170,4 +161,36 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { ...@@ -170,4 +161,36 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
$assert_session->pageTextContainsOnce('Drupal core will be updated to ' . $target_version); $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);
}
} }
...@@ -8,7 +8,6 @@ use Drupal\automatic_updates_test\Datetime\TestTime; ...@@ -8,7 +8,6 @@ use Drupal\automatic_updates_test\Datetime\TestTime;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2; use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\package_manager_bypass\Beginner;
use Drupal\system\SystemManager; use Drupal\system\SystemManager;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait; use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
use Drupal\Tests\Traits\Core\CronRunTrait; use Drupal\Tests\Traits\Core\CronRunTrait;
...@@ -424,7 +423,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -424,7 +423,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
// readiness check (without storing the results), and the checker is no // readiness check (without storing the results), and the checker is no
// longer raising an error. // longer raising an error.
$this->drupalGet('/admin/modules/automatic-update'); $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'); $assert_session->buttonExists('Update');
// Ensure that the previous results are still displayed on another admin // Ensure that the previous results are still displayed on another admin
// page, to confirm that the updater form is not discarding the previous // page, to confirm that the updater form is not discarding the previous
......
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