diff --git a/tests/modules/automatic_updates_test/automatic_updates_test.install b/tests/modules/automatic_updates_test/automatic_updates_test.install new file mode 100644 index 0000000000000000000000000000000000000000..8bc60b1dae6087ea3c98d03991568ab6169f1cb9 --- /dev/null +++ b/tests/modules/automatic_updates_test/automatic_updates_test.install @@ -0,0 +1,17 @@ +<?php + +/** + * @file + * Contains install and update hooks. + */ + +if (\Drupal::state()->get('automatic_updates_test.new_update')) { + + /** + * Dynamic automatic_updates_update_9001. + */ + function automatic_updates_update_9001(&$sandbox) { + + } + +} diff --git a/tests/modules/automatic_updates_test/automatic_updates_test.services.yml b/tests/modules/automatic_updates_test/automatic_updates_test.services.yml index 2c7c10f707cecab97bc9d09364c41104c6b77c84..165cde6e6466c3845bae609085b47a0ed6cba823 100644 --- a/tests/modules/automatic_updates_test/automatic_updates_test.services.yml +++ b/tests/modules/automatic_updates_test/automatic_updates_test.services.yml @@ -1,8 +1,4 @@ services: - automatic_updates_test.route_subscriber: - class: \Drupal\automatic_updates_test\Routing\RouteSubscriber - tags: - - { name: event_subscriber } automatic_updates_test.checker: class: Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1 tags: diff --git a/tests/modules/automatic_updates_test/src/AutomaticUpdatesTestServiceProvider.php b/tests/modules/automatic_updates_test/src/AutomaticUpdatesTestServiceProvider.php deleted file mode 100644 index 50e1b431493a2a3ad4232bbad0c4ba0a51f9b743..0000000000000000000000000000000000000000 --- a/tests/modules/automatic_updates_test/src/AutomaticUpdatesTestServiceProvider.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace Drupal\automatic_updates_test; - -use Drupal\automatic_updates_test\Validator\TestPendingUpdatesValidator; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\DependencyInjection\ServiceProviderBase; - -/** - * Modifies container services for testing purposes. - */ -class AutomaticUpdatesTestServiceProvider extends ServiceProviderBase { - - /** - * {@inheritdoc} - */ - public function alter(ContainerBuilder $container) { - parent::alter($container); - - $container->getDefinition('package_manager.validator.pending_updates') - ->setClass(TestPendingUpdatesValidator::class); - } - -} diff --git a/tests/modules/automatic_updates_test/src/Form/TestUpdateReady.php b/tests/modules/automatic_updates_test/src/Form/TestUpdateReady.php deleted file mode 100644 index fb749d88bbdffc8ea76356ea5a74d7ca910de6ad..0000000000000000000000000000000000000000 --- a/tests/modules/automatic_updates_test/src/Form/TestUpdateReady.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace Drupal\automatic_updates_test\Form; - -use Drupal\automatic_updates\Form\UpdateReady; - -/** - * A test-only version of the form displayed before applying an update. - */ -class TestUpdateReady extends UpdateReady { - - /** - * {@inheritdoc} - */ - protected function getModulesWithStagedDatabaseUpdates(): array { - return $this->state->get('automatic_updates_test.staged_database_updates', parent::getModulesWithStagedDatabaseUpdates()); - } - -} diff --git a/tests/modules/automatic_updates_test/src/Routing/RouteSubscriber.php b/tests/modules/automatic_updates_test/src/Routing/RouteSubscriber.php deleted file mode 100644 index 3edebbeb351702e96f4a39b01cc7653faf60e4f2..0000000000000000000000000000000000000000 --- a/tests/modules/automatic_updates_test/src/Routing/RouteSubscriber.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -namespace Drupal\automatic_updates_test\Routing; - -use Drupal\automatic_updates_test\Form\TestUpdateReady; -use Drupal\Core\Routing\RouteSubscriberBase; -use Symfony\Component\Routing\RouteCollection; - -/** - * Alters route definitions for testing purposes. - */ -class RouteSubscriber extends RouteSubscriberBase { - - /** - * {@inheritdoc} - */ - protected function alterRoutes(RouteCollection $collection) { - $collection->get('automatic_updates.confirmation_page') - ->setDefault('_form', TestUpdateReady::class); - } - -} diff --git a/tests/modules/automatic_updates_test/src/Validator/TestPendingUpdatesValidator.php b/tests/modules/automatic_updates_test/src/Validator/TestPendingUpdatesValidator.php deleted file mode 100644 index f12963c7b47f01eaf4b53ea91d835ce1ac68c154..0000000000000000000000000000000000000000 --- a/tests/modules/automatic_updates_test/src/Validator/TestPendingUpdatesValidator.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace Drupal\automatic_updates_test\Validator; - -use Drupal\package_manager\Validator\PendingUpdatesValidator; - -/** - * Defines a test-only implementation of the pending updates validator. - */ -class TestPendingUpdatesValidator extends PendingUpdatesValidator { - - /** - * {@inheritdoc} - */ - public function updatesExist(): bool { - $pending_updates = \Drupal::state() - ->get('automatic_updates_test.staged_database_updates', []); - - // If the System module should expose a pending update, create one that will - // be detected by the update hook registry. We only do this for System so - // that there is NO way we could possibly evaluate any user input (i.e., - // if malicious code were somehow injected into state). - if (array_key_exists('system', $pending_updates)) { - // @codingStandardsIgnoreLine - eval('function system_update_4294967294() {}'); - } - return parent::updatesExist(); - } - -} diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php index 2e4f6ed52577e79db983c74d626330b75bd211b1..69093a54d9e517712235bdfaa666504f08326f2f 100644 --- a/tests/src/Functional/UpdaterFormTest.php +++ b/tests/src/Functional/UpdaterFormTest.php @@ -363,15 +363,10 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->checkForMetaRefresh(); $this->assertUpdateStagedTimes(1); $this->assertUpdateReady(); - // Simulate a staged database update in the System module. We must do this - // after the update has started, because the pending updates validator - // will prevent an update from starting. - $this->container->get('state') - ->set('automatic_updates_test.staged_database_updates', [ - 'system' => [ - 'name' => 'System', - ], - ]); + // Simulate a staged database update in the automatic_updates_test module. + // We must do this after the update has started, because the pending updates + // validator will prevent an update from starting. + $this->container->get('state')->set('automatic_updates_test.new_update', TRUE); // The warning from the updater form should be not be repeated, but we // should see a warning about pending database updates, and once the staged // changes have been applied, we should be redirected to update.php, where