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

Issue #3307369 by kunal.sachdev, tedbow, phenaproxima: Validate all changed or...

Issue #3307369 by kunal.sachdev, tedbow, phenaproxima: Validate all changed or updated Drupal projects with Update XML
parent c2790b06
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,16 @@ use Drupal\package_manager\ValidationResult; ...@@ -12,6 +12,16 @@ use Drupal\package_manager\ValidationResult;
*/ */
class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBase { class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
// In this test, we don't care whether the updated projects are secure and
// supported.
$this->disableValidators[] = 'package_manager.validator.supported_releases';
parent::setUp();
}
/** /**
* Tests that new installed packages overwrite existing directories. * Tests that new installed packages overwrite existing directories.
* *
......
<?php
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\ValidationResult;
/**
* @coversDefaultClass \Drupal\package_manager\Validator\SupportedReleaseValidator
*
* @group package_manager
*/
class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
/**
* Data provider for testException().
*
* @return mixed[][]
* The test cases.
*/
public function providerException(): array {
$fixtures_folder = __DIR__ . '/../../fixtures/supported_release_validator';
$release_fixture_folder = __DIR__ . '/../../fixtures/release-history';
$summary = t('Cannot update because the following project version is not in the list of installable releases.');
return [
'semver, supported update' => [
'semver_test',
"$release_fixture_folder/semver_test.1.1.xml",
"$fixtures_folder/semver_supported_update_stage",
[],
],
'semver, update to unsupported branch' => [
'semver_test',
"$release_fixture_folder/semver_test.1.1.xml",
"$fixtures_folder/semver_unsupported_update_stage",
[
ValidationResult::createError(['semver_test (drupal/semver_test) 8.2.0'], $summary),
],
],
'legacy, supported update' => [
'aaa_update_test',
"$release_fixture_folder/aaa_update_test.1.1.xml",
"$fixtures_folder/legacy_supported_update_stage",
[],
],
'legacy, update to unsupported branch' => [
'aaa_update_test',
"$release_fixture_folder/aaa_update_test.1.1.xml",
"$fixtures_folder/legacy_unsupported_update_stage",
[
ValidationResult::createError(['aaa_update_test (drupal/aaa_update_test) 3.0.0'], $summary),
],
],
'aaa_automatic_updates_test(not in active), update to unsupported branch' => [
'aaa_automatic_updates_test',
"$release_fixture_folder/aaa_automatic_updates_test.9.8.2.xml",
"$fixtures_folder/aaa_automatic_updates_test_unsupported_update_stage",
[
ValidationResult::createError(['aaa_automatic_updates_test (drupal/aaa_automatic_updates_test) 7.0.1-dev'], $summary),
],
],
'aaa_automatic_updates_test(not in active), update to supported branch' => [
'aaa_automatic_updates_test',
"$release_fixture_folder/aaa_automatic_updates_test.9.8.2.xml",
"$fixtures_folder/aaa_automatic_updates_test_supported_update_stage",
[],
],
];
}
/**
* Tests exceptions when updating to unsupported or insecure releases.
*
* @param string $project
* The project to update.
* @param string $release_xml
* Path of release xml for project.
* @param string $stage_dir
* Path of fixture stage directory. It will be used as the virtual project's
* stage directory.
* @param array $expected_results
* The expected validation results.
*
* @dataProvider providerException
*/
public function testException(string $project, string $release_xml, string $stage_dir, array $expected_results): void {
$this->setReleaseMetadata([
$project => $release_xml,
'drupal' => __DIR__ . '/../../fixtures/release-history/drupal.9.8.2.xml',
]);
$active_dir = __DIR__ . '/../../fixtures/supported_release_validator/active';
$this->copyFixtureFolderToActiveDirectory($active_dir);
$this->copyFixtureFolderToStageDirectoryOnApply($stage_dir);
$this->assertResults($expected_results, PreApplyEvent::class);
}
}
...@@ -4,75 +4,24 @@ namespace Drupal\Tests\automatic_updates\Build; ...@@ -4,75 +4,24 @@ namespace Drupal\Tests\automatic_updates\Build;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Tests\package_manager\Build\TemplateProjectTestBase; use Drupal\Tests\package_manager\Build\TemplateProjectTestBase;
use Drupal\Tests\package_manager\Traits\FixtureUtilityTrait;
use Drupal\Tests\RandomGeneratorTrait;
/** /**
* Base class for tests that perform in-place updates. * Base class for tests that perform in-place updates.
*/ */
abstract class UpdateTestBase extends TemplateProjectTestBase { abstract class UpdateTestBase extends TemplateProjectTestBase {
use FixtureUtilityTrait;
use RandomGeneratorTrait;
/**
* A secondary server instance, to serve XML metadata about available updates.
*
* @var \Symfony\Component\Process\Process
*/
private $metadataServer;
/**
* {@inheritdoc}
*/
protected function tearDown(): void {
if ($this->metadataServer) {
$this->metadataServer->stop();
}
parent::tearDown();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function createTestProject(string $template): void { protected function createTestProject(string $template): void {
parent::createTestProject($template); parent::createTestProject($template);
// Install Drupal, Automatic Updates, and other modules needed for testing. // Install Automatic Updates, and other modules needed for testing.
$this->installQuickStart('minimal');
$this->formLogin($this->adminUsername, $this->adminPassword);
$this->installModules([ $this->installModules([
'automatic_updates', 'automatic_updates',
'automatic_updates_test', 'automatic_updates_test',
'automatic_updates_test_cron', 'automatic_updates_test_cron',
'automatic_updates_test_release_history',
]); ]);
// When checking for updates, we need to be able to make sub-requests, but
// the built-in PHP server is single-threaded. Therefore, open a second
// server instance on another port, which will serve the metadata about
// available updates.
$port = $this->findAvailablePort();
$this->metadataServer = $this->instantiateServer($port);
$code = <<<END
\$config['automatic_updates.settings']['cron_port'] = $port;
\$config['update.settings']['fetch']['url'] = 'http://localhost:$port/test-release-history';
END;
$this->writeSettings($code);
}
/**
* Prepares the test site to serve an XML feed of available release metadata.
*
* @param array $xml_map
* The update XML map, as used by update_test.settings.
*
* @see \Drupal\automatic_updates_test\TestController::metadata()
*/
protected function setReleaseMetadata(array $xml_map): void {
$xml_map = var_export($xml_map, TRUE);
$this->writeSettings("\$config['update_test.settings']['xml_map'] = $xml_map;");
} }
/** /**
...@@ -106,19 +55,4 @@ END; ...@@ -106,19 +55,4 @@ END;
} }
} }
/**
* Copies a fixture directory to a temporary directory and returns its path.
*
* @param string $fixture_directory
* The fixture directory.
*
* @return string
* The temporary directory.
*/
protected function copyFixtureToTempDirectory(string $fixture_directory): string {
$temp_directory = $this->getWorkspaceDirectory() . '/fixtures_temp_' . $this->randomMachineName(20);
static::copyFixtureFilesTo($fixture_directory, $temp_directory);
return $temp_directory;
}
} }
...@@ -55,7 +55,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { ...@@ -55,7 +55,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
*/ */
protected function installModulesFromClassProperty(ContainerInterface $container): void { protected function installModulesFromClassProperty(ContainerInterface $container): void {
$container->get('module_installer')->install([ $container->get('module_installer')->install([
'automatic_updates_test_release_history', 'package_manager_test_release_history',
]); ]);
$this->container = $container->get('kernel')->getContainer(); $this->container = $container->get('kernel')->getContainer();
......
...@@ -19,6 +19,16 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -19,6 +19,16 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
*/ */
protected static $modules = ['automatic_updates']; protected static $modules = ['automatic_updates'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
// In this test, we don't care whether the updated projects are secure and
// supported.
$this->disableValidators[] = 'package_manager.validator.supported_releases';
parent::setUp();
}
/** /**
* Asserts a set of validation results when staged changes are applied. * Asserts a set of validation results when staged changes are applied.
* *
......
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