From 7d40ee3076eb79db4a88d927fce4b338061ced60 Mon Sep 17 00:00:00 2001 From: "omkar.podey" <omkar.podey@3685158.no-reply.drupal.org> Date: Tue, 27 Sep 2022 14:49:06 +0000 Subject: [PATCH] Issue #3303900 by phenaproxima, omkar.podey: Remove PreApply check in PackagesInstalledWithComposerValidator --- .../automatic_updates_extensions.services.yml | 6 -- ...PackagesInstalledWithComposerValidator.php | 98 ------------------- .../active/vendor/composer/installed.json | 44 --------- .../vendor/composer/installed.json | 34 ------- .../vendor/composer/installed.json | 54 ---------- .../vendor/composer/installed.json | 34 ------- .../vendor/composer/installed.json | 34 ------- .../tests/src/Build/ModuleUpdateTest.php | 2 - .../tests/src/Functional/UpdaterFormTest.php | 6 +- ...agesInstalledWithComposerValidatorTest.php | 98 ------------------- .../Validator/UpdateReleaseValidatorTest.php | 8 -- 11 files changed, 1 insertion(+), 417 deletions(-) delete mode 100644 automatic_updates_extensions/src/Validator/PackagesInstalledWithComposerValidator.php delete mode 100644 automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/active/vendor/composer/installed.json delete mode 100644 automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_not_installed_stage/vendor/composer/installed.json delete mode 100644 automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/module_theme_profile_dependency_not_installed_stage/vendor/composer/installed.json delete mode 100644 automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/profile_not_installed_stage/vendor/composer/installed.json delete mode 100644 automatic_updates_extensions/tests/fixtures/packages_installed_with_composer_validator/theme_not_installed_stage/vendor/composer/installed.json delete mode 100644 automatic_updates_extensions/tests/src/Kernel/Validator/PackagesInstalledWithComposerValidatorTest.php diff --git a/automatic_updates_extensions/automatic_updates_extensions.services.yml b/automatic_updates_extensions/automatic_updates_extensions.services.yml index 4e38d2f244..95de366d61 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 487b46a64f..0000000000 --- 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 a220e444fa..0000000000 --- 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 3ad2ba801c..0000000000 --- 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 c6b553899b..0000000000 --- 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 c4c8db4e54..0000000000 --- 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 e09bb8a0fd..0000000000 --- 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 b674eeb03a..c9c7e1d177 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 c0c6f28d71..9e421d1f23 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 42c3068a9f..0000000000 --- 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 b83fc5b7d9..cc0e70ae67 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(). * -- GitLab