diff --git a/src/Validator/RequestedUpdateValidator.php b/src/Validator/RequestedUpdateValidator.php index fc3bcea5c9bfeef4fd64894d0b4b27ebf7ea06e4..09762abe2675f85bd4bc31d58e331822ee51d212 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 8cab3f117963f0744524a20b5de1d740d56a09ed..a7dcbe76c4ed7527f350d57df512d584c4e2a48a 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 27da2f1228e793ba7ec01aec2e4414430e00e6e0..96ad003883bdbec4babb54664492ed233b642a93 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 623282199310e668bc3b2735459e7fae2f6ce4cb..7ffd8cbdfe348e4ea7cfc6adc2e4d3e6002c98cb 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); + } } }