diff --git a/tests/modules/automatic_updates_test_disable_validators/automatic_updates_test_disable_validators.info.yml b/tests/modules/automatic_updates_test_disable_validators/automatic_updates_test_disable_validators.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..be3bce29ef81a7b280acffce9f47ba5a468d5094 --- /dev/null +++ b/tests/modules/automatic_updates_test_disable_validators/automatic_updates_test_disable_validators.info.yml @@ -0,0 +1,4 @@ +name: 'Automatic Updates Test - Disable validators' +type: module +description: 'Provides a mechanism to disable specific readiness validators during functional tests' +package: Testing diff --git a/tests/modules/automatic_updates_test_disable_validators/src/AutomaticUpdatesTestDisableValidatorsServiceProvider.php b/tests/modules/automatic_updates_test_disable_validators/src/AutomaticUpdatesTestDisableValidatorsServiceProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..1f009782b61d2b88b2064a407d4e101f17ab768e --- /dev/null +++ b/tests/modules/automatic_updates_test_disable_validators/src/AutomaticUpdatesTestDisableValidatorsServiceProvider.php @@ -0,0 +1,24 @@ +<?php + +namespace Drupal\automatic_updates_test_disable_validators; + +use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\DependencyInjection\ServiceProviderBase; +use Drupal\Core\Site\Settings; + +/** + * Disables specific readiness validators in the service container. + */ +class AutomaticUpdatesTestDisableValidatorsServiceProvider extends ServiceProviderBase { + + /** + * {@inheritdoc} + */ + public function alter(ContainerBuilder $container) { + parent::alter($container); + + $validators = Settings::get('automatic_updates_test_disable_validators', []); + array_walk($validators, [$container, 'removeDefinition']); + } + +} diff --git a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php index 6f694e6180a739ae052548e6db7cdf9ef47bd542..acefb94b1846a8b01a1a33c49aebe1b5761eedcd 100644 --- a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php +++ b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\automatic_updates\Functional; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Site\Settings; use Drupal\Tests\BrowserTestBase; /** @@ -13,7 +13,11 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { /** * {@inheritdoc} */ - protected static $modules = ['update', 'update_test']; + protected static $modules = [ + 'automatic_updates_test_disable_validators', + 'update', + 'update_test', + ]; /** * The service IDs of any validators to disable. @@ -39,26 +43,32 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { } /** - * Disables validators in the test site's services.yml. + * Disables validators in the test site's settings. * * This modifies the service container such that the disabled validators are - * instances of stdClass, and not subscribed to any events. + * not defined at all. This method will have no effect unless the + * automatic_updates_test_disable_validators module is installed. * * @param string[] $validators * The service IDs of the validators to disable. + * + * @see \Drupal\automatic_updates_test_disable_validators\AutomaticUpdatesTestDisableValidatorsServiceProvider::alter() */ protected function disableValidators(array $validators): void { - $services_file = $this->getDrupalRoot() . '/' . $this->siteDirectory . '/services.yml'; - $this->assertFileIsWritable($services_file); - $services = file_get_contents($services_file); - $services = Yaml::decode($services); + $key = 'automatic_updates_test_disable_validators'; + $disabled_validators = Settings::get($key, []); foreach ($validators as $service_id) { - $services['services'][$service_id] = [ - 'class' => 'stdClass', - ]; + $disabled_validators[] = $service_id; } - file_put_contents($services_file, Yaml::encode($services)); + $this->writeSettings([ + 'settings' => [ + $key => (object) [ + 'value' => $disabled_validators, + 'required' => TRUE, + ], + ], + ]); $this->rebuildContainer(); }