diff --git a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php index f9c8470..b43c6a7 100644 --- a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php +++ b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php @@ -83,7 +83,7 @@ protected function checkValue($key, $value) { } catch (SchemaIncompleteException $e) { if (is_scalar($value) || $value === NULL) { - return array($error_key => 'Missing schema.'); + return array($error_key => 'Missing schema'); } } // Do not check value if it is defined to be ignored. diff --git a/core/modules/config/src/Tests/SchemaCheckTraitTest.php b/core/modules/config/src/Tests/SchemaCheckTraitTest.php new file mode 100644 index 0000000..3b5793a --- /dev/null +++ b/core/modules/config/src/Tests/SchemaCheckTraitTest.php @@ -0,0 +1,77 @@ + 'SchemaCheckTrait test', + 'description' => 'Tests the functionality of SchemaCheckTrait.', + 'group' => 'Configuration', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $this->installConfig(array('config_test', 'config_schema_test')); + $this->typedConfig = \Drupal::service('config.typed'); + } + + /** + * Tests \Drupal\Core\Config\Schema\SchemaCheckTrait. + */ + public function testTrait() { + // Test a non existing schema. + $ret = $this->checkConfigSchema($this->typedConfig, 'config_schema_test.noschema', \Drupal::config('config_schema_test.noschema')->get()); + $this->assertIdentical($ret, FALSE); + + // Test an existing schema with valid data. + $config_data = \Drupal::config('config_test.types')->get(); + $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data); + $this->assertIdentical($ret, TRUE); + + // Add a new key and new array to test the error messages. + $config_data = array('new_key' => 'new_value', 'new_array' => array()) + $config_data; + $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data); + $expected = array( + 'config_test.types:new_key' => 'Missing schema', + 'config_test.types:new_array' => 'Non-scalar value but not defined as an array (such as mapping or sequence)', + ); + $this->assertIdentical($ret, $expected); + } + +}