Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / DefaultConfigTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Config;
4
5 use Drupal\Tests\SchemaCheckTestTrait;
6 use Drupal\config_test\TestInstallStorage;
7 use Drupal\Core\Config\InstallStorage;
8 use Drupal\Core\DependencyInjection\ContainerBuilder;
9 use Drupal\KernelTests\KernelTestBase;
10 use Symfony\Component\DependencyInjection\Reference;
11
12 /**
13  * Tests that default configuration provided by all modules matches schema.
14  *
15  * @group config
16  */
17 class DefaultConfigTest extends KernelTestBase {
18
19   use SchemaCheckTestTrait;
20
21   /**
22    * Modules to enable.
23    *
24    * @var array
25    */
26   public static $modules = ['system', 'config_test'];
27
28   /**
29    * Themes which provide default configuration and need enabling.
30    *
31    * If a theme provides default configuration but does not have a schema
32    * because it can rely on schemas added by system_config_schema_info_alter()
33    * then this test needs to enable it.
34    *
35    * @var array
36    */
37   protected $themes = ['seven'];
38
39   protected function setUp() {
40     parent::setUp();
41     \Drupal::service('theme_handler')->install($this->themes);
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function register(ContainerBuilder $container) {
48     parent::register($container);
49     $container->register('default_config_test.schema_storage')
50       ->setClass('\Drupal\config_test\TestInstallStorage')
51       ->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY);
52
53     $definition = $container->getDefinition('config.typed');
54     $definition->replaceArgument(1, new Reference('default_config_test.schema_storage'));
55   }
56
57   /**
58    * Tests default configuration data type.
59    */
60   public function testDefaultConfig() {
61     $typed_config = \Drupal::service('config.typed');
62     // Create a configuration storage with access to default configuration in
63     // every module, profile and theme.
64     $default_config_storage = new TestInstallStorage();
65
66     foreach ($default_config_storage->listAll() as $config_name) {
67       // Skip files provided by the config_schema_test module since that module
68       // is explicitly for testing schema.
69       if (strpos($config_name, 'config_schema_test') === 0) {
70         continue;
71       }
72
73       $data = $default_config_storage->read($config_name);
74       $this->assertConfigSchema($typed_config, $config_name, $data);
75     }
76   }
77
78 }