class DesignTokenValuePluginManagerKernelTest

Tests the design token value plugin manager.

Attributes

#[CoversClass(DesignTokenValuePluginManager::class)] #[Group('design_token')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of DesignTokenValuePluginManagerKernelTest

File

core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenValuePluginManagerKernelTest.php, line 24

Namespace

Drupal\KernelTests\Core\Theme\DesignToken
View source
class DesignTokenValuePluginManagerKernelTest extends KernelTestBase {
  
  /**
   * The DesignTokenValuePluginManager service.
   */
  protected DesignTokenValuePluginManagerInterface $designTokenValuePluginManager;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->designTokenValuePluginManager = $this->container
      ->get(DesignTokenValuePluginManagerInterface::class);
  }
  
  /**
   * Tests detected plugins provided by Core.
   */
  public function testDetectedPlugins() : void {
    $definitions = $this->designTokenValuePluginManager
      ->getDefinitions();
    $expected = [
      'dimension' => [
        'class' => Dimension::class,
        'provider' => 'core',
        'id' => 'dimension',
        'label' => new TranslatableMarkup('Dimension'),
      ],
      'fontFamily' => [
        'class' => FontFamily::class,
        'provider' => 'core',
        'id' => 'fontFamily',
        'label' => new TranslatableMarkup('Font family'),
      ],
      'fontWeight' => [
        'class' => FontWeight::class,
        'provider' => 'core',
        'id' => 'fontWeight',
        'label' => new TranslatableMarkup('Font weight'),
      ],
      'number' => [
        'class' => Number::class,
        'provider' => 'core',
        'id' => 'number',
        'label' => new TranslatableMarkup('Number'),
      ],
      'typography' => [
        'class' => Typography::class,
        'provider' => 'core',
        'id' => 'typography',
        'label' => new TranslatableMarkup('Typography'),
      ],
    ];
    foreach ($expected as $id => $infos) {
      $this->assertArrayHasKey($id, $definitions);
      foreach ($infos as $key => $expectedValue) {
        $this->assertEquals($expectedValue, $definitions[$id][$key]);
      }
    }
  }
  
  /**
   * Tests plugin interfaces.
   */
  public function testPluginInterfaces() : void {
    $configuration = [
      'unit' => 'rem',
      'value' => 2,
    ];
    /** @var \Drupal\Core\Theme\Plugin\DesignTokenValue\Dimension $instance */
    $instance = $this->designTokenValuePluginManager
      ->createInstance('dimension', $configuration);
    $this->assertInstanceOf(Dimension::class, $instance);
    $this->assertInstanceOf(DesignTokenValueInterface::class, $instance);
  }

}

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