From c98b2fdca0921426f479be8082429ec92ec2bd48 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 16 May 2014 12:49:42 -0500 Subject: [PATCH] =?UTF-8?q?Issue=20#2266501=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?vijaycs85,=20YesCT:=20Array=20level=20schema=20errors=20are=20n?= =?UTF-8?q?ot=20reported,=20fix=20wrong=20schemas=20identified.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/Tests/ConfigSchemaTestBase.php | 78 +++++++++---------- .../entity/config/schema/entity.schema.yml | 6 ++ .../image/config/schema/image.schema.yml | 23 ++++++ .../config/schema/update_test.schema.yml | 6 +- .../user/config/schema/user.schema.yml | 6 ++ .../views.argument_validator.schema.yml | 5 +- .../config/schema/views.cache.schema.yml | 29 ++++--- .../config/schema/views.data_types.schema.yml | 19 +++-- ...field.instance.node.article.field_tags.yml | 1 + 9 files changed, 109 insertions(+), 64 deletions(-) diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTestBase.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTestBase.php index 61eee7e9a3e6..b31551a0a7ca 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTestBase.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTestBase.php @@ -2,11 +2,12 @@ /** * @file - * Contains Drupal\config\Tests\DefaultConfigTest. + * Contains Drupal\config\Tests\ConfigSchemaTestBase. */ namespace Drupal\config\Tests; +use Drupal\Core\Config\Schema\ArrayElement; use Drupal\Core\Config\Schema\Property; use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\TypedData\Type\BooleanInterface; @@ -38,21 +39,12 @@ abstract class ConfigSchemaTestBase extends WebTestBase { protected $configName; /** + * Global state for whether the config has a valid schema. + * * @var boolean */ protected $configPass; - /** - * {@inheritdoc} - */ - public static function getInfo() { - return array( - 'name' => 'Default configuration', - 'description' => 'Tests that default configuration provided by all modules matches schema.', - 'group' => 'Configuration', - ); - } - /** * Asserts the TypedConfigManager has a valid schema for the configuration. * @@ -92,44 +84,46 @@ public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $c * Returns mixed value. */ protected function checkValue($key, $value) { + + try { + $element = $this->schema->get($key); + } + catch (SchemaIncompleteException $e) { + $this->fail("{$this->configName}:$key has no schema."); + } if (is_scalar($value) || $value === NULL) { - try { - $success = FALSE; - $type = gettype($value); - $element = $this->schema->get($key); - if ($element instanceof PrimitiveInterface) { - if ($type == 'integer' && $element instanceof IntegerInterface) { - $success = TRUE; - } - if ($type == 'double' && $element instanceof FloatInterface) { - $success = TRUE; - } - if ($type == 'boolean' && $element instanceof BooleanInterface) { - $success = TRUE; - } - if ($type == 'string' && ($element instanceof StringInterface || $element instanceof Property)) { - $success = TRUE; - } - // Null values are allowed for all types. - if ($value === NULL) { - $success = TRUE; - } + $success = FALSE; + $type = gettype($value); + if ($element instanceof PrimitiveInterface) { + if ($type == 'integer' && $element instanceof IntegerInterface) { + $success = TRUE; } - else { - // @todo throw an exception due to an incomplete schema. Only possible - // once https://drupal.org/node/1910624 is complete. + if ($type == 'double' && $element instanceof FloatInterface) { + $success = TRUE; } - $class = get_class($element); - if (!$success) { - $this->fail("{$this->configName}:$key has the wrong schema. Variable type is $type and schema class is $class."); + if ($type == 'boolean' && $element instanceof BooleanInterface) { + $success = TRUE; + } + if ($type == 'string' && ($element instanceof StringInterface || $element instanceof Property)) { + $success = TRUE; + } + // Null values are allowed for all scalar types. + if ($value === NULL) { + $success = TRUE; } } - catch (SchemaIncompleteException $e) { - $this->fail("{$this->configName}:$key has no schema."); + if (!$success) { + $class = get_class($element); + $this->fail("{$this->configName}:$key has the wrong schema. Variable type is $type and schema class is $class."); } } else { - // Any non-scalar value must be an array. + if (!$element instanceof ArrayElement) { + $this->fail("Non-scalar {$this->configName}:$key is not defined as an array type (such as mapping or sequence)."); + } + + // Go on processing so we can get errors on all levels. Any non-scalar + // value must be an array so cast to an array. if (!is_array($value)) { $value = (array) $value; } diff --git a/core/modules/entity/config/schema/entity.schema.yml b/core/modules/entity/config/schema/entity.schema.yml index a6c87f0b6a3d..0fc9af7cf045 100644 --- a/core/modules/entity/config/schema/entity.schema.yml +++ b/core/modules/entity/config/schema/entity.schema.yml @@ -127,6 +127,12 @@ entity.form_display.*.*.*: dependencies: type: config_dependencies label: 'Dependencies' + hidden: + type: sequence + label: 'Hidden' + sequence: + - type: boolean + label: 'Component' # Default schema for entity display field with undefined type. entity_view_display.field.*: diff --git a/core/modules/image/config/schema/image.schema.yml b/core/modules/image/config/schema/image.schema.yml index 7545c127d23b..5b642b356b55 100644 --- a/core/modules/image/config/schema/image.schema.yml +++ b/core/modules/image/config/schema/image.schema.yml @@ -126,6 +126,29 @@ field.image.instance_settings: type: field_default_image label: 'Default value' +field.image.value: + type: sequence + label: 'Default value' + sequence: + - type: mapping + label: 'Default image' + mapping: + fid: + type: integer + label: 'File ID' + alt: + type: string + label: 'Alternate text' + title: + type: string + label: 'Title text' + width: + type: integer + label: 'Width' + height: + type: integer + label: 'Height' + entity_view_display.field.image: type: entity_field_view_display_base label: 'Image field display format settings' diff --git a/core/modules/update/tests/modules/update_test/config/schema/update_test.schema.yml b/core/modules/update/tests/modules/update_test/config/schema/update_test.schema.yml index cbe32d43757c..2235f2b364f5 100644 --- a/core/modules/update/tests/modules/update_test/config/schema/update_test.schema.yml +++ b/core/modules/update/tests/modules/update_test/config/schema/update_test.schema.yml @@ -5,19 +5,19 @@ update_test.settings: label: 'Update test settings' mapping: system_info: - type: seqeuence + type: sequence label: 'System info' sequence: - type: string label: 'Value' update_status: - type: seqeuence + type: sequence label: 'Update status' sequence: - type: string label: 'Value' xml_map: - type: seqeuence + type: sequence label: 'XML map' sequence: - type: string diff --git a/core/modules/user/config/schema/user.schema.yml b/core/modules/user/config/schema/user.schema.yml index 7f6192162968..736170441d6a 100644 --- a/core/modules/user/config/schema/user.schema.yml +++ b/core/modules/user/config/schema/user.schema.yml @@ -171,3 +171,9 @@ action.configuration.user_remove_role_action: action.configuration.user_unblock_user_action: type: action_configuration_default label: 'Unblock the selected users configuration' + +search.plugin.user_search: + type: sequence + label: 'User search' + sequence: + - type: undefined diff --git a/core/modules/views/config/schema/views.argument_validator.schema.yml b/core/modules/views/config/schema/views.argument_validator.schema.yml index 3dbc9d7fe904..6e3cb4406d32 100644 --- a/core/modules/views/config/schema/views.argument_validator.schema.yml +++ b/core/modules/views/config/schema/views.argument_validator.schema.yml @@ -22,8 +22,11 @@ views.argument_validator_entity: type: mapping mapping: bundles: - type: boolean + type: sequence label: 'Bundles' + sequence: + - type: string + label: 'Bundle' access: type: boolean label: 'Access' diff --git a/core/modules/views/config/schema/views.cache.schema.yml b/core/modules/views/config/schema/views.cache.schema.yml index 1139df69e886..3e90332b79df 100644 --- a/core/modules/views/config/schema/views.cache.schema.yml +++ b/core/modules/views/config/schema/views.cache.schema.yml @@ -1,20 +1,29 @@ # Schema for the views cache. views.cache.none: - type: mapping - label: 'None' + type: views_cache + label: 'No caching' mapping: - type: - type: string - label: 'Cache type' + options: + type: sequence + label: 'Options' + sequence: + - type: undefined + +views.cache.tag: + type: views_cache + label: 'Tag based caching' + mapping: + options: + type: sequence + label: 'Options' + sequence: + - type: undefined views.cache.time: - type: mapping - label: 'None' + type: views_cache + label: 'Time based caching' mapping: - type: - type: string - label: 'Time-based' options: type: mapping label: 'Cache options' diff --git a/core/modules/views/config/schema/views.data_types.schema.yml b/core/modules/views/config/schema/views.data_types.schema.yml index f29da85be12b..ae143bb81975 100644 --- a/core/modules/views/config/schema/views.data_types.schema.yml +++ b/core/modules/views/config/schema/views.data_types.schema.yml @@ -54,14 +54,6 @@ views_display: label: 'Provider' cache: type: views.cache.[type] - label: 'Caching' - mapping: - type: - type: string - label: 'Cache type' - provider: - type: string - label: 'Provider' empty: type: sequence label: 'No results behavior' @@ -864,3 +856,14 @@ views_entity_row: view_mode: type: string label: 'View mode' + +views_cache: + type: mapping + label: 'Cache configuration' + mapping: + type: + type: string + label: 'Cache type' + provider: + type: string + label: 'Provider' diff --git a/core/profiles/standard/config/install/field.instance.node.article.field_tags.yml b/core/profiles/standard/config/install/field.instance.node.article.field_tags.yml index 18b58c2413b8..369306a37568 100644 --- a/core/profiles/standard/config/install/field.instance.node.article.field_tags.yml +++ b/core/profiles/standard/config/install/field.instance.node.article.field_tags.yml @@ -2,6 +2,7 @@ id: node.article.field_tags entity_type: node bundle: article field_name: field_tags +field_type: taxonomy_term_reference label: Tags description: 'Enter a comma-separated list. For example: Amsterdam, Mexico City, "Cleveland, Ohio"' required: false -- GitLab