Commit 74a50236 authored by effulgentsia's avatar effulgentsia

Issue #2580389 by benjy, alexpott, jibran: Allow test classes to specify the...

Issue #2580389 by benjy, alexpott, jibran: Allow test classes to specify the config object exceptions
parent 35af6480
......@@ -43,14 +43,24 @@ class ConfigSchemaChecker implements EventSubscriberInterface {
*/
protected $checked = array();
/**
* An array of config object names that are excluded from schema checking.
*
* @var string[]
*/
protected $exclude = array();
/**
* Constructs the ConfigSchemaChecker object.
*
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_manager
* The typed config manager.
* @param string[] $exclude
* An array of config object names that are excluded from schema checking.
*/
public function __construct(TypedConfigManagerInterface $typed_manager) {
public function __construct(TypedConfigManagerInterface $typed_manager, array $exclude = array()) {
$this->typedManager = $typed_manager;
$this->exclude = $exclude;
}
/**
......@@ -74,17 +84,7 @@ public function onConfigSave(ConfigCrudEvent $event) {
$name = $saved_config->getName();
$data = $saved_config->get();
$checksum = hash('crc32b', serialize($data));
$exceptions = array(
// Following are used to test lack of or partial schema. Where partial
// schema is provided, that is explicitly tested in specific tests.
'config_schema_test.noschema',
'config_schema_test.someschema',
'config_schema_test.schema_data_types',
'config_schema_test.no_schema_data_types',
// Used to test application of schema to filtering of configuration.
'config_test.dynamic.system',
);
if (!in_array($name, $exceptions) && !isset($this->checked[$name . ':' . $checksum])) {
if (!in_array($name, $this->exclude) && !isset($this->checked[$name . ':' . $checksum])) {
$this->checked[$name . ':' . $checksum] = TRUE;
$errors = $this->checkConfigSchema($this->typedManager, $name, $data);
if ($errors === FALSE) {
......
......@@ -322,6 +322,7 @@ public function containerBuild(ContainerBuilder $container) {
$container
->register('simpletest.config_schema_checker', 'Drupal\Core\Config\Testing\ConfigSchemaChecker')
->addArgument(new Reference('config.typed'))
->addArgument($this->getConfigSchemaExclusions())
->addTag('event_subscriber');
}
......
......@@ -294,6 +294,22 @@ abstract class TestBase {
*/
protected $strictConfigSchema = TRUE;
/**
* An array of config object names that are excluded from schema checking.
*
* @var string[]
*/
protected static $configSchemaCheckerExclusions = array(
// Following are used to test lack of or partial schema. Where partial
// schema is provided, that is explicitly tested in specific tests.
'config_schema_test.noschema',
'config_schema_test.someschema',
'config_schema_test.schema_data_types',
'config_schema_test.no_schema_data_types',
// Used to test application of schema to filtering of configuration.
'config_test.dynamic.system',
);
/**
* HTTP authentication method (specified as a CURLAUTH_* constant).
*
......@@ -1585,4 +1601,23 @@ public function getTempFilesDirectory() {
return $this->tempFilesDirectory;
}
/**
* Gets the config schema exclusions for this test.
*
* @return string[]
* An array of config object names that are excluded from schema checking.
*/
protected function getConfigSchemaExclusions() {
$class = get_class($this);
$exceptions = [];
while ($class) {
if (property_exists($class, 'configSchemaCheckerExclusions')) {
$exceptions = array_merge($exceptions, $class::$configSchemaCheckerExclusions);
}
$class = get_parent_class($class);
}
// Filter out any duplicates.
return array_unique($exceptions);
}
}
......@@ -785,7 +785,7 @@ protected function prepareSettings() {
$services = $yaml->parse($content);
$services['services']['simpletest.config_schema_checker'] = [
'class' => 'Drupal\Core\Config\Testing\ConfigSchemaChecker',
'arguments' => ['@config.typed'],
'arguments' => ['@config.typed', $this->getConfigSchemaExclusions()],
'tags' => [['name' => 'event_subscriber']]
];
file_put_contents($directory . '/services.yml', $yaml->dump($services));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment