diff --git a/core/lib/Drupal/Core/Config/ConfigNameException.php b/core/lib/Drupal/Core/Config/ConfigNameException.php new file mode 100644 index 0000000..f02f227 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigNameException.php @@ -0,0 +1,12 @@ +assertIdentical($new_config->get('404'), $expected_values['404']); } + /** + * Tests the validation of configuration object names. + */ + function testNameValidation() { + // Try to save an object name with no namespace. + $name = 'nonamespace'; + $message = 'Expected ConfigNameException was thrown for a name without a namespace.'; + try { + $config = config($name); + $config->save(); + $this->fail($message); + } + catch (ConfigException $e) { + $this->pass($message); + } + + // Try to save an object with a name longer than 250 characters. + $name = 'config_test.herman_melville.moby_dick_or_the_whale.harper_1851.now_small_fowls_flew_screaming_over_the_yet_yawning_gulf_a_sullen_white_surf_beat_against_its_steep_sides_then_all_collapsed_and_the_great_shroud_of_the_sea_rolled_on_as_it_rolled_five_thousand_years_ago'; + $message = 'Expected ConfigNameException was thrown for a name longer than Config::MAX_NAME_LENGTH.'; + try { + $config = config($name); + $config->save(); + $this->fail($message); + } + catch (ConfigNameException $e) { + $this->pass($message); + } + + // Try to save a valid object name. + $name = 'config.namespace'; + $message = 'ConfigNameException was not thrown for a valid object name.'; + try { + $config = config($name); + $config->save(); + $this->pass($message); + } + catch (ConfigException $e) { + $this->fail($message); + } + } + }