Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443205
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443205
Commits
7872b9a0
Commit
7872b9a0
authored
10 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2287193
by alexpott: Fixed checkConfigSchema() can fail to report errors.
parent
5a0893fd
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php
+3
-2
3 additions, 2 deletions
core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php
core/modules/config/src/Tests/SchemaCheckTraitTest.php
+77
-0
77 additions, 0 deletions
core/modules/config/src/Tests/SchemaCheckTraitTest.php
with
80 additions
and
2 deletions
core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php
+
3
−
2
View file @
7872b9a0
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
core/modules/config/src/Tests/SchemaCheckTraitTest.php
0 → 100644
+
77
−
0
View file @
7872b9a0
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment