class DesignTokenValidationTest

Tests validation of design_token entities.

Attributes

#[Group('design_token')] #[Group('config')] #[Group('Validation')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of DesignTokenValidationTest

File

core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenValidationTest.php, line 15

Namespace

Drupal\KernelTests\Core\Theme\DesignToken
View source
class DesignTokenValidationTest extends ConfigEntityValidationTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $values = [
      'id' => 'my_id',
      'path' => 'foo.bar.baz',
      'type' => 'dimension',
      'scopes' => [
        ':root' => [
          'value' => 12,
          'unit' => 'px',
        ],
        '.card' => [
          'value' => 14,
          'unit' => 'rem',
        ],
        '%breadcrumb' => [
          'value' => 14,
          'unit' => 'rem',
        ],
      ],
    ];
    $this->entity = DesignToken::create($values);
    $this->entity
      ->save();
  }
  
  /**
   * {@inheritdoc}
   */
  public function testImmutableProperties(array $valid_values = []) : void {
    // If we don't clear the previous scopes here, we will get unrelated
    // validation errors (in addition to the one we're expecting), because the
    // scopes from the *old* type won't match the config schema for the
    // scopes of the *new* type.
    $this->entity
      ->set('scopes', []);
    parent::testImmutableProperties([
      'type' => 'fontWeight',
    ]);
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.