function ConfigSchemaTest::testConfigSchemaInfoAlter
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testConfigSchemaInfoAlter()
- 10 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testConfigSchemaInfoAlter()
- 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testConfigSchemaInfoAlter()
Tests hook_config_schema_info_alter().
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigSchemaTest.php, line 554
Class
- ConfigSchemaTest
- Tests schema for configuration objects.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testConfigSchemaInfoAlter() {
/** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
$typed_config = \Drupal::service('config.typed');
$typed_config->clearCachedDefinitions();
// Ensure that keys can not be added or removed by
// hook_config_schema_info_alter().
\Drupal::state()->set('config_schema_test_exception_remove', TRUE);
try {
$typed_config->getDefinitions();
$this->fail('Expected ConfigSchemaAlterException thrown.');
} catch (ConfigSchemaAlterException $e) {
$this->assertEqual($e->getMessage(), 'Invoking hook_config_schema_info_alter() has removed (config_schema_test.hook) schema definitions');
}
\Drupal::state()->set('config_schema_test_exception_add', TRUE);
try {
$typed_config->getDefinitions();
$this->fail('Expected ConfigSchemaAlterException thrown.');
} catch (ConfigSchemaAlterException $e) {
$this->assertEqual($e->getMessage(), 'Invoking hook_config_schema_info_alter() has added (config_schema_test.hook_added_definition) and removed (config_schema_test.hook) schema definitions');
}
\Drupal::state()->set('config_schema_test_exception_remove', FALSE);
try {
$typed_config->getDefinitions();
$this->fail('Expected ConfigSchemaAlterException thrown.');
} catch (ConfigSchemaAlterException $e) {
$this->assertEqual($e->getMessage(), 'Invoking hook_config_schema_info_alter() has added (config_schema_test.hook_added_definition) schema definitions');
}
// Tests that hook_config_schema_info_alter() can add additional metadata to
// existing configuration schema.
\Drupal::state()->set('config_schema_test_exception_add', FALSE);
$definitions = $typed_config->getDefinitions();
$this->assertEqual($definitions['config_schema_test.hook']['additional_metadata'], 'new schema info');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.