-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Parse @font-face src property as comma-delimited list
Fixes #789. Also adds an initial `TestCase` for `Rule/Rule`.
- Loading branch information
Jake Hotson
committed
Jan 17, 2025
1 parent
d783f0e
commit defbc9e
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sabberworm\CSS\Tests\Value; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sabberworm\CSS\Parsing\ParserState; | ||
use Sabberworm\CSS\Settings; | ||
use Sabberworm\CSS\Rule\Rule; | ||
use Sabberworm\CSS\Value\RuleValueList; | ||
use Sabberworm\CSS\Value\ValueList; | ||
|
||
/** | ||
* @covers \Sabberworm\CSS\Rule\Rule | ||
*/ | ||
final class RuleTest extends TestCase | ||
{ | ||
/** | ||
* @return array<string, array{0: string, 1: array<int, string>}> | ||
*/ | ||
public static function provideRulesAndExpectedParsedValueListTypes(): array | ||
{ | ||
return [ | ||
'src (e.g. in @font-face)' => [ | ||
" | ||
src: url('../fonts/open-sans-italic-300.woff2') format('woff2'), | ||
url('../fonts/open-sans-italic-300.ttf') format('truetype'); | ||
", | ||
[RuleValueList::class, RuleValueList::class], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @param array<int, string> $expectedTypeClassnames | ||
* | ||
* @dataProvider provideRulesAndExpectedParsedValueListTypes | ||
*/ | ||
public function parsesValuesIntoExpectedTypeList(string $rule, array $expectedTypeClassnames): void | ||
{ | ||
$subject = Rule::parse(new ParserState($rule, Settings::create())); | ||
|
||
$value = $subject->getValue(); | ||
self::assertInstanceOf(ValueList::class, $value); | ||
|
||
$actualClassnames = \array_map( | ||
function ($component): string { | ||
return \get_class($component); | ||
}, | ||
$value->getListComponents() | ||
); | ||
|
||
self::assertSame($expectedTypeClassnames, $actualClassnames); | ||
} | ||
} |