class DesignTokenEntityTest

Tests design token entity.

Attributes

#[CoversClass(DesignToken::class)] #[Group('design_token')]

Hierarchy

Expanded class hierarchy of DesignTokenEntityTest

File

core/tests/Drupal/Tests/Core/Theme/DesignToken/DesignTokenEntityTest.php, line 16

Namespace

Drupal\Tests\Core\Theme\DesignToken
View source
class DesignTokenEntityTest extends UnitTestCase {
  
  /**
   * Tests getCssScopeName.
   */
  public function testGetCssScopeName(string $scope, string $expected) : void {
    $this->assertEquals($expected, DesignToken::getCssScopeName($scope));
  }
  
  /**
   * Data provider for ::testGetCssScopeName().
   *
   * @return \Generator
   *   The test cases.
   */
  public static function providerGetCssScopeName() : iterable {
    yield 'Nothing to replace' => [
      'my-scope',
      'my-scope',
    ];
    yield 'One character to replace' => [
      '%my-scope',
      '.my-scope',
    ];
    yield 'Multiple characters to replace' => [
      '%my-scope %more-precise %even%more%precise',
      '.my-scope .more-precise .even.more.precise',
    ];
  }
  
  /**
   * Tests getConfigScopeName.
   */
  public function testGetConfigScopeName(string $scope, string $expected) : void {
    $this->assertEquals($expected, DesignToken::getConfigScopeName($scope));
  }
  
  /**
   * Data provider for ::testGetConfigScopeName().
   *
   * @return \Generator
   *   The test cases.
   */
  public static function providerGetConfigScopeName() : iterable {
    yield 'Nothing to replace' => [
      'my-scope',
      'my-scope',
    ];
    yield 'One character to replace' => [
      '.my-scope',
      '%my-scope',
    ];
    yield 'Multiple characters to replace' => [
      '.my-scope .more-precise .even.more.precise',
      '%my-scope %more-precise %even%more%precise',
    ];
  }
  
  /**
   * Tests getCssVariableName.
   */
  public function testGetCssVariableName(string $path, string $expected) : void {
    $token = new DesignToken([
      'path' => $path,
    ], 'design_token');
    $this->assertEquals($expected, $token->getCssVariableName());
  }
  
  /**
   * Data provider for ::testGetCssVariableName().
   *
   * @return \Generator
   *   The test cases.
   */
  public static function providerGetCssVariableName() : iterable {
    yield 'Simple' => [
      'myPath',
      '--myPath',
    ];
    yield 'With underscores' => [
      'my_token_path',
      '--my-token-path',
    ];
    yield 'With spaces' => [
      'my token path',
      '--my-token-path',
    ];
    yield 'With dots' => [
      'my.token.path',
      '--my-token-path',
    ];
  }

}

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