DefaultConfigTest.php

Same filename in this branch
  1. 9 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
  2. 9 core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php
Same filename in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/DefaultConfigTest.php
  3. 8.9.x core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php
  4. 10 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
  5. 10 core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php
  6. 11.x core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
  7. 11.x core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php

Namespace

Drupal\KernelTests\Core\Config

File

core/tests/Drupal/KernelTests/Core/Config/DefaultConfigTest.php

View source
<?php

namespace Drupal\KernelTests\Core\Config;

use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\config_test\TestInstallStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Tests that default configuration provided by all modules matches schema.
 *
 * @group config
 */
class DefaultConfigTest extends KernelTestBase {
    use SchemaCheckTestTrait;
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'system',
        'config_test',
    ];
    
    /**
     * Config files to be ignored by this test.
     *
     * @var array
     */
    protected $toSkip = [
        // Skip files provided by the config_schema_test module since that module
        // is explicitly for testing schema.
'config_schema_test.ignore',
        'config_schema_test.noschema',
        'config_schema_test.plugin_types',
        'config_schema_test.someschema.somemodule.section_one.subsection',
        'config_schema_test.someschema.somemodule.section_two.subsection',
        'config_schema_test.someschema.with_parents',
        'config_schema_test.someschema',
        // Skip tour-test-legacy files as they intentionally have deprecated
        // properties.
'tour.tour.tour-test-legacy',
        'tour.tour.tour-test-legacy-location',
    ];
    
    /**
     * {@inheritdoc}
     */
    public function register(ContainerBuilder $container) {
        parent::register($container);
        $container->register('default_config_test.schema_storage')
            ->setClass('\\Drupal\\config_test\\TestInstallStorage')
            ->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY);
        $definition = $container->getDefinition('config.typed');
        $definition->replaceArgument(1, new Reference('default_config_test.schema_storage'));
    }
    
    /**
     * Tests default configuration data type.
     */
    public function testDefaultConfig() {
        $typed_config = \Drupal::service('config.typed');
        // Create a configuration storage with access to default configuration in
        // every module, profile and theme.
        $default_config_storage = new TestInstallStorage();
        foreach ($default_config_storage->listAll() as $config_name) {
            if (in_array($config_name, $this->toSkip)) {
                continue;
            }
            $data = $default_config_storage->read($config_name);
            $this->assertConfigSchema($typed_config, $config_name, $data);
        }
    }

}

Classes

Title Deprecated Summary
DefaultConfigTest Tests that default configuration provided by all modules matches schema.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.