Skip to content
Snippets Groups Projects
Commit 9e2c8f7e authored by Rahul Gupta's avatar Rahul Gupta Committed by Adam G-H
Browse files

Issue #3303113 by phenaproxima, rahul_, rkoller, tedbow: Add bullet points to...

Issue #3303113 by phenaproxima, rahul_, rkoller, tedbow: Add bullet points to the modules listed on the ready to update pages warning message
parent 5bcd830a
No related branches found
No related tags found
1 merge request!426Issue #3303113: Add bullet points to the modules listed on the ready to update pages warning message
...@@ -10,6 +10,7 @@ use Drupal\Core\Batch\BatchBuilder; ...@@ -10,6 +10,7 @@ use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
use Drupal\package_manager\Exception\StageException; use Drupal\package_manager\Exception\StageException;
...@@ -52,6 +53,13 @@ final class UpdateReady extends FormBase { ...@@ -52,6 +53,13 @@ final class UpdateReady extends FormBase {
*/ */
protected $stagedDatabaseUpdateValidator; protected $stagedDatabaseUpdateValidator;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/** /**
* Constructs a new UpdateReady object. * Constructs a new UpdateReady object.
* *
...@@ -65,13 +73,16 @@ final class UpdateReady extends FormBase { ...@@ -65,13 +73,16 @@ final class UpdateReady extends FormBase {
* The module list service. * The module list service.
* @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator * @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator
* The staged database update validator service. * The staged database update validator service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/ */
public function __construct(ExtensionUpdater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator) { public function __construct(ExtensionUpdater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator, RendererInterface $renderer) {
$this->updater = $updater; $this->updater = $updater;
$this->setMessenger($messenger); $this->setMessenger($messenger);
$this->state = $state; $this->state = $state;
$this->moduleList = $module_list; $this->moduleList = $module_list;
$this->stagedDatabaseUpdateValidator = $staged_database_update_validator; $this->stagedDatabaseUpdateValidator = $staged_database_update_validator;
$this->renderer = $renderer;
} }
/** /**
...@@ -90,7 +101,8 @@ final class UpdateReady extends FormBase { ...@@ -90,7 +101,8 @@ final class UpdateReady extends FormBase {
$container->get('messenger'), $container->get('messenger'),
$container->get('state'), $container->get('state'),
$container->get('extension.list.module'), $container->get('extension.list.module'),
$container->get('automatic_updates.validator.staged_database_updates') $container->get('automatic_updates.validator.staged_database_updates'),
$container->get('renderer')
); );
} }
...@@ -113,10 +125,16 @@ final class UpdateReady extends FormBase { ...@@ -113,10 +125,16 @@ final class UpdateReady extends FormBase {
// changes have been applied. // changes have been applied.
$pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater); $pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater);
if ($pending_updates) { if ($pending_updates) {
$messages[MessengerInterface::TYPE_WARNING][] = $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.'); natcasesort($pending_updates);
foreach ($pending_updates as $pending_update) { $message_item_list = [
$messages[MessengerInterface::TYPE_WARNING][] = $pending_update; '#theme' => 'item_list',
} '#prefix' => '<p>' . $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.') . '</p>',
'#items' => $pending_updates,
'#context' => [
'list_style' => 'automatic-updates-extensions__pending-database-updates',
],
];
$messages[MessengerInterface::TYPE_WARNING][] = $this->renderer->renderRoot($message_item_list);
} }
// Don't set any messages if the form has been submitted, because we don't // Don't set any messages if the form has been submitted, because we don't
......
...@@ -190,10 +190,15 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -190,10 +190,15 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertUpdateStagedTimes(1); $this->assertUpdateStagedTimes(1);
// Confirm that the site was put into maintenance mode if needed. // Confirm that the site was put into maintenance mode if needed.
$this->assertSame($state->get('system.maintenance_mode'), $maintenance_mode_on); $this->assertSame($state->get('system.maintenance_mode'), $maintenance_mode_on);
$possible_update_message = 'Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.';
$assert_session->pageTextContains($possible_update_message); // Ensure that a list of pending database updates is visible, along with a
$assert_session->pageTextContainsOnce('System'); // short explanation, in the warning messages.
$assert_session->pageTextContainsOnce('Automatic Updates Theme With Updates'); $warning_messages = $assert_session->elementExists('xpath', '//div[@data-drupal-messages]//div[@aria-label="Warning message"]');
$this->assertStringContainsString('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.', $warning_messages->getText());
$pending_updates = $warning_messages->findAll('css', 'ul.item-list__automatic-updates-extensions__pending-database-updates li');
$this->assertCount(2, $pending_updates);
$this->assertSame('Automatic Updates Theme With Updates', $pending_updates[0]->getText());
$this->assertSame('System', $pending_updates[1]->getText());
$page->pressButton('Continue'); $page->pressButton('Continue');
$this->checkForMetaRefresh(); $this->checkForMetaRefresh();
......
...@@ -10,6 +10,7 @@ use Drupal\Core\Extension\ModuleExtensionList; ...@@ -10,6 +10,7 @@ use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
use Drupal\package_manager\Exception\StageException; use Drupal\package_manager\Exception\StageException;
use Drupal\package_manager\Exception\StageOwnershipException; use Drupal\package_manager\Exception\StageOwnershipException;
...@@ -51,6 +52,13 @@ final class UpdateReady extends FormBase { ...@@ -51,6 +52,13 @@ final class UpdateReady extends FormBase {
*/ */
protected $stagedDatabaseUpdateValidator; protected $stagedDatabaseUpdateValidator;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/** /**
* Constructs a new UpdateReady object. * Constructs a new UpdateReady object.
* *
...@@ -64,13 +72,16 @@ final class UpdateReady extends FormBase { ...@@ -64,13 +72,16 @@ final class UpdateReady extends FormBase {
* The module list service. * The module list service.
* @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator * @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator
* The staged database update validator service. * The staged database update validator service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/ */
public function __construct(Updater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator) { public function __construct(Updater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator, RendererInterface $renderer) {
$this->updater = $updater; $this->updater = $updater;
$this->setMessenger($messenger); $this->setMessenger($messenger);
$this->state = $state; $this->state = $state;
$this->moduleList = $module_list; $this->moduleList = $module_list;
$this->stagedDatabaseUpdateValidator = $staged_database_update_validator; $this->stagedDatabaseUpdateValidator = $staged_database_update_validator;
$this->renderer = $renderer;
} }
/** /**
...@@ -89,7 +100,8 @@ final class UpdateReady extends FormBase { ...@@ -89,7 +100,8 @@ final class UpdateReady extends FormBase {
$container->get('messenger'), $container->get('messenger'),
$container->get('state'), $container->get('state'),
$container->get('extension.list.module'), $container->get('extension.list.module'),
$container->get('automatic_updates.validator.staged_database_updates') $container->get('automatic_updates.validator.staged_database_updates'),
$container->get('renderer')
); );
} }
...@@ -112,10 +124,16 @@ final class UpdateReady extends FormBase { ...@@ -112,10 +124,16 @@ final class UpdateReady extends FormBase {
// the staged changes have been applied. // the staged changes have been applied.
$pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater); $pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater);
if ($pending_updates) { if ($pending_updates) {
$messages[MessengerInterface::TYPE_WARNING][] = $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.'); natcasesort($pending_updates);
foreach ($pending_updates as $pending_update) { $message_item_list = [
$messages[MessengerInterface::TYPE_WARNING][] = $pending_update; '#theme' => 'item_list',
} '#prefix' => '<p>' . $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.') . '</p>',
'#items' => $pending_updates,
'#context' => [
'list_style' => 'automatic-updates__pending-database-updates',
],
];
$messages[MessengerInterface::TYPE_WARNING][] = $this->renderer->renderRoot($message_item_list);
} }
try { try {
......
...@@ -483,10 +483,17 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -483,10 +483,17 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
// changes have been applied, we should be redirected to update.php, where // changes have been applied, we should be redirected to update.php, where
// neither warning should be visible. // neither warning should be visible.
$assert_session->pageTextNotContains(reset($messages)); $assert_session->pageTextNotContains(reset($messages));
// Ensure that a list of pending database updates is visible, along with a
// short explanation, in the warning messages.
$possible_update_message = 'Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.'; $possible_update_message = 'Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.';
$assert_session->pageTextContains($possible_update_message); $warning_messages = $assert_session->elementExists('xpath', '//div[@data-drupal-messages]//div[@aria-label="Warning message"]');
$assert_session->pageTextContains('System'); $this->assertStringContainsString($possible_update_message, $warning_messages->getText());
$assert_session->pageTextContainsOnce('Automatic Updates Theme With Updates'); $pending_updates = $warning_messages->findAll('css', 'ul.item-list__automatic-updates__pending-database-updates li');
$this->assertCount(2, $pending_updates);
$this->assertSame('Automatic Updates Theme With Updates', $pending_updates[0]->getText());
$this->assertSame('System', $pending_updates[1]->getText());
if ($maintenance_mode_on === TRUE) { if ($maintenance_mode_on === TRUE) {
$assert_session->fieldNotExists('maintenance_mode'); $assert_session->fieldNotExists('maintenance_mode');
} }
......
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