Commit 7872b9a0 authored by catch's avatar catch

Issue #2287193 by alexpott: Fixed checkConfigSchema() can fail to report errors.

parent 5a0893fd
......@@ -54,8 +54,9 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co
}
$definition = $typed_config->getDefinition($config_name);
$this->schema = $typed_config->create($definition, $config_data);
$errors = array();
foreach ($config_data as $key => $value) {
$errors = $this->checkValue($key, $value);
$errors = array_merge($errors, $this->checkValue($key, $value));
}
if (empty($errors)) {
return TRUE;
......@@ -82,7 +83,7 @@ protected function checkValue($key, $value) {
}
catch (SchemaIncompleteException $e) {
if (is_scalar($value) || $value === NULL) {
return array($error_key => 'Missing schema.');
return array($error_key => 'Missing schema');
}
}
// Do not check value if it is defined to be ignored.
......
<?php
/**
* @file
* Contains \Drupal\config\Tests\SchemaCheckTraitTest.
*/
namespace Drupal\config\Tests;
use Drupal\Core\Config\Schema\SchemaCheckTrait;
use Drupal\simpletest\KernelTestBase;
/**
* Tests \Drupal\Core\Config\Schema\SchemaCheckTrait.
*/
class SchemaCheckTraitTest extends KernelTestBase {
use SchemaCheckTrait;
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfig;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_test', 'config_schema_test');
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'SchemaCheckTrait test',
'description' => 'Tests the functionality of SchemaCheckTrait.',
'group' => 'Configuration',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->installConfig(array('config_test', 'config_schema_test'));
$this->typedConfig = \Drupal::service('config.typed');
}
/**
* Tests \Drupal\Core\Config\Schema\SchemaCheckTrait.
*/
public function testTrait() {
// Test a non existing schema.
$ret = $this->checkConfigSchema($this->typedConfig, 'config_schema_test.noschema', \Drupal::config('config_schema_test.noschema')->get());
$this->assertIdentical($ret, FALSE);
// Test an existing schema with valid data.
$config_data = \Drupal::config('config_test.types')->get();
$ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
$this->assertIdentical($ret, TRUE);
// Add a new key and new array to test the error messages.
$config_data = array('new_key' => 'new_value', 'new_array' => array()) + $config_data;
$ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
$expected = array(
'config_test.types:new_key' => 'Missing schema',
'config_test.types:new_array' => 'Non-scalar value but not defined as an array (such as mapping or sequence)',
);
$this->assertIdentical($ret, $expected);
}
}
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