e2cc00cf4ddd397746b9ad2c2fafdcbbe7d9a20d
[yaffs-website] / web / core / tests / Drupal / Tests / Traits / Core / Config / SchemaConfigListenerTestTrait.php
1 <?php
2
3 namespace Drupal\Tests\Traits\Core\Config;
4
5 use \Drupal\Core\Config\Schema\SchemaIncompleteException;
6
7 /**
8  * Adds a test for the configuration schema checker use in tests.
9  */
10 trait SchemaConfigListenerTestTrait {
11
12   /**
13    * Tests \Drupal\Core\Config\Development\ConfigSchemaChecker.
14    */
15   public function testConfigSchemaChecker() {
16     // Test a non-existing schema.
17     $message = 'Expected SchemaIncompleteException thrown';
18     try {
19       $this->config('config_schema_test.schemaless')->set('foo', 'bar')->save();
20       $this->fail($message);
21     }
22     catch (SchemaIncompleteException $e) {
23       $this->pass($message);
24       $this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
25     }
26
27     // Test a valid schema.
28     $message = 'Unexpected SchemaIncompleteException thrown';
29     $config = $this->config('config_test.types')->set('int', 10);
30     try {
31       $config->save();
32       $this->pass($message);
33     }
34     catch (SchemaIncompleteException $e) {
35       $this->fail($message);
36     }
37
38     // Test an invalid schema.
39     $message = 'Expected SchemaIncompleteException thrown';
40     $config = $this->config('config_test.types')
41       ->set('foo', 'bar')
42       ->set('array', 1);
43     try {
44       $config->save();
45       $this->fail($message);
46     }
47     catch (SchemaIncompleteException $e) {
48       $this->pass($message);
49       $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());
50     }
51
52   }
53
54 }