function ConfigModuleOverridesTest::testSimpleModuleOverrides

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigModuleOverridesTest.php \Drupal\KernelTests\Core\Config\ConfigModuleOverridesTest::testSimpleModuleOverrides()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigModuleOverridesTest.php \Drupal\KernelTests\Core\Config\ConfigModuleOverridesTest::testSimpleModuleOverrides()
  3. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigModuleOverridesTest.php \Drupal\KernelTests\Core\Config\ConfigModuleOverridesTest::testSimpleModuleOverrides()

File

core/tests/Drupal/KernelTests/Core/Config/ConfigModuleOverridesTest.php, line 21

Class

ConfigModuleOverridesTest
Tests module overrides of configuration using event subscribers.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSimpleModuleOverrides() : void {
    $GLOBALS['config_test_run_module_overrides'] = TRUE;
    $name = 'system.site';
    $overridden_name = 'Wow overridden site name';
    $non_overridden_name = 'Wow this name is on disk mkay';
    $overridden_slogan = 'Yay for overrides!';
    $non_overridden_slogan = 'Yay for defaults!';
    $config_factory = $this->container
        ->get('config.factory');
    $config_factory->getEditable($name)
        ->set('name', $non_overridden_name)
        ->set('slogan', $non_overridden_slogan)
        ->set('langcode', 'en')
        ->save();
    $this->assertEquals($non_overridden_name, $config_factory->get('system.site')
        ->getOriginal('name', FALSE));
    $this->assertEquals($non_overridden_slogan, $config_factory->get('system.site')
        ->getOriginal('slogan', FALSE));
    $this->assertEquals($overridden_name, $config_factory->get('system.site')
        ->get('name'));
    $this->assertEquals($overridden_slogan, $config_factory->get('system.site')
        ->get('slogan'));
    // Test overrides of completely new configuration objects. In normal runtime
    // this should only happen for configuration entities as we should not be
    // creating simple configuration objects on the fly.
    $config = $config_factory->get('config_override_test.new');
    $this->assertTrue($config->isNew(), 'The configuration object config_override_test.new is new');
    $this->assertSame('override', $config->get('module'));
    $this->assertNull($config->getOriginal('module', FALSE));
    unset($GLOBALS['config_test_run_module_overrides']);
}

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