Skip to content
Snippets Groups Projects
Commit 9bff583f authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Adam G-H
Browse files

Issue #3365177 by kunal.sachdev, tedbow: RequestedUpdateValidator should...

Issue #3365177 by kunal.sachdev, tedbow: RequestedUpdateValidator should subscribe to StatusCheckEvent
parent bdc38a94
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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();
......
......@@ -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');
......
......@@ -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);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment