1 config.test | public ConfigurationTest::testExistingConfig() |
Tests reading existing config files provided by a module.
File
- core/
modules/ config/ tests/ config.test, line 38 - Tests for Configuration module.
Class
- ConfigurationTest
- Tests reading and writing file contents.
Code
public function testExistingConfig() {
// Get a list of all configuration files by prefix. Note that even doing
// this check also checks that the configuration provided by a module has
// been moved into the "active" storage directory when the module was
// installed.
$config_names = config_get_names_with_prefix('config_test.group', 'active');
$expected_names = array(
'config_test.group.item_1',
'config_test.group.item_2',
);
$this->assertEqual($config_names, $expected_names, 'Existing configuration files found by their prefixes.');
// Attempt to save a configuration without a name key.
$item_config = config('config_test.group.item_1');
try {
$item_config->validateData();
$this->pass('Configuration data validated successfully.');
}
catch (ConfigValidateException $e) {
$this->fail('Configuration data unexpectedly failed with the Exception message: ' . $e->getMessage());
}
// Attempt to save a configuration without a name key.
$item_name = $item_config->get('name');
$item_config->clear('name');
try {
$item_config->validateData();
$this->fail('Configuration data validated unexpectedly when a ConfigValidateException should have been thrown.');
}
catch (ConfigValidateException $e) {
$this->pass('Configuration data validation properly threw a ConfigValidateException when the name was removed.');
}
$item_config->set('name', $item_name);
// Attempt to save a configuration without a label key.
$item_label = $item_config->get('label');
$item_config->clear('label');
try {
$item_config->validateData();
$this->fail('Configuration data validated unexpectedly when a ConfigValidateException should have been thrown.');
}
catch (ConfigValidateException $e) {
$this->pass('Configuration data validation properly threw a ConfigValidateException when the label was removed.');
}
$item_config->set('label', $item_label);
// Get an individual configuration.
$config = config('config_test.simple');
$expected_config = array(
'favorite_animal' => 'cats',
'favorite_color' => 'blue',
);
// Test both paths.
$this->assertEqual($config->get(), $expected_config, 'The configuration file via Config::get() contained the expected configuration.');
$this->assertEqual($config->getData(), $expected_config, 'The configuration file via Config::getData() contained the expected configuration.');
}