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