Verified Commit b90b2e30 authored by Dave Long's avatar Dave Long
Browse files

Issue #3376794 by Wim Leers, borisson_: `type: mapping` should use `ValidKeys:...

Issue #3376794 by Wim Leers, borisson_: `type: mapping` should use `ValidKeys: <infer>` constraint by default
parent 9057fa1c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ mapping:
  label: Mapping
  class: '\Drupal\Core\Config\Schema\Mapping'
  definition_class: '\Drupal\Core\TypedData\MapDataDefinition'
  mapping: {}
  constraints:
    # By default, only allow the explicitly listed mapping keys.
    ValidKeys: '<infer>'
sequence:
  label: Sequence
  class: '\Drupal\Core\Config\Schema\Sequence'
+1 −1
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ public function testBlockMigration() {
    // Check migrate messages.
    $messages = iterator_to_array($this->getMigration('d6_block')->getIdMap()->getMessages());
    $this->assertCount(2, $messages);
    $this->assertSame($messages[1]->message, 'Schema errors for block.block.aggregator with the following errors: block.block.aggregator:settings.block_count missing schema, block.block.aggregator:settings.feed missing schema');
    $this->assertSame($messages[1]->message, 'Schema errors for block.block.aggregator with the following errors: block.block.aggregator:settings.block_count missing schema, block.block.aggregator:settings.feed missing schema, 0 [settings] &#039;block_count&#039; is not a supported key., 1 [settings] &#039;feed&#039; is not a supported key.');
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public function testConfigSchemaChecker() {
      $this->fail('Expected SchemaIncompleteException thrown');
    }
    catch (SchemaIncompleteException $e) {
      $this->assertEquals('Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence, config_test.types:foo missing schema', $e->getMessage());
      $this->assertEquals("Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence, config_test.types:foo missing schema, 0 [] &#039;foo&#039; is not a supported key.", $e->getMessage());
    }

    // Test that the config event listener is working in the child site.
+14 −3
Original line number Diff line number Diff line
@@ -181,9 +181,20 @@ public function testSimpleConfigValidation() {
    $value['zebra'] = 'foo';
    $typed_config->setValue($value);
    $result = $typed_config->validate();
    $this->assertCount(1, $result);
    $this->assertEquals('', $result->get(0)->getPropertyPath());
    $this->assertEquals('Unexpected keys: elephant, zebra', $result->get(0)->getMessage());
    $this->assertCount(3, $result);
    // 2 constraint violations triggered by the default validation constraint
    // for `type: mapping`
    // @see \Drupal\Core\Validation\Plugin\Validation\Constraint\ValidKeysConstraint
    $this->assertSame('', $result->get(0)->getPropertyPath());
    $this->assertEquals("'elephant' is not a supported key.", $result->get(0)->getMessage());
    $this->assertSame('', $result->get(1)->getPropertyPath());
    $this->assertEquals("'zebra' is not a supported key.", $result->get(1)->getMessage());
    // 1 additional constraint violation triggered by the custom
    // constraint for the `config_test.validation` type, which indirectly
    // extends `type: mapping` (via `type: config_object`).
    // @see \Drupal\config_test\ConfigValidation::validateMapping()
    $this->assertEquals('', $result->get(2)->getPropertyPath());
    $this->assertEquals('Unexpected keys: elephant, zebra', $result->get(2)->getMessage());
  }

}
+8 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public function testSchemaMapping() {
    $expected['type'] = 'config_schema_test.someschema';
    $expected['definition_class'] = '\Drupal\Core\TypedData\MapDataDefinition';
    $expected['unwrap_for_canonical_representation'] = TRUE;
    $expected['constraints'] = ['ValidKeys' => '<infer>'];
    $this->assertEquals($expected, $definition, 'Retrieved the right metadata for configuration with only some schema.');

    // Check type detection on elements with undefined types.
@@ -120,6 +121,7 @@ public function testSchemaMapping() {
    $expected['type'] = 'system.maintenance';
    $expected['definition_class'] = '\Drupal\Core\TypedData\MapDataDefinition';
    $expected['unwrap_for_canonical_representation'] = TRUE;
    $expected['constraints'] = ['ValidKeys' => '<infer>'];
    $this->assertEquals($expected, $definition, 'Retrieved the right metadata for system.maintenance');

    // Mixed schema with ignore elements.
@@ -150,6 +152,7 @@ public function testSchemaMapping() {
    ];
    $expected['type'] = 'config_schema_test.ignore';
    $expected['unwrap_for_canonical_representation'] = TRUE;
    $expected['constraints'] = ['ValidKeys' => '<infer>'];

    $this->assertEquals($expected, $definition);

@@ -194,6 +197,7 @@ public function testSchemaMapping() {
    $expected['mapping']['third_party_settings']['sequence']['type'] = '[%parent.%parent.%type].third_party.[%key]';
    $expected['mapping']['_core']['type'] = '_core_config_info';
    $expected['type'] = 'image.style.*';
    $expected['constraints'] = ['ValidKeys' => '<infer>'];

    $this->assertEquals($expected, $definition);

@@ -212,6 +216,7 @@ public function testSchemaMapping() {
    $expected['mapping']['upscale']['type'] = 'boolean';
    $expected['mapping']['upscale']['label'] = 'Upscale';
    $expected['type'] = 'image.effect.image_scale';
    $expected['constraints'] = ['ValidKeys' => '<infer>'];

    $this->assertEquals($expected, $definition, 'Retrieved the right metadata for image.effect.image_scale');

@@ -235,6 +240,7 @@ public function testSchemaMapping() {
      'integer' => ['type' => 'integer'],
      'string' => ['type' => 'string'],
    ];
    $expected['constraints'] = ['ValidKeys' => '<infer>'];
    $this->assertEquals($expected, $definition, 'Retrieved the right metadata for config_test.dynamic.third_party:third_party_settings.config_schema_test');

    // More complex, several level deep test.
@@ -252,6 +258,7 @@ public function testSchemaMapping() {
    $expected['type'] = 'config_schema_test.someschema.somemodule.*.*';
    $expected['definition_class'] = '\Drupal\Core\TypedData\MapDataDefinition';
    $expected['unwrap_for_canonical_representation'] = TRUE;
    $expected['constraints'] = ['ValidKeys' => '<infer>'];

    $this->assertEquals($expected, $definition, 'Retrieved the right metadata for config_schema_test.someschema.somemodule.section_one.subsection');

@@ -520,6 +527,7 @@ public function testSchemaFallback() {
    $expected['mapping']['testdescription']['type'] = 'text';
    $expected['mapping']['testdescription']['label'] = 'Description';
    $expected['type'] = 'config_schema_test.wildcard_fallback.*';
    $expected['constraints'] = ['ValidKeys' => '<infer>'];

    $this->assertEquals($expected, $definition, 'Retrieved the right metadata for config_schema_test.wildcard_fallback.something');

Loading