Skip to content
Snippets Groups Projects
Commit 2a39d899 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3295874 by phenaproxima: In functional tests, use the state service to...

Issue #3295874 by phenaproxima: In functional tests, use the state service to simulate staged database updates
parent 02af438a
No related branches found
No related tags found
1 merge request!379Issue #3295874: In functional tests, use the state service to simulate staged database updates
......@@ -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;
......
<?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'),
]);
}
}
}
<?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);
}
}
......@@ -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');
......
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