Skip to content

Commit 3ce5e9a

Browse files
committed
[TASK] Add some more tests for parsing comments
Also add a skipped test for the broken behavior that currently is blocking Emogrifier. This is the 8.x backport of #738.
1 parent df0ac7c commit 3ce5e9a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/RuleSet/DeclarationBlockTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Sabberworm\CSS\Tests\RuleSet;
44

55
use PHPUnit\Framework\TestCase;
6+
use Sabberworm\CSS\OutputFormat;
67
use Sabberworm\CSS\Parser;
78
use Sabberworm\CSS\Rule\Rule;
9+
use Sabberworm\CSS\Settings as ParserSettings;
810
use Sabberworm\CSS\Value\Size;
911

1012
/**
@@ -450,4 +452,50 @@ public function orderOfElementsMatchingOriginalOrderAfterExpandingShorthands()
450452
array_map('strval', $oDeclaration->getRulesAssoc())
451453
);
452454
}
455+
456+
/**
457+
* @return array<string, array{0: non-empty-string, 1: non-empty-string}>
458+
*/
459+
public static function declarationBlocksWithCommentsProvider()
460+
{
461+
return [
462+
'CSS comments with one asterisk' => ['p {color: #000;/* black */}', 'p {color: #000;}'],
463+
'CSS comments with two asterisks' => ['p {color: #000;/** black */}', 'p {color: #000;}'],
464+
];
465+
}
466+
467+
/**
468+
* @test
469+
* @param string $cssWithComments
470+
* @param string $cssWithoutComments
471+
* @dataProvider declarationBlocksWithCommentsProvider
472+
*/
473+
public function canRemoveCommentsFromRulesUsingLenientParsing($cssWithComments, $cssWithoutComments) {
474+
$parserSettings = ParserSettings::create()->withLenientParsing(true);
475+
$document = (new Parser($cssWithComments, $parserSettings))->parse();
476+
477+
$outputFormat = (new OutputFormat())->setRenderComments(false);
478+
$renderedDocument = $document->render($outputFormat);
479+
480+
self::assertSame($cssWithoutComments, $renderedDocument);
481+
}
482+
483+
/**
484+
* @test
485+
*
486+
* @param string $cssWithComments
487+
* @param string $cssWithoutComments
488+
* @dataProvider declarationBlocksWithCommentsProvider
489+
*/
490+
public function canRemoveCommentsFromRulesUsingStrictParsing($cssWithComments, $cssWithoutComments) {
491+
self::markTestSkipped('This currently crashes, and we need to fix it.');
492+
493+
$parserSettings = ParserSettings::create()->withLenientParsing(false);
494+
$document = (new Parser($cssWithComments, $parserSettings))->parse();
495+
496+
$outputFormat = (new OutputFormat())->setRenderComments(false);
497+
$renderedDocument = $document->render($outputFormat);
498+
499+
self::assertSame($cssWithoutComments, $renderedDocument);
500+
}
453501
}

0 commit comments

Comments
 (0)