Commit 3308cc49 authored by Rahul Gupta's avatar Rahul Gupta Committed by Ted Bowman
Browse files

Issue #3304640 by rahul_, tedbow: Logic error in...

Issue #3304640 by rahul_, tedbow: Logic error in \Drupal\automatic_updates\Controller\UpdateController::onFinish
parent 6b2c682f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -135,6 +135,10 @@ class TestSubscriber implements EventSubscriberInterface {
    elseif ($results === 'exit') {
      exit();
    }
    elseif (is_string($results)) {
      \Drupal::messenger()->addStatus($results);
      return;
    }
    /** @var \Drupal\package_manager\ValidationResult $result */
    foreach ($results as $result) {
      if ($result->getSeverity() === SystemManager::REQUIREMENT_ERROR) {
@@ -164,4 +168,18 @@ class TestSubscriber implements EventSubscriberInterface {
    ];
  }

  /**
   * Sets a status message that will be sent to the messenger for an event.
   *
   * @param string $message
   *   Message text.
   * @param string $event
   *   The event class.
   */
  public static function setMessage(string $message, string $event): void {
    $key = static::getStateKey($event);
    $state = \Drupal::state();
    $state->set($key, $message);
  }

}
+4 −4
Original line number Diff line number Diff line
@@ -78,13 +78,13 @@ final class UpdateController extends ControllerBase {
        // @todo Remove once the core bug that shows the maintenance mode
        //   message after the site is out of maintenance mode is fixed in
        //   https://www.drupal.org/i/3279246.
        $messages = $this->messenger()->messagesByType(MessengerInterface::TYPE_STATUS);
        $messages = array_filter($messages, function (string $message) {
        $status_messages = $this->messenger()->messagesByType(MessengerInterface::TYPE_STATUS);
        $status_messages = array_filter($status_messages, function (string $message) {
          return !str_starts_with($message, (string) $this->t('Operating in maintenance mode.'));
        });
        $this->messenger()->deleteByType(MessengerInterface::TYPE_STATUS);
        foreach ($messages as $message) {
          $this->messenger()->addStatus($message);
        foreach ($status_messages as $status_message) {
          $this->messenger()->addStatus($status_message);
        }
      }
    }
+43 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Drupal\automatic_updates_test\Datetime\TestTime;
use Drupal\automatic_updates_test\StagedDatabaseUpdateValidator;
use Drupal\package_manager\Event\PostRequireEvent;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PostApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
@@ -601,6 +602,48 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
    $this->assertNotSame($pre_apply_time, $post_apply_time);
  }

  /**
   * Data provider for testUpdateCompleteMessage().
   *
   * @return string[][]
   *   The test cases.
   */
  public function providerUpdateCompleteMessage(): array {
    return [
      'maintenance mode off' => [FALSE],
      'maintenance mode on' => [TRUE],
    ];
  }

  /**
   * Tests the update complete message is displayed when another message exist.
   *
   * @param bool $maintenance_mode_on
   *   Whether maintenance should be on at the beginning of the update.
   *
   * @dataProvider providerUpdateCompleteMessage
   */
  public function testUpdateCompleteMessage(bool $maintenance_mode_on): void {
    $assert_session = $this->assertSession();
    $this->setCoreVersion('9.8.0');
    $this->checkForUpdates();
    $state = $this->container->get('state');
    $state->set('system.maintenance_mode', $maintenance_mode_on);
    $page = $this->getSession()->getPage();

    $this->drupalGet('/admin/modules/automatic-update');
    Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
    $page->pressButton('Update to 9.8.1');
    $this->checkForMetaRefresh();
    // Confirm that the site was put into maintenance mode if needed.
    $custom_message = 'custom status message.';
    TestSubscriber1::setMessage($custom_message, PostApplyEvent::class);
    $page->pressButton('Continue');
    $this->checkForMetaRefresh();
    $assert_session->pageTextContainsOnce($custom_message);
    $assert_session->pageTextContainsOnce('Update complete!');
  }

  /**
   * Tests what happens when a staged update is deleted without being destroyed.
   */