diff --git a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide b/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide deleted file mode 100644 index 8215de0b462a258714e2ebb3b9624da096742794..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: aaa_automatic_updates_test diff --git a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/aaa_update_test/aaa_update_test.info.yml.hide b/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/aaa_update_test/aaa_update_test.info.yml.hide deleted file mode 100644 index b2d1f884d4a007ebd07dc00b3e46a8c5d098918d..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/aaa_update_test/aaa_update_test.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: aaa_update_test diff --git a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/automatic_updates_extensions_test_theme/automatic_updates_extensions_test_theme.info.yml.hide b/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/automatic_updates_extensions_test_theme/automatic_updates_extensions_test_theme.info.yml.hide deleted file mode 100644 index 0fe2d04a2c8fcbbee0154cb3d879fd6016e6c430..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/automatic_updates_extensions_test_theme/automatic_updates_extensions_test_theme.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: automatic_updates_extensions_test_theme diff --git a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/my_dev_module/my_dev_module.info.yml.hide b/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/my_dev_module/my_dev_module.info.yml.hide deleted file mode 100644 index 038e544660c96601ccc767d75d191d1ed132abc3..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/my_dev_module/my_dev_module.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: my_dev_module diff --git a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/my_module/my_module.info.yml.hide b/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/my_module/my_module.info.yml.hide deleted file mode 100644 index eb1bc0fda720c2989242046e42db1097f2f8f631..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/my_module/my_module.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: my_module diff --git a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/semver_test/semver_test.info.yml.hide b/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/semver_test/semver_test.info.yml.hide deleted file mode 100644 index 6175b81a041a98520a59f20ff0e1bce7b659cacd..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/two_projects/web/projects/semver_test/semver_test.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: semver_test diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php index ebacbd0bfb5795e4f89f8ebe7450ee0f0af1b17c..459ebb5f85da81f14e88364ca9fa1c0b1648129f 100644 --- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php +++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php @@ -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', diff --git a/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_1/module_1.info.yml.hide b/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_1/module_1.info.yml.hide deleted file mode 100644 index ab706bde15dafebe6bab1098e9427c4f497f2818..0000000000000000000000000000000000000000 --- a/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_1/module_1.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: module_1 diff --git a/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_2/module_2.info.yml.hide b/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_2/module_2.info.yml.hide deleted file mode 100644 index e6bd53b3dc1c670f4cc2267c280384763abe91b8..0000000000000000000000000000000000000000 --- a/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_2/module_2.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: module_2 diff --git a/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_5/module_5.info.yml.hide b/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_5/module_5.info.yml.hide deleted file mode 100644 index e92200afd97fe1a21e400620553dae9c55b0977e..0000000000000000000000000000000000000000 --- a/package_manager/tests/fixtures/overwrite_existing_validation/active/modules/module_5/module_5.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: module_5 diff --git a/package_manager/tests/fixtures/supported_release_validator/aaa_automatic_updates_test_supported_update_stage/modules/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide b/package_manager/tests/fixtures/supported_release_validator/aaa_automatic_updates_test_supported_update_stage/modules/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide deleted file mode 100644 index 8215de0b462a258714e2ebb3b9624da096742794..0000000000000000000000000000000000000000 --- a/package_manager/tests/fixtures/supported_release_validator/aaa_automatic_updates_test_supported_update_stage/modules/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: aaa_automatic_updates_test diff --git a/package_manager/tests/fixtures/supported_release_validator/aaa_automatic_updates_test_unsupported_update_stage/modules/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide b/package_manager/tests/fixtures/supported_release_validator/aaa_automatic_updates_test_unsupported_update_stage/modules/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide deleted file mode 100644 index 8215de0b462a258714e2ebb3b9624da096742794..0000000000000000000000000000000000000000 --- a/package_manager/tests/fixtures/supported_release_validator/aaa_automatic_updates_test_unsupported_update_stage/modules/aaa_automatic_updates_test/aaa_automatic_updates_test.info.yml.hide +++ /dev/null @@ -1 +0,0 @@ -project: aaa_automatic_updates_test diff --git a/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php b/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php index 142307555659c4fecde61db11735ed10119f6af2..0a985ee7dc22f0faa3ddb21901c9a79b5808437e 100644 --- a/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php +++ b/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php @@ -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); diff --git a/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php b/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php index 539d753b289843cccbe49c826582b83ef3c3d526..cd08c843544a3396e268b8181093719923dea3eb 100644 --- a/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php +++ b/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php @@ -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. diff --git a/package_manager/tests/src/Traits/FixtureUtilityTrait.php b/package_manager/tests/src/Traits/FixtureUtilityTrait.php index 01eb6a689be1e8f94e30b7b985069740eb596e2b..a780c6c339e74d0b14c8cce5e062967e4867e43f 100644 --- a/package_manager/tests/src/Traits/FixtureUtilityTrait.php +++ b/package_manager/tests/src/Traits/FixtureUtilityTrait.php @@ -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])); } /** diff --git a/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php b/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php index 8c648a0e80832ed423404cd0b044088ea641e40a..2ce4b8ee8e0c8f111d53354ebb536b6952eba0d5 100644 --- a/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php @@ -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 );