You are here

public function ConfigModuleOverridesTest::testSimpleModuleOverrides in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigModuleOverridesTest.php \Drupal\config\Tests\ConfigModuleOverridesTest::testSimpleModuleOverrides()

File

core/modules/config/src/Tests/ConfigModuleOverridesTest.php, line 26
Contains \Drupal\config\Tests\ConfigModuleOverridesTest.

Class

ConfigModuleOverridesTest
Tests module overrides of configuration using event subscribers.

Namespace

Drupal\config\Tests

Code

public function testSimpleModuleOverrides() {
  $GLOBALS['config_test_run_module_overrides'] = TRUE;
  $name = 'system.site';
  $overridden_name = 'ZOMG overridden site name';
  $non_overridden_name = 'ZOMG 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)
    ->save();
  $this
    ->assertEqual($non_overridden_name, $config_factory
    ->get('system.site')
    ->getOriginal('name', FALSE));
  $this
    ->assertEqual($non_overridden_slogan, $config_factory
    ->get('system.site')
    ->getOriginal('slogan', FALSE));
  $this
    ->assertEqual($overridden_name, $config_factory
    ->get('system.site')
    ->get('name'));
  $this
    ->assertEqual($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
    ->assertIdentical($config
    ->get('module'), 'override');
  $this
    ->assertIdentical($config
    ->getOriginal('module', FALSE), NULL);
  unset($GLOBALS['config_test_run_module_overrides']);
}