function DesignTokenConfigEntityKernelTest::testConfigSchema
Tests config schema.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ DesignToken/ DesignTokenConfigEntityKernelTest.php, line 174
Class
- DesignTokenConfigEntityKernelTest
- Tests values are from test module design_tokens_test.
Namespace
Drupal\KernelTests\Core\Theme\DesignTokenCode
public function testConfigSchema() : void {
$types = [
'dimension' => [
'id' => 'dimension',
'path' => 'dimension',
'type' => 'dimension',
'scopes' => [
':root' => [
'value' => 12,
'unit' => 'px',
],
],
],
'dimension with enum' => [
'id' => 'dimension_with_enum',
'path' => 'dimension',
'type' => 'dimension',
'scopes' => [
':root' => [
'value' => 12,
'unit' => DimensionUnit::Rem,
],
],
],
'fontFamily' => [
'id' => 'font_family',
'path' => 'font.family',
'type' => 'fontFamily',
'scopes' => [
':root' => [
'Arial',
],
],
],
'fontFamily with string' => [
'id' => 'font_family_with_family',
'path' => 'font.family',
'type' => 'fontFamily',
'scopes' => [
':root' => 'Arial',
],
],
'fontWeight' => [
'id' => 'font_weight',
'path' => 'font.weight',
'type' => 'fontWeight',
'scopes' => [
':root' => 202,
],
],
'fontWeight with string' => [
'id' => 'font_weight_with_string',
'path' => 'font.weight',
'type' => 'fontWeight',
'scopes' => [
':root' => 'regular',
],
],
'fontWeight with enum' => [
'id' => 'font_weight_with_enum',
'path' => 'font.weight',
'type' => 'fontWeight',
'scopes' => [
':root' => FontWeightAlias::Bold,
],
],
'number' => [
'id' => 'number',
'path' => 'number',
'type' => 'number',
'scopes' => [
':root' => 12,
],
],
'typography' => [
'id' => 'typography',
'path' => 'typography',
'type' => 'typography',
'scopes' => [
':root' => [
'fontFamily' => [
'Arial',
'Helvetica',
],
'fontSize' => [
'value' => 10,
'unit' => 'px',
],
'fontWeight' => 'bold',
'letterSpacing' => [
'value' => 5,
'unit' => 'px',
],
'lineHeight' => 5,
],
],
],
'typography with other config structure' => [
'id' => 'typography_with_other',
'path' => 'typography',
'type' => 'typography',
'scopes' => [
':root' => [
'fontFamily' => 'Arial',
'fontSize' => [
'value' => 10,
'unit' => DimensionUnit::Rem,
],
'fontWeight' => 'bold',
'letterSpacing' => [
'value' => 5,
'unit' => DimensionUnit::Px,
],
'lineHeight' => 5,
],
],
],
'valid_path' => [
'id' => 'valid_path',
'path' => 'foo bar.baz_foo-bar',
'type' => 'number',
'scopes' => [
':root' => 12,
],
],
];
foreach ($types as $values) {
/** @var \Drupal\Core\Theme\Entity\DesignTokenInterface $config */
$config = $this->entityTypeManager
->getStorage('design_token')
->create($values);
$config->save();
$this->assertInstanceOf(DesignTokenInterface::class, $config);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.