3 namespace Drupal\Tests\Traits\Core\Config;
5 use Drupal\Core\Config\Schema\SchemaIncompleteException;
8 * Adds a test for the configuration schema checker use in tests.
10 trait SchemaConfigListenerTestTrait {
13 * Tests \Drupal\Core\Config\Development\ConfigSchemaChecker.
15 public function testConfigSchemaChecker() {
16 // Test a non-existing schema.
17 $message = 'Expected SchemaIncompleteException thrown';
19 $this->config('config_schema_test.schemaless')->set('foo', 'bar')->save();
20 $this->fail($message);
22 catch (SchemaIncompleteException $e) {
23 $this->pass($message);
24 $this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
27 // Test a valid schema.
28 $message = 'Unexpected SchemaIncompleteException thrown';
29 $config = $this->config('config_test.types')->set('int', 10);
32 $this->pass($message);
34 catch (SchemaIncompleteException $e) {
35 $this->fail($message);
38 // Test a valid schema, where the value is accessed before saving. Ensures
39 // that overridden data is correctly reset after casting.
40 $message = 'Unexpected SchemaIncompleteException thrown';
41 $config = $this->config('config_test.types')->set('int', '10');
45 $this->pass($message);
47 catch (SchemaIncompleteException $e) {
48 $this->fail($message);
51 // Test an invalid schema.
52 $message = 'Expected SchemaIncompleteException thrown';
53 $config = $this->config('config_test.types')
58 $this->fail($message);
60 catch (SchemaIncompleteException $e) {
61 $this->pass($message);
62 $this->assertEqual('Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence, config_test.types:foo missing schema', $e->getMessage());