From 9bff583f67403f5fbad50d839b41a3249a0adefb Mon Sep 17 00:00:00 2001 From: Kunal Sachdev <57170-kunal.sachdev@users.noreply.drupalcode.org> Date: Wed, 21 Jun 2023 19:29:44 +0000 Subject: [PATCH] Issue #3365177 by kunal.sachdev, tedbow: RequestedUpdateValidator should subscribe to StatusCheckEvent --- src/Validator/RequestedUpdateValidator.php | 8 +++++--- tests/src/Functional/UpdateLockTest.php | 4 ++-- tests/src/Functional/UpdateWarningTest.php | 1 + .../RequestedUpdateValidatorTest.php | 20 +++++++++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Validator/RequestedUpdateValidator.php b/src/Validator/RequestedUpdateValidator.php index fc3bcea5c9..09762abe26 100644 --- a/src/Validator/RequestedUpdateValidator.php +++ b/src/Validator/RequestedUpdateValidator.php @@ -9,6 +9,7 @@ use Drupal\automatic_updates\UpdateStage; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\ComposerInspector; use Drupal\package_manager\Event\PreApplyEvent; +use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -40,12 +41,12 @@ final class RequestedUpdateValidator implements EventSubscriberInterface { /** * Validates that requested packages have been updated to the right version. * - * @param \Drupal\package_manager\Event\PreApplyEvent $event + * @param \Drupal\package_manager\Event\PreApplyEvent|\Drupal\package_manager\Event\StatusCheckEvent $event * The pre-apply event. */ - public function checkRequestedStagedVersion(PreApplyEvent $event): void { + public function checkRequestedStagedVersion(PreApplyEvent|StatusCheckEvent $event): void { $stage = $event->stage; - if (!($stage instanceof UpdateStage)) { + if (!($stage instanceof UpdateStage) || !$stage->stageDirectoryExists()) { return; } $requested_package_versions = $stage->getPackageVersions(); @@ -96,6 +97,7 @@ final class RequestedUpdateValidator implements EventSubscriberInterface { * {@inheritdoc} */ public static function getSubscribedEvents(): array { + $events[StatusCheckEvent::class][] = ['checkRequestedStagedVersion']; $events[PreApplyEvent::class][] = ['checkRequestedStagedVersion']; return $events; } diff --git a/tests/src/Functional/UpdateLockTest.php b/tests/src/Functional/UpdateLockTest.php index 8cab3f1179..a7dcbe76c4 100644 --- a/tests/src/Functional/UpdateLockTest.php +++ b/tests/src/Functional/UpdateLockTest.php @@ -42,7 +42,7 @@ class UpdateLockTest extends AutomaticUpdatesFunctionalTestBase { * Tests that only user who started an update can continue through it. */ public function testLock(): void { - $this->getStageFixtureManipulator()->setCorePackageVersion('9.8.1'); + $this->getStageFixtureManipulator()->setCorePackageVersion('9.8.2'); $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $this->mockActiveCoreVersion('9.8.0'); @@ -56,7 +56,7 @@ class UpdateLockTest extends AutomaticUpdatesFunctionalTestBase { $this->drupalGet('/admin/modules/update'); $page->pressButton('Update'); $this->checkForMetaRefresh(); - $this->assertUpdateReady('9.8.1'); + $this->assertUpdateReady('9.8.2'); $assert_session->buttonExists('Continue'); $url = $this->getSession()->getCurrentUrl(); diff --git a/tests/src/Functional/UpdateWarningTest.php b/tests/src/Functional/UpdateWarningTest.php index 27da2f1228..96ad003883 100644 --- a/tests/src/Functional/UpdateWarningTest.php +++ b/tests/src/Functional/UpdateWarningTest.php @@ -19,6 +19,7 @@ class UpdateWarningTest extends UpdaterFormTestBase { * Tests that update can be completed even if a status check throws a warning. */ public function testContinueOnWarning(): void { + $this->getStageFixtureManipulator()->setCorePackageVersion('9.8.1'); $session = $this->getSession(); $this->mockActiveCoreVersion('9.8.0'); diff --git a/tests/src/Kernel/StatusCheck/RequestedUpdateValidatorTest.php b/tests/src/Kernel/StatusCheck/RequestedUpdateValidatorTest.php index 6232821993..7ffd8cbdfe 100644 --- a/tests/src/Kernel/StatusCheck/RequestedUpdateValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/RequestedUpdateValidatorTest.php @@ -41,13 +41,13 @@ class RequestedUpdateValidatorTest extends AutomaticUpdatesKernelTestBase { $this->container->get('module_installer')->install(['automatic_updates']); $stage = $this->container->get(UpdateStage::class); - $stage->begin(['drupal' => '9.8.1']); - $stage->stage(); - $expected_results = [ ValidationResult::createError([t("The requested update to 'drupal/core-recommended' to version '9.8.1' does not match the actual staged update to '9.8.2'.")]), ValidationResult::createError([t("The requested update to 'drupal/core-dev' to version '9.8.1' was not performed.")]), ]; + $stage->begin(['drupal' => '9.8.1']); + $this->assertStatusCheckResults($expected_results, $stage); + $stage->stage(); try { $stage->apply(); $this->fail('Expecting an exception.'); @@ -72,12 +72,20 @@ class RequestedUpdateValidatorTest extends AutomaticUpdatesKernelTestBase { ]); $this->container->get('module_installer')->install(['automatic_updates']); + $expected_results = [ + ValidationResult::createError([t('No updates detected in the staging area.')]), + ]; $stage = $this->container->get(UpdateStage::class); $stage->begin(['drupal' => '9.8.1']); + $this->assertStatusCheckResults($expected_results, $stage); $stage->stage(); - $this->expectException(StageEventException::class); - $this->expectExceptionMessage('No updates detected in the staging area.'); - $stage->apply(); + try { + $stage->apply(); + $this->fail('Expecting an exception.'); + } + catch (StageEventException $exception) { + $this->assertExpectedResultsFromException($expected_results, $exception); + } } } -- GitLab