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

Issue #3321236 by tedbow, omkar.podey, Wim Leers: Add actual project folders...

Issue #3321236 by tedbow, omkar.podey, Wim Leers: Add actual project folders in \Drupal\Tests\package_manager\Traits\FixtureUtilityTrait::addPackage
parent f4a86801
No related branches found
No related tags found
1 merge request!599Issue #3321236: Add actual project folder changes from methods in FixtureUtilityTrait
Showing
with 92 additions and 56 deletions
......@@ -88,7 +88,6 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
'access administration pages',
]);
$this->activeDir = $this->container->get('package_manager.path_locator')->getProjectRoot();
$this->copyFixtureFilesTo(__DIR__ . '/../../fixtures/two_projects', $this->activeDir);
$this->addPackage($this->activeDir, [
'name' => 'drupal/semver_test',
'version' => '8.1.0',
......
......@@ -36,27 +36,39 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas
* by the 'package_manager_bypass' module.
*/
public function testNewPackagesOverwriteExisting(): void {
$fixtures_dir = __DIR__ . '/../../fixtures/overwrite_existing_validation';
$this->copyFixtureFolderToActiveDirectory("$fixtures_dir/active");
$active_dir = $this->container->get('package_manager.path_locator')->getProjectRoot();
$modules_dir = "$active_dir/modules";
$this->addProjectAtPath("$modules_dir/module_1");
$this->addProjectAtPath("$modules_dir/module_2");
$this->addProjectAtPath("$modules_dir/module_5");
$stage = $this->createStage();
$stage->create();
$stage_dir = $stage->getStageDirectory();
// module_1 and module_2 will raise errors because they would overwrite
// non-Composer managed paths in the active directory.
$this->addPackage($stage_dir, [
'name' => 'drupal/module_1',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_1',
]);
$this->addPackage($stage_dir, [
'name' => 'drupal/module_2',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_2',
]);
$this->addPackage(
$stage_dir,
[
'name' => 'drupal/module_1',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_1',
],
FALSE,
FALSE
);
$this->addPackage(
$stage_dir,
[
'name' => 'drupal/module_2',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_2',
],
FALSE,
FALSE
);
// module_3 will cause no problems, since it doesn't exist in the active
// directory at all.
......@@ -70,12 +82,17 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas
// module_4 doesn't exist in the active directory but the 'install_path' as
// known to Composer in the staged directory collides with module_1 in the
// active directory which will cause an error.
$this->addPackage($stage_dir, [
'name' => 'drupal/module_4',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_1',
]);
$this->addPackage(
$stage_dir,
[
'name' => 'drupal/module_4',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_1',
],
FALSE,
FALSE,
);
// module_5_different_path will not cause a problem, even though its package
// name is drupal/module_5, because its project name and path in the staging
......@@ -111,7 +128,7 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas
try {
$stage->apply();
// If no exception occurs, ensure we weren't expecting any errors.
$this->assertEmpty($expected_results);
$this->assertValidationResultsEqual($expected_results, []);
}
catch (StageValidationException $e) {
$this->assertNotEmpty($expected_results);
......
......@@ -23,8 +23,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
protected function setUp(): void {
parent::setUp();
$active_fixture_dir = __DIR__ . '/../../fixtures/supported_release_validator/active';
$this->copyFixtureFolderToActiveDirectory($active_fixture_dir);
$active_dir = $this->container->get('package_manager.path_locator')
->getProjectRoot();
$this->addPackage($active_dir, [
......@@ -73,7 +71,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'semver_test' => "$release_fixture_folder/semver_test.1.1.xml",
],
NULL,
TRUE,
[
'name' => "drupal/semver_test",
......@@ -87,7 +84,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'semver_test' => "$release_fixture_folder/semver_test.1.1.xml",
],
NULL,
TRUE,
[
'name' => "drupal/semver_test",
......@@ -103,7 +99,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'aaa_update_test' => "$release_fixture_folder/aaa_update_test.1.1.xml",
],
NULL,
TRUE,
[
'name' => "drupal/aaa_update_test",
......@@ -117,7 +112,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'aaa_update_test' => "$release_fixture_folder/aaa_update_test.1.1.xml",
],
NULL,
TRUE,
[
'name' => "drupal/aaa_update_test",
......@@ -133,7 +127,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'aaa_automatic_updates_test' => "$release_fixture_folder/aaa_automatic_updates_test.7.0.1.xml",
],
"$fixtures_folder/aaa_automatic_updates_test_unsupported_update_stage",
FALSE,
[
'name' => "drupal/aaa_automatic_updates_test",
......@@ -149,7 +142,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'aaa_automatic_updates_test' => "$release_fixture_folder/aaa_automatic_updates_test.7.0.1.xml",
],
"$fixtures_folder/aaa_automatic_updates_test_supported_update_stage",
FALSE,
[
'name' => "drupal/aaa_automatic_updates_test",
......@@ -163,7 +155,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'package_manager_theme' => "$release_fixture_folder/package_manager_theme.1.1.xml",
],
NULL,
TRUE,
[
'name' => "drupal/package_manager_theme",
......@@ -177,7 +168,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
[
'package_manager_theme' => "$release_fixture_folder/package_manager_theme.1.1.xml",
],
NULL,
TRUE,
[
'name' => "drupal/package_manager_theme",
......@@ -194,7 +184,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
// @see \Drupal\package_manager\Validator\SupportedReleaseValidator::checkStagedReleases()
'updating a module that does not start with drupal/' => [
[],
NULL,
TRUE,
[
'name' => "somewhere/a_drupal_module",
......@@ -212,9 +201,6 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
*
* @param array $release_metadata
* Array of paths of the fake release metadata keyed by project name.
* @param string|null $stage_fixture_dir
* Path of fixture stage directory or NULL. It will be used to fixture files
* to virtual stage directory when the project is not in active.
* @param bool $project_in_active
* Whether the project is in the active directory or not.
* @param array $package
......@@ -224,13 +210,11 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase {
*
* @dataProvider providerException
*/
public function testException(array $release_metadata, ?string $stage_fixture_dir, bool $project_in_active, array $package, array $expected_results): void {
public function testException(array $release_metadata, bool $project_in_active, array $package, array $expected_results): void {
$this->setReleaseMetadata(['drupal' => __DIR__ . '/../../fixtures/release-history/drupal.9.8.2.xml'] + $release_metadata);
$listener = function (PreApplyEvent $event) use ($project_in_active, $package, $stage_fixture_dir): void {
if ($stage_fixture_dir) {
$this->copyFixtureFilesTo($stage_fixture_dir, $event->getStage()->getStageDirectory());
}
$listener = function (PreApplyEvent $event) use ($project_in_active, $package, $expected_results): void {
$stage_dir = $event->getStage()->getStageDirectory();
// @todo add test coverage for packages that don't start with 'drupal/' in
// https://www.drupal.org/node/3321386.
......
......@@ -5,6 +5,7 @@ declare(strict_types = 1);
namespace Drupal\Tests\package_manager\Traits;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Serialization\Yaml;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
......@@ -99,12 +100,48 @@ trait FixtureUtilityTrait {
* installed.php. Must include the `name` and `type` keys.
* @param bool $is_dev_requirement
* Whether or not the package is a development requirement.
* @param bool $create_project
* Whether or not the project info.yml file should be created.
*/
protected function addPackage(string $dir, array $package, bool $is_dev_requirement = FALSE): void {
protected function addPackage(string $dir, array $package, bool $is_dev_requirement = FALSE, bool $create_project = TRUE): void {
foreach (['name', 'type'] as $required_key) {
$this->assertArrayHasKey($required_key, $package);
}
$this->setPackage($dir, $package['name'], $package, FALSE, $is_dev_requirement);
$drupal_project_types = [
'drupal-module',
'drupal-theme',
'drupal-custom-module',
'drupal-custom-theme',
];
if (!$create_project || !in_array($package['type'], $drupal_project_types, TRUE)) {
return;
}
$this->assertNotEmpty($package['install_path']);
$install_path = "$dir/vendor/composer/" . $package['install_path'];
$this->addProjectAtPath($install_path);
}
/**
* Adds a project at a path.
*
* @param string $path
* The path.
* @param string|null $project_name
* (optional) The project name. If known is specified the last part of the
* path will be used.
*
* @todo Move to FixtureManipulator in https://www.drupal.org/i/3322913.
*/
protected function addProjectAtPath(string $path, ?string $project_name = NULL): void {
$fs = new Filesystem();
$this->assertDirectoryDoesNotExist($path);
$fs->mkdir($path);
if ($project_name === NULL) {
$path_parts = explode('/', $path);
$project_name = array_pop($path_parts);
}
file_put_contents("$path/$project_name.info.yml", Yaml::encode(['project' => $project_name]));
}
/**
......
......@@ -79,7 +79,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
$this->addPackage($active_dir, [
'name' => 'drupal/test_module',
'version' => '1.3.0',
'type' => 'drupal_module',
'type' => 'drupal-module',
'install_path' => '../../modules/test_module',
]);
$this->addPackage($active_dir, [
'name' => 'other/removed',
......@@ -91,7 +92,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
[
'name' => 'drupal/dev-test_module',
'version' => '1.3.0',
'type' => 'drupal_module',
'type' => 'drupal-module',
'install_path' => '../../modules/dev_test_module',
],
TRUE
);
......@@ -171,11 +173,13 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/test_theme',
'version' => '1.3.0',
'type' => 'drupal-theme',
'install_path' => '../../themes/test_theme',
]);
$this->addPackage($active_dir, [
'name' => 'drupal/test_module2',
'version' => '1.3.1',
'type' => 'drupal-module',
'install_path' => '../../modules/test_module2',
]);
$this->addPackage($active_dir, [
'name' => 'other/removed',
......@@ -188,6 +192,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/dev-test_theme',
'version' => '1.3.0',
'type' => 'drupal-custom-theme',
'install_path' => '../../modules/dev_test_theme',
],
TRUE
);
......@@ -197,6 +202,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/dev-test_module2',
'version' => '1.3.1',
'type' => 'drupal-module',
'install_path' => '../../modules/dev_test_module2',
],
TRUE
);
......@@ -246,6 +252,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/test_module',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/test_module',
]);
$this->addPackage($active_dir, [
'name' => 'other/changed',
......@@ -258,6 +265,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/dev-test_module',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/dev_test_module',
],
TRUE
);
......@@ -315,6 +323,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/test_module',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/test_module',
]);
$this->addPackage($active_dir, [
'name' => 'other/removed',
......@@ -331,6 +340,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
'name' => 'drupal/dev-test_module',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/dev_test_module',
],
TRUE
);
......
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