Skip to content
Snippets Groups Projects
Commit d4ac1f79 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3266640 by tedbow: Simplify testing a pending update

parent 750930e8
No related branches found
No related tags found
1 merge request!219Issue #3266640: Simplify testing a pending update
<?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) {
}
}
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:
......
<?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);
}
}
<?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());
}
}
<?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);
}
}
<?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();
}
}
......@@ -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
......
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