Commit 68b8b52f authored by catch's avatar catch

Issue #2925689 by alexpott: ConfigValidation class contains code that is...

Issue #2925689 by alexpott: ConfigValidation class contains code that is brittle and changing for every addition
parent 9286bb49
......@@ -74,8 +74,11 @@ public static function validateGiraffes($string, ExecutionContextInterface $cont
* The validation execution context.
*/
public static function validateMapping($mapping, ExecutionContextInterface $context) {
if ($diff = array_diff(array_keys($mapping), ['llama', 'cat', 'giraffe', 'uuid', '_core'])) {
$context->addViolation('Missing giraffe.');
// Ensure we are validating the entire mapping by diffing against all the
// keys.
$mapping_schema = \Drupal::service('config.typed')->get('config_test.validation')->getValue();
if ($diff = array_diff_key($mapping, $mapping_schema)) {
$context->addViolation('Unexpected keys: ' . implode(', ', array_keys($diff)));
}
}
......
......@@ -155,11 +155,12 @@ public function testSimpleConfigValidation() {
$value = $typed_config->getValue();
unset($value['giraffe']);
$value['elephant'] = 'foo';
$value['zebra'] = 'foo';
$typed_config->setValue($value);
$result = $typed_config->validate();
$this->assertCount(1, $result);
$this->assertEquals('', $result->get(0)->getPropertyPath());
$this->assertEquals('Missing giraffe.', $result->get(0)->getMessage());
$this->assertEquals('Unexpected keys: elephant, zebra', $result->get(0)->getMessage());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment