public function ConfigTest::testOverrideData in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testOverrideData()
- 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testOverrideData()
@covers ::setModuleOverride @covers ::setSettingsOverride @covers ::getOriginal @covers ::hasOverrides @dataProvider overrideDataProvider
File
- core/
tests/ Drupal/ Tests/ Core/ Config/ ConfigTest.php, line 179
Class
- ConfigTest
- Tests the Config.
Namespace
Drupal\Tests\Core\ConfigCode
public function testOverrideData($data, $module_data, $setting_data) {
// Set initial data.
$this->config
->setData($data);
// Check original data was set correctly.
$this
->assertConfigDataEquals($data);
// Save so that the original data is stored.
$this->config
->save();
$this
->assertFalse($this->config
->hasOverrides());
$this
->assertOverriddenKeys($data, []);
// Set module override data and check value before and after save.
$this->config
->setModuleOverride($module_data);
$this
->assertConfigDataEquals($module_data);
$this
->assertOverriddenKeys($data, $module_data);
$this->config
->save();
$this
->assertConfigDataEquals($module_data);
$this
->assertOverriddenKeys($data, $module_data);
// Reset the module overrides.
$this->config
->setModuleOverride([]);
$this
->assertOverriddenKeys($data, []);
// Set setting override data and check value before and after save.
$this->config
->setSettingsOverride($setting_data);
$this
->assertConfigDataEquals($setting_data);
$this
->assertOverriddenKeys($data, $setting_data);
$this->config
->save();
$this
->assertConfigDataEquals($setting_data);
$this
->assertOverriddenKeys($data, $setting_data);
// Set module overrides again to ensure override order is correct.
$this->config
->setModuleOverride($module_data);
$merged_overrides = array_merge($module_data, $setting_data);
// Setting data should be overriding module data.
$this
->assertConfigDataEquals($setting_data);
$this
->assertOverriddenKeys($data, $merged_overrides);
$this->config
->save();
$this
->assertConfigDataEquals($setting_data);
$this
->assertOverriddenKeys($data, $merged_overrides);
// Check original data has not changed.
$this
->assertOriginalConfigDataEquals($data, FALSE);
// Check setting overrides are returned with $apply_overrides = TRUE.
$this
->assertOriginalConfigDataEquals($setting_data, TRUE);
// Check that $apply_overrides defaults to TRUE.
foreach ($setting_data as $key => $value) {
$config_value = $this->config
->getOriginal($key);
$this
->assertEquals($value, $config_value);
}
// Check that the overrides can be completely reset.
$this->config
->setModuleOverride([]);
$this->config
->setSettingsOverride([]);
$this
->assertConfigDataEquals($data);
$this
->assertOverriddenKeys($data, []);
$this->config
->save();
$this
->assertConfigDataEquals($data);
$this
->assertOverriddenKeys($data, []);
}