function DesignTokenConfigEntityKernelTest::testInvalidConfigSchema
Tests invalid config schema.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ DesignToken/ DesignTokenConfigEntityKernelTest.php, line 313
Class
- DesignTokenConfigEntityKernelTest
- Tests values are from test module design_tokens_test.
Namespace
Drupal\KernelTests\Core\Theme\DesignTokenCode
public function testInvalidConfigSchema() : void {
$definitions = $this->designTokenValuePluginManager
->getDefinitions();
$validIds = implode(', ', array_keys($definitions));
$cases = [
'invalid_id' => [
'exceptionMessage' => 'Schema errors for core.design_token.invalidId with the following errors: 0 [id] The <em class="placeholder">&quot;invalidId&quot;</em> machine name is not valid.',
'config' => [
'id' => 'invalidId',
'path' => 'foo',
'type' => 'number',
'scopes' => [
':root' => 12,
],
],
],
'invalid_path' => [
'exceptionMessage' => 'Schema errors for core.design_token.invalid_path with the following errors: 0 [path] The <em class="placeholder">&quot;foo bar.baz_foo-bar Capital&quot;</em> path is not valid.',
'config' => [
'id' => 'invalid_path',
'path' => 'foo bar.baz_foo-bar Capital',
'type' => 'number',
'scopes' => [
':root' => 12,
],
],
],
'invalid_type' => [
'exceptionMessage' => 'The "foo" plugin does not exist. Valid plugin IDs for Drupal\\Core\\Theme\\DesignToken\\DesignTokenValuePluginManager are: ' . $validIds,
'config' => [
'id' => 'invalid_type',
'path' => 'bar',
'type' => 'foo',
'scopes' => [
':root' => [],
],
],
],
'invalid_scope' => [
'exceptionMessage' => 'Schema errors for core.design_token.invalid_scope with the following errors: 0 [scopes] The CSS selector {invalid_scope} is invalid., 1 [scopes] The keys of the sequence do not match the given constraints.',
'config' => [
'id' => 'invalid_scope',
'path' => 'invalid_scope',
'type' => 'fontFamily',
'scopes' => [
'{invalid_scope}' => [
'Arial',
],
],
],
],
'invalid_value_structure' => [
'exceptionMessage' => "The configuration property scopes.:root.0.0 doesn't exist.",
'config' => [
'id' => 'font_family',
'path' => 'font.family',
'type' => 'fontFamily',
'scopes' => [
':root' => [
[
6,
],
],
],
],
],
'invalid_font_weight_range' => [
'exceptionMessage' => "Schema errors for core.design_token.font_weight_range with the following errors: 0 [scopes.:root] This value should be between <em class="placeholder">1</em> and <em class="placeholder">1000</em>.",
'config' => [
'id' => 'font_weight_range',
'path' => 'font.family',
'type' => 'fontWeight',
'scopes' => [
':root' => 1500,
],
],
],
];
foreach ($cases as $key => $case) {
try {
/** @var \Drupal\Core\Theme\Entity\DesignTokenInterface $config */
$config = $this->entityTypeManager
->getStorage('design_token')
->create($case['config']);
$config->save();
$this->fail("There should have been a config schema exception with the case {$key}.");
} catch (\Exception $exception) {
$this->assertEquals($case['exceptionMessage'], $exception->getMessage());
$this->assertInstanceOf(\Exception::class, $exception);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.