class FontWeightTest
Tests font weight value plugin.
Attributes
#[CoversClass(FontWeight::class)]
#[Group('design_token')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Theme\DesignToken\DesignTokenValuePluginTestBase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\Core\Theme\DesignToken\Plugin\FontWeightTest extends \Drupal\Tests\Core\Theme\DesignToken\DesignTokenValuePluginTestBase
- class \Drupal\Tests\Core\Theme\DesignToken\DesignTokenValuePluginTestBase extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of FontWeightTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ DesignToken/ Plugin/ FontWeightTest.php, line 17
Namespace
Drupal\Tests\Core\Theme\DesignToken\PluginView source
class FontWeightTest extends DesignTokenValuePluginTestBase {
/**
* {@inheritdoc}
*/
protected string $pluginId = 'fontWeight';
/**
* {@inheritdoc}
*/
public function testToDtcg(mixed $value, mixed $expected) : void {
assert(is_string($expected) || is_int($expected));
$configuration = [
'value' => $value,
];
$plugin = new FontWeight($configuration, $this->pluginId, []);
$this->assertSame($expected, $plugin->toDtcg());
}
/**
* Data provider for ::testToDtcg().
*
* @return \Generator
* The test cases.
*/
public static function providerToDtcg() : iterable {
foreach (FontWeightAlias::cases() as $case) {
yield $case->name => [
$case->value,
$case->value(),
];
}
yield 'integer' => [
50,
50,
];
yield 'minimum' => [
1,
1,
];
yield 'maximum' => [
1000,
1000,
];
}
/**
* {@inheritdoc}
*/
public function testToCss(mixed $value, string $expected) : void {
$configuration = [
'value' => $value,
];
$plugin = new FontWeight($configuration, $this->pluginId, []);
$this->assertSame($expected, $plugin->toCss());
}
/**
* Data provider for ::testToCss().
*
* @return \Generator
* The test cases.
*/
public static function providerToCss() : iterable {
foreach (FontWeightAlias::cases() as $case) {
yield $case->name => [
$case->value,
(string) $case->value(),
];
}
yield 'integer' => [
50,
'50',
];
yield 'minimum' => [
1,
'1',
];
yield 'maximum' => [
1000,
'1000',
];
}
/**
* Tests invalid unit.
*/
public function testInvalidUnit() : void {
$this->expectException(\ValueError::class);
$this->expectExceptionMessage('"<script>alert()</script>" is not a valid backing value for enum Drupal\\Core\\Theme\\DesignToken\\Enum\\FontWeightAlias');
$configuration = [
'value' => '<script>alert()</script>',
];
new FontWeight($configuration, $this->pluginId, []);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.