Version 1
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / SchemaCheckTraitTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Config;
4
5 use Drupal\Core\Config\Schema\SchemaCheckTrait;
6 use Drupal\KernelTests\KernelTestBase;
7
8
9 /**
10  * Tests the functionality of SchemaCheckTrait.
11  *
12  * @group config
13  */
14 class SchemaCheckTraitTest extends KernelTestBase {
15
16   use SchemaCheckTrait;
17
18   /**
19    * The typed config manager.
20    *
21    * @var \Drupal\Core\Config\TypedConfigManagerInterface
22    */
23   protected $typedConfig;
24
25   /**
26    * Modules to enable.
27    *
28    * @var array
29    */
30   public static $modules = ['config_test', 'config_schema_test'];
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function setUp() {
36     parent::setUp();
37     $this->installConfig(['config_test', 'config_schema_test']);
38     $this->typedConfig = \Drupal::service('config.typed');
39   }
40
41   /**
42    * Tests \Drupal\Core\Config\Schema\SchemaCheckTrait.
43    */
44   public function testTrait() {
45     // Test a non existing schema.
46     $ret = $this->checkConfigSchema($this->typedConfig, 'config_schema_test.noschema', $this->config('config_schema_test.noschema')->get());
47     $this->assertIdentical($ret, FALSE);
48
49     // Test an existing schema with valid data.
50     $config_data = $this->config('config_test.types')->get();
51     $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
52     $this->assertIdentical($ret, TRUE);
53
54     // Add a new key, a new array and overwrite boolean with array to test the
55     // error messages.
56     $config_data = ['new_key' => 'new_value', 'new_array' => []] + $config_data;
57     $config_data['boolean'] = [];
58     $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
59     $expected = [
60       'config_test.types:new_key' => 'missing schema',
61       'config_test.types:new_array' => 'missing schema',
62       'config_test.types:boolean' => 'non-scalar value but not defined as an array (such as mapping or sequence)',
63     ];
64     $this->assertEqual($ret, $expected);
65   }
66
67 }