Skip to content
Snippets Groups Projects

Fake site should always be used for functional tests

3 files
+ 95
79
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -8,13 +8,12 @@ use Drupal\automatic_updates\CronUpdateRunner;
use Drupal\automatic_updates\CommandExecutor;
use Drupal\automatic_updates\UpdateStage;
use Drupal\fixture_manipulator\StageFixtureManipulator;
use Drupal\package_manager\PathLocator;
use Drupal\Tests\automatic_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.
@@ -27,6 +26,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
use ComposerStagerTestTrait;
use FixtureManipulatorTrait;
use FixtureUtilityTrait;
use TestSetUpTrait;
/**
* {@inheritdoc}
@@ -48,29 +48,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
$this->mockActiveCoreVersion('9.8.0');
}
/**
* {@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);
}
/**
* {@inheritdoc}
*/
@@ -104,30 +81,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
->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.
*
@@ -153,36 +106,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
$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.
*/
Loading