Commit c98b2fdc authored by alexpott's avatar alexpott

Issue #2266501 by Gábor Hojtsy, vijaycs85, YesCT: Array level schema errors...

Issue #2266501 by Gábor Hojtsy, vijaycs85, YesCT: Array level schema errors are not reported, fix wrong schemas identified.
parent 3ee31d17
......@@ -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;
}
......
......@@ -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.*:
......
......@@ -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'
......
......@@ -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
......
......@@ -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
......@@ -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'
......
# 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'
......
......@@ -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'
......@@ -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
......
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