Commit ae049e93 authored by catch's avatar catch

Issue #2391021 by Gábor Hojtsy: Config schema issues in config tests themselves

parent 827b39b4
......@@ -66,7 +66,17 @@ public function onConfigSave(ConfigCrudEvent $event) {
$name = $saved_config->getName();
$data = $saved_config->get();
$checksum = crc32(serialize($data));
if (!isset($this->checked[$name . ':' . $checksum])) {
$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])) {
$this->checked[$name . ':' . $checksum] = TRUE;
$errors = $this->checkConfigSchema($this->typedManager, $name, $data);
if ($errors === FALSE) {
......
......@@ -23,6 +23,15 @@
*/
class ConfigCRUDTest extends KernelTestBase {
/**
* Exempt from strict schema checking.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = FALSE;
/**
* Modules to enable.
*
......@@ -178,7 +187,7 @@ function testNameValidation() {
$config->save();
$this->pass($message);
}
catch (\Exception $e) {
catch (ConfigNameException $e) {
$this->fail($message);
}
......
......@@ -16,6 +16,15 @@
*/
class ConfigDependencyTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......
......@@ -11,6 +11,15 @@
*/
class ConfigEntityNormalizeTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
public static $modules = array('config_test');
protected function setUp() {
......
......@@ -18,6 +18,15 @@
*/
class ConfigEventsTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......
......@@ -16,6 +16,16 @@
* @group config
*/
class ConfigFileContentTest extends KernelTestBase {
/**
* Exempt from strict schema checking.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = FALSE;
/**
* Tests setting, writing, and reading of a configuration setting.
*/
......
......@@ -22,6 +22,15 @@
*/
class ConfigImportRenameValidationTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Config Importer object used for testing.
*
......
......@@ -16,6 +16,16 @@
* @see \Drupal\Core\Config\ConfigInstaller
*/
class ConfigInstallTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
protected function setUp() {
parent::setUp();
......
......@@ -17,6 +17,15 @@
*/
class ConfigLanguageOverrideTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......
......@@ -16,6 +16,15 @@
*/
class ConfigOverrideTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......
......@@ -20,6 +20,15 @@
*/
class ConfigSchemaTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......
......@@ -17,6 +17,16 @@
* @group config
*/
class SchemaCheckTraitTest extends KernelTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
use SchemaCheckTrait;
/**
......
......@@ -35,12 +35,12 @@ public function testConfigSchemaChecker() {
// Test a non-existing schema.
$message = 'Expected SchemaIncompleteException thrown';
try {
\Drupal::config('config_schema_test.noschema')->set('foo', 'bar')->save();
\Drupal::config('config_schema_test.schemaless')->set('foo', 'bar')->save();
$this->fail($message);
}
catch (SchemaIncompleteException $e) {
$this->pass($message);
$this->assertEqual('No schema for config_schema_test.noschema', $e->getMessage());
$this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
}
// Test a valid schema.
......
......@@ -36,12 +36,12 @@ public function testConfigSchemaChecker() {
// Test a non-existing schema.
$msg = 'Expected SchemaIncompleteException thrown';
try {
\Drupal::config('config_schema_test.noschema')->set('foo', 'bar')->save();
\Drupal::config('config_schema_test.schemaless')->set('foo', 'bar')->save();
$this->fail($msg);
}
catch (SchemaIncompleteException $e) {
$this->pass($msg);
$this->assertEqual('No schema for config_schema_test.noschema', $e->getMessage());
$this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
}
// Test a valid schema.
......@@ -71,7 +71,7 @@ public function testConfigSchemaChecker() {
// Test that the config event listener is working in the child site.
$this->drupalGet('config_test/schema_listener');
$this->assertText('No schema for config_schema_test.noschema');
$this->assertText('No schema for config_schema_test.schemaless');
}
}
config_collection_install_test.test:
type: mapping
label: 'Collection test'
mapping:
collection:
type: string
label: 'Collection'
config_events_test.test:
type: mapping
label: 'Configuration events test'
mapping:
key:
type: string
label: 'Value'
......@@ -105,6 +105,44 @@ config_test.system:
foo:
type: string
label: 'Foo'
baz:
type: string
label: 'Baz'
'404':
type: string
label: '404'
config_test.new:
type: mapping
label: 'Configuration test'
mapping:
key:
type: string
label: 'Test setting'
new_key:
type: string
label: 'Test setting'
uuid:
type: string
label: 'UUID'
config_test.old:
type: config_test.new
config_test.foo:
type: mapping
label: 'Configuration test'
mapping:
value:
type: mapping
label: 'Value'
mapping:
key:
type: string
label: 'Key'
label:
type: label
label: 'Label'
config_test.bar:
type: config_test.foo
......@@ -43,6 +43,6 @@ class ConfigQueryTest extends ConfigTest {
*
* @var array
*/
public $array;
public $array = array();
}
......@@ -20,7 +20,7 @@ class SchemaListenerController extends ControllerBase {
*/
public function test() {
try {
$this->config('config_schema_test.noschema')->set('foo', 'bar')->save();
$this->config('config_schema_test.schemaless')->set('foo', 'bar')->save();
}
catch (SchemaIncompleteException $e) {
return [
......
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