diff --git a/src/Validator/StagedDatabaseUpdateValidator.php b/src/Validator/StagedDatabaseUpdateValidator.php index d7ed7ecf4c635ec4baa6cb2bd96a8126b4f5b78e..fb386c6b4d698b5a5374694c468d9cb20e6bd150 100644 --- a/src/Validator/StagedDatabaseUpdateValidator.php +++ b/src/Validator/StagedDatabaseUpdateValidator.php @@ -21,7 +21,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; * at any time without warning. External code should not interact with this * class. */ -final class StagedDatabaseUpdateValidator implements EventSubscriberInterface { +class StagedDatabaseUpdateValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/tests/modules/automatic_updates_test/src/AutomaticUpdatesTestServiceProvider.php b/tests/modules/automatic_updates_test/src/AutomaticUpdatesTestServiceProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..3dfd3dd79d0d04e0b5abfcd182ceb929de5a6ae7 --- /dev/null +++ b/tests/modules/automatic_updates_test/src/AutomaticUpdatesTestServiceProvider.php @@ -0,0 +1,30 @@ +<?php + +namespace Drupal\automatic_updates_test; + +use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\DependencyInjection\ServiceProviderBase; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Modifies container services for testing. + */ +class AutomaticUpdatesTestServiceProvider extends ServiceProviderBase { + + /** + * {@inheritdoc} + */ + public function alter(ContainerBuilder $container) { + parent::alter($container); + + $service_id = 'automatic_updates.validator.staged_database_updates'; + if ($container->hasDefinition($service_id)) { + $container->getDefinition($service_id) + ->setClass(StagedDatabaseUpdateValidator::class) + ->addMethodCall('setState', [ + new Reference('state'), + ]); + } + } + +} diff --git a/tests/modules/automatic_updates_test/src/StagedDatabaseUpdateValidator.php b/tests/modules/automatic_updates_test/src/StagedDatabaseUpdateValidator.php new file mode 100644 index 0000000000000000000000000000000000000000..34d1b0ca1298a7d77c562d3232e9dd2b2e5f4015 --- /dev/null +++ b/tests/modules/automatic_updates_test/src/StagedDatabaseUpdateValidator.php @@ -0,0 +1,54 @@ +<?php + +namespace Drupal\automatic_updates_test; + +use Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator as BaseValidator; +use Drupal\Core\Extension\Extension; +use Drupal\Core\State\StateInterface; +use Drupal\package_manager\Stage; + +/** + * Allows tests to dictate which extensions have staged database updates. + */ +class StagedDatabaseUpdateValidator extends BaseValidator { + + /** + * The state service. + * + * @var \Drupal\Core\State\StateInterface + */ + private $state; + + /** + * Sets the state service dependency. + * + * @param \Drupal\Core\State\StateInterface $state + * The state service. + */ + public function setState(StateInterface $state) { + $this->state = $state; + } + + /** + * Sets the names of the extensions which should have staged database updates. + * + * @param string[]|null $extensions + * The machine names of the extensions which should say they have staged + * database updates, or NULL to defer to the parent class. + */ + public static function setExtensionsWithUpdates(?array $extensions): void { + \Drupal::state()->set(static::class, $extensions); + } + + /** + * {@inheritdoc} + */ + public function hasStagedUpdates(Stage $stage, Extension $extension): bool { + $extensions = $this->state->get(static::class); + if (isset($extensions)) { + return in_array($extension->getName(), $extensions, TRUE); + } + return parent::hasStagedUpdates($stage, $extension); + } + +} diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php index 475a4578174e2909f53863bb16c641cafd98dcca..746958a148d312814d4c8bad81abe92e0665f3d3 100644 --- a/tests/src/Functional/UpdaterFormTest.php +++ b/tests/src/Functional/UpdaterFormTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\automatic_updates\Functional; use Drupal\automatic_updates\Event\ReadinessCheckEvent; 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\PreCreateEvent; @@ -467,6 +468,8 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); $messages = reset($expected_results)->getMessages(); + StagedDatabaseUpdateValidator::setExtensionsWithUpdates(['system', 'automatic_updates_theme_with_updates']); + $page = $this->getSession()->getPage(); $this->drupalGet('/admin/modules/automatic-update'); Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');