diff --git a/automatic_updates_extensions/automatic_updates_extensions.services.yml b/automatic_updates_extensions/automatic_updates_extensions.services.yml index 4e38d2f24418ff61aed6a3654bf754ad609993a5..95de366d616573959cd5786c6774ea29466fdbaf 100644 --- a/automatic_updates_extensions/automatic_updates_extensions.services.yml +++ b/automatic_updates_extensions/automatic_updates_extensions.services.yml @@ -13,12 +13,6 @@ services: - '@datetime.time' - '@PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface' - '@package_manager.failure_marker' - automatic_updates_extensions.validator.packages_installed_with_composer: - class: Drupal\automatic_updates_extensions\Validator\PackagesInstalledWithComposerValidator - arguments: - - '@string_translation' - tags: - - { name: event_subscriber } automatic_updates_extensions.validator.target_release: class: Drupal\automatic_updates_extensions\Validator\UpdateReleaseValidator tags: diff --git a/automatic_updates_extensions/src/Validator/PackagesInstalledWithComposerValidator.php b/automatic_updates_extensions/src/Validator/PackagesInstalledWithComposerValidator.php deleted file mode 100644 index 487b46a64ff8c997a70e43e3b0685887650a216f..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/src/Validator/PackagesInstalledWithComposerValidator.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -namespace Drupal\automatic_updates_extensions\Validator; - -use Composer\Package\PackageInterface; -use Drupal\automatic_updates_extensions\ExtensionUpdater; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\package_manager\Event\PreApplyEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * Validates packages are installed via Composer. - * - * @todo Remove this validator completely in https://www.drupal.org/i/3303900. - */ -class PackagesInstalledWithComposerValidator implements EventSubscriberInterface { - - use StringTranslationTrait; - - /** - * Constructs a InstalledPackagesValidator object. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - */ - public function __construct(TranslationInterface $translation) { - $this->setStringTranslation($translation); - } - - /** - * Validates that packages are installed with composer or not. - * - * @param \Drupal\package_manager\Event\PreApplyEvent $event - * The event object. - */ - public function checkPackagesInstalledWithComposer(PreApplyEvent $event): void { - $stage = $event->getStage(); - - if (!$stage instanceof ExtensionUpdater) { - return; - } - - $missing_packages = $this->getPackagesNotInstalledWithComposer($event); - if ($missing_packages) { - // Removing drupal/ from package names for better user presentation. - $missing_projects = str_replace('drupal/', '', array_keys($missing_packages)); - $event->addError($missing_projects, $this->t('Automatic Updates can only update projects that were installed via Composer. The following packages are not installed through composer:')); - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - return [ - PreApplyEvent::class => 'checkPackagesInstalledWithComposer', - ]; - } - - /** - * Gets the packages which aren't installed via composer. - * - * @param \Drupal\package_manager\Event\PreApplyEvent $event - * The event object. - * - * @return \Composer\Package\PackageInterface[] - * Packages not installed via composer. - */ - protected function getPackagesNotInstalledWithComposer(PreApplyEvent $event): array { - $stage = $event->getStage(); - $active_composer = $stage->getActiveComposer(); - - $missing_packages = $stage->getStageComposer()->getPackagesNotIn($active_composer); - - // The core update system can only fetch release information for modules, - // themes, or profiles that are in the active code base (whether they're - // installed or not). If a package is not one of those types, ignore it - // even if its vendor namespace is `drupal`. - $types = [ - 'drupal-module', - 'drupal-theme', - 'drupal-profile', - ]; - $filter = function (PackageInterface $package) use ($types): bool { - return in_array($package->getType(), $types, TRUE); - }; - $missing_packages = array_filter($missing_packages, $filter); - - // The core update system can only fetch release information for drupal - // projects, so saving only the packages whose name starts with drupal/. - $missing_packages = array_filter($missing_packages, function (string $key) { - return str_starts_with($key, 'drupal/'); - }, ARRAY_FILTER_USE_KEY); - return $missing_packages; - } - -} diff --git a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/active/vendor/composer/installed.json b/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/active/vendor/composer/installed.json deleted file mode 100644 index a220e444fa0ceb5f4cf3d3bbdfff469dd1d19ac8..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/active/vendor/composer/installed.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "packages": [ - { - "name": "drupal/core-recommended", - "version": "9.8.0", - "require": { - "drupal/core": "9.8.0" - } - }, - { - "name": "drupal/core", - "version": "9.8.0" - }, - { - "name": "drupal/my_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/my_dev_module", - "version": "9.8.1", - "type": "drupal-module" - }, - { - "name": "drupal/existing_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/existing_theme", - "version": "9.8.0", - "type": "drupal-theme" - }, - { - "name": "drupal/existing_profile", - "version": "9.8.0", - "type": "drupal-profile" - } - ], - "dev": true, - "dev-package-names": [ - "drupal/my_dev_module" - ] -} diff --git a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_not_installed_stage/vendor/composer/installed.json b/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_not_installed_stage/vendor/composer/installed.json deleted file mode 100644 index 3ad2ba801c1bfdfb46b380db265d49c607e34161..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_not_installed_stage/vendor/composer/installed.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "packages": [ - { - "name": "drupal/core-recommended", - "version": "9.8.0", - "require": { - "drupal/core": "9.8.0" - } - }, - { - "name": "drupal/core", - "version": "9.8.0" - }, - { - "name": "drupal/my_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/my_dev_module", - "version": "9.8.1", - "type": "drupal-module" - }, - { - "name": "drupal/new_module", - "version": "9.8.0", - "type": "drupal-module" - } - ], - "dev": true, - "dev-package-names": [ - "drupal/my_dev_module" - ] -} diff --git a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_theme_profile_dependency_not_installed_stage/vendor/composer/installed.json b/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_theme_profile_dependency_not_installed_stage/vendor/composer/installed.json deleted file mode 100644 index c6b553899bda162dccf1b0ff00bee6444ebcb471..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_theme_profile_dependency_not_installed_stage/vendor/composer/installed.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "packages": [ - { - "name": "drupal/core-recommended", - "version": "9.8.0", - "require": { - "drupal/core": "9.8.0" - } - }, - { - "name": "drupal/core", - "version": "9.8.0" - }, - { - "name": "drupal/my_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/my_dev_module", - "version": "9.8.1", - "type": "drupal-module" - }, - { - "name": "drupal/new_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "not-drupal/new_module1", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/new_theme", - "version": "9.8.0", - "type": "drupal-theme" - }, - { - "name": "drupal/new_profile", - "version": "9.8.0", - "type": "drupal-profile" - }, - { - "name": "drupal/new_dependency", - "version": "9.8.0", - "type": "drupal-library" - } - ], - "dev": true, - "dev-package-names": [ - "drupal/my_dev_module" - ] -} diff --git a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/profile_not_installed_stage/vendor/composer/installed.json b/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/profile_not_installed_stage/vendor/composer/installed.json deleted file mode 100644 index c4c8db4e547a1935017371d6df2dd1caad59fd56..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/profile_not_installed_stage/vendor/composer/installed.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "packages": [ - { - "name": "drupal/core-recommended", - "version": "9.8.0", - "require": { - "drupal/core": "9.8.0" - } - }, - { - "name": "drupal/core", - "version": "9.8.0" - }, - { - "name": "drupal/my_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/my_dev_module", - "version": "9.8.1", - "type": "drupal-module" - }, - { - "name": "drupal/new_profile", - "version": "9.8.0", - "type": "drupal-profile" - } - ], - "dev": true, - "dev-package-names": [ - "drupal/my_dev_module" - ] -} diff --git a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/theme_not_installed_stage/vendor/composer/installed.json b/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/theme_not_installed_stage/vendor/composer/installed.json deleted file mode 100644 index e09bb8a0fd3758badcbdd824a58379c4be7c87cd..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/theme_not_installed_stage/vendor/composer/installed.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "packages": [ - { - "name": "drupal/core-recommended", - "version": "9.8.0", - "require": { - "drupal/core": "9.8.0" - } - }, - { - "name": "drupal/core", - "version": "9.8.0" - }, - { - "name": "drupal/my_module", - "version": "9.8.0", - "type": "drupal-module" - }, - { - "name": "drupal/my_dev_module", - "version": "9.8.1", - "type": "drupal-module" - }, - { - "name": "drupal/new_theme", - "version": "9.8.0", - "type": "drupal-theme" - } - ], - "dev": true, - "dev-package-names": [ - "drupal/my_dev_module" - ] -} diff --git a/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php b/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php index b674eeb03aab9b7aca8113e468a1911e9fd6f2c5..c9c7e1d177020e8b27ba74e3727854281b60e362 100644 --- a/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php +++ b/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php @@ -60,8 +60,6 @@ END; // Use the API endpoint to create a stage and update the 'new_module' module // to 1.1.0. // @see \Drupal\automatic_updates_extensions_test_api\ApiController::run() - // There will be error in updating as this module is not installed - // via composer @see \Drupal\Tests\automatic_updates_extensions\Kernel\Validator\PackagesInstalledWithComposerValidatorTest. $query = http_build_query([ 'projects' => [ 'new_module' => '1.1.0', diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php index c0c6f28d7161c0b8af7bc0080de38a08426e9707..9e421d1f23d9d75ebf27f4804d21f0a48e8aff4e 100644 --- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php +++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php @@ -65,12 +65,8 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { * {@inheritdoc} */ protected function setUp(): void { - // In this test class, some modules are added and this validator will - // complain because these are not installed via composer. This validator - // already has test coverage. - // @see \Drupal\Tests\automatic_updates_extensions\Build\ModuleUpdateTest - $this->disableValidators[] = 'automatic_updates_extensions.validator.packages_installed_with_composer'; parent::setUp(); + $user = $this->createUser([ 'administer site configuration', 'administer software updates', diff --git a/automatic_updates_extensions/tests/src/Kernel/Validator/PackagesInstalledWithComposerValidatorTest.php b/automatic_updates_extensions/tests/src/Kernel/Validator/PackagesInstalledWithComposerValidatorTest.php deleted file mode 100644 index 42c3068a9f4e8187bb7d253f7610c661e0141f03..0000000000000000000000000000000000000000 --- a/automatic_updates_extensions/tests/src/Kernel/Validator/PackagesInstalledWithComposerValidatorTest.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -namespace Drupal\Tests\automatic_updates_extensions\Kernel\Validator; - -use Drupal\package_manager\Event\PreApplyEvent; -use Drupal\package_manager\ValidationResult; -use Drupal\Tests\automatic_updates_extensions\Kernel\AutomaticUpdatesExtensionsKernelTestBase; - -/** - * Validates the installed packages via composer after an update. - * - * @coversDefaultClass \Drupal\automatic_updates_extensions\Validator\PackagesInstalledWithComposerValidator - * - * @group automatic_updates_extensions - */ -class PackagesInstalledWithComposerValidatorTest extends AutomaticUpdatesExtensionsKernelTestBase { - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - // In this test, we don't care whether the updated projects are secure and - // supported. - $this->disableValidators[] = 'automatic_updates_extensions.validator.target_release'; - $this->disableValidators[] = 'package_manager.validator.supported_releases'; - // @todo The validator being tested covers the same cases as the following - // validator. PackagesInstalledWithComposerValidatorTest will be removed - // in https://drupal.org/i/3303900. - $this->disableValidators[] = 'package_manager.validator.overwrite_existing_packages'; - parent::setUp(); - } - - /** - * Data provider for testPreApplyException(). - * - * @return mixed[][] - * The test cases. - */ - public function providerPreApplyException(): array { - $summary = t('Automatic Updates can only update projects that were installed via Composer. The following packages are not installed through composer:'); - $fixtures_folder = __DIR__ . '/../../../fixtures/packages_installed_with_composer_validator'; - - return [ - 'module not installed via Composer' => [ - "$fixtures_folder/module_not_installed_stage", - [ - ValidationResult::createError(['new_module'], $summary), - ], - ], - 'theme not installed via Composer' => [ - "$fixtures_folder/theme_not_installed_stage", - [ - ValidationResult::createError(['new_theme'], $summary), - ], - ], - 'profile not installed via Composer' => [ - "$fixtures_folder/profile_not_installed_stage", - [ - ValidationResult::createError(['new_profile'], $summary), - ], - ], - // The `drupal/new_dependency` package won't show up in the error because - // its type is `drupal-library`, and the validator only considers the - // `drupal-module`, `drupal-theme`, and `drupal-profile` package types. - // The `not-drupal/new_module1` package won't show up either, even though - // its type is `drupal-module`, because it doesn't start with `drupal/`. - // @see \Drupal\automatic_updates_extensions\Validator\PackagesInstalledWithComposerValidator - 'module, theme, and profile not installed via Composer' => [ - "$fixtures_folder/module_theme_profile_dependency_not_installed_stage", - [ - ValidationResult::createError( - ['new_module', 'new_theme', 'new_profile'], - $summary - ), - ], - ], - ]; - } - - /** - * Tests the packages installed with composer during pre-apply. - * - * @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 providerPreApplyException - */ - public function testPreApplyException(string $stage_dir, array $expected_results): void { - $active_dir = __DIR__ . '/../../../fixtures/packages_installed_with_composer_validator/active'; - $this->copyFixtureFolderToActiveDirectory($active_dir); - $this->copyFixtureFolderToStageDirectoryOnApply($stage_dir); - $this->assertUpdateResults(['my_module' => '9.8.1'], $expected_results, PreApplyEvent::class); - } - -} diff --git a/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php b/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php index b83fc5b7d9616390f7db02a91da2e48ee2fe9625..cc0e70ae67239130e27ca9323cca71e5ffaa7a8d 100644 --- a/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php +++ b/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php @@ -14,14 +14,6 @@ use Drupal\Tests\automatic_updates_extensions\Kernel\AutomaticUpdatesExtensionsK */ class UpdateReleaseValidatorTest extends AutomaticUpdatesExtensionsKernelTestBase { - /** - * {@inheritdoc} - */ - protected function setUp(): void { - $this->disableValidators[] = 'automatic_updates_extensions.validator.packages_installed_with_composer'; - parent::setUp(); - } - /** * Data provider for testPreCreateException(). *