class FontFamilyTest

Tests font family value plugin.

Attributes

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

Hierarchy

Expanded class hierarchy of FontFamilyTest

File

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

Namespace

Drupal\Tests\Core\Theme\DesignToken\Plugin
View source
class FontFamilyTest extends DesignTokenValuePluginTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected string $pluginId = 'fontFamily';
  
  /**
   * {@inheritdoc}
   */
  public function testToDtcg(mixed $value, mixed $expected) : void {
    $this->assertIsArray($expected);
    $configuration = [
      'value' => $value,
    ];
    $plugin = new FontFamily($configuration, $this->pluginId, []);
    $this->assertSame($expected, $plugin->toDtcg());
  }
  
  /**
   * Data provider for ::testToDtcg().
   *
   * @return \Generator
   *   The test cases.
   */
  public static function providerToDtcg() : iterable {
    yield 'string' => [
      'Arial',
      [
        'Arial',
      ],
    ];
    yield 'list' => [
      [
        'Arial',
        'sans-serif',
      ],
      [
        'Arial',
        'sans-serif',
      ],
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  public function testToCss(mixed $value, string $expected) : void {
    $configuration = [
      'value' => $value,
    ];
    $plugin = new FontFamily($configuration, $this->pluginId, []);
    $this->assertSame($expected, $plugin->toCss());
  }
  
  /**
   * Data provider for ::testToCss().
   *
   * @return \Generator
   *   The test cases.
   */
  public static function providerToCss() : iterable {
    yield 'string' => [
      'Arial',
      'Arial',
    ];
    yield 'list' => [
      [
        'Arial',
        'sans-serif',
      ],
      'Arial, sans-serif',
    ];
    yield 'XSS' => [
      [
        'Arial',
        '<script>alert()</script>',
      ],
      'Arial, &lt;script&gt;alert()&lt;/script&gt;',
    ];
  }

}

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