function ConfigSchemaTest::testConfigSchemaInfoAlter
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php \Drupal\KernelTests\Core\Config\ConfigSchemaTest::testConfigSchemaInfoAlter()
- 8.9.x 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 634
Class
- ConfigSchemaTest
- Tests schema for configuration objects.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testConfigSchemaInfoAlter() : void {
/** @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->assertEquals('Invoking hook_config_schema_info_alter() has removed (config_schema_test.hook) schema definitions', $e->getMessage());
}
\Drupal::state()->set('config_schema_test_exception_add', TRUE);
try {
$typed_config->getDefinitions();
$this->fail('Expected ConfigSchemaAlterException thrown.');
} catch (ConfigSchemaAlterException $e) {
$this->assertEquals('Invoking hook_config_schema_info_alter() has added (config_schema_test.hook_added_definition) and removed (config_schema_test.hook) schema definitions', $e->getMessage());
}
\Drupal::state()->set('config_schema_test_exception_remove', FALSE);
try {
$typed_config->getDefinitions();
$this->fail('Expected ConfigSchemaAlterException thrown.');
} catch (ConfigSchemaAlterException $e) {
$this->assertEquals('Invoking hook_config_schema_info_alter() has added (config_schema_test.hook_added_definition) schema definitions', $e->getMessage());
}
// 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->assertEquals('new schema info', $definitions['config_schema_test.hook']['additional_metadata']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.