Issue #2580389 by benjy, alexpott, jibran: Allow test classes to specify the config object exceptions

8.0.x
effulgentsia 2015-10-15 11:04:55 -07:00
parent 35af648043
commit 74a50236b8
4 changed files with 49 additions and 13 deletions

View File

@ -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 @@ class ConfigSchemaChecker implements EventSubscriberInterface {
$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) {

View File

@ -322,6 +322,7 @@ EOD;
$container
->register('simpletest.config_schema_checker', 'Drupal\Core\Config\Testing\ConfigSchemaChecker')
->addArgument(new Reference('config.typed'))
->addArgument($this->getConfigSchemaExclusions())
->addTag('event_subscriber');
}

View File

@ -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 @@ abstract class TestBase {
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);
}
}

View File

@ -785,7 +785,7 @@ abstract class WebTestBase extends TestBase {
$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));