From 101c2c88fc7ae0b11cdca863787c7e164af4f7ae Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 27 Oct 2024 08:40:40 +0100 Subject: [PATCH] Changes as suggested in the code review --- src/Css/CssDocument.php | 2 +- tests/Support/Traits/CssDataProviders.php | 16 ++--- tests/Unit/Css/CssDocumentTest.php | 12 ++-- .../AbstractHtmlProcessorTest.php | 68 +++++++++---------- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Css/CssDocument.php b/src/Css/CssDocument.php index c5bb78f1..a0d7628e 100644 --- a/src/Css/CssDocument.php +++ b/src/Css/CssDocument.php @@ -63,7 +63,7 @@ public function __construct(string $css, bool $debug) private function hasNestedAtRule(string $css): bool { return (new Preg()) - ->match('/@(?:media|supports|(?:-webkit-|-moz-|-ms-|-o-)?+(keyframes|document))\\b/', $css) !== 0; + ->match('/@(?:media|supports|(?:-webkit-|-moz-|-ms-|-o-)?+(keyframes|document))\\b/', $css) !== 0; } /** diff --git a/tests/Support/Traits/CssDataProviders.php b/tests/Support/Traits/CssDataProviders.php index 343b9771..1c50c5e7 100644 --- a/tests/Support/Traits/CssDataProviders.php +++ b/tests/Support/Traits/CssDataProviders.php @@ -29,19 +29,19 @@ public function provideEquivalentCompleteCss(): array { $datasetsWithAtMediaRuleSelectorListAndPropertyDeclaration = self::crossDatasetWithItself([ 'unminified CSS with `@media` rule, selector list, and property declaration' - => ['@media screen { html, body { color: green; } }'], + => ['@media screen { html, body { color: green; } }'], 'minified CSS with `@media` rule, selector list, and property declaration' - => ['@media screen{html,body{color:green}}'], + => ['@media screen{html,body{color:green}}'], 'CSS with `@media` rule, selector list, and property declaration, with extra spaces' - => [' @media screen { html , body { color : green ; } } '], + => [' @media screen { html , body { color : green ; } } '], 'CSS with `@media` rule, selector list, and property declaration, with linefeeds' - => ["\n@media\nscreen\n{\nhtml\n,\nbody\n{\ncolor\n:\ngreen\n;\n}\n}\n"], + => ["\n@media\nscreen\n{\nhtml\n,\nbody\n{\ncolor\n:\ngreen\n;\n}\n}\n"], 'CSS with `@media` rule, selector list, and property declaration, with Windows line endings' - => ["\r\n@media\r\nscreen\r\n{\r\nhtml\r\n,\r\nbody\r\n{\r\ncolor\r\n:\r\ngreen\r\n;\r\n}\r\n}\r\n"], + => ["\r\n@media\r\nscreen\r\n{\r\nhtml\r\n,\r\nbody\r\n{\r\ncolor\r\n:\r\ngreen\r\n;\r\n}\r\n}\r\n"], 'CSS with `@media` rule, selector list, and property declaration, with uppercase at-rule name' - => ['@MEDIA screen { html, body { color: green; } }'], + => ['@MEDIA screen { html, body { color: green; } }'], 'CSS with `@media` rule, selector list, and property declaration, with mixed-case at-rule name' - => ['@MeDiA screen { html, body { color: green; } }'], + => ['@MeDiA screen { html, body { color: green; } }'], ]); $datasetsWithUrlPropertyValue = self::crossDatasetWithItself([ @@ -53,7 +53,7 @@ public function provideEquivalentCompleteCss(): array 'CSS with single-quoted string in property value' => ['.new::before { content: \'New Entry! \'; }'], 'CSS with double-quoted string in property value' => ['.new::before { content: "New Entry! "; }'], 'CSS with quoted string in property value without trailing semicolon' - => ['.new::before { content: "New Entry! " }'], + => ['.new::before { content: "New Entry! " }'], 'minified CSS with quoted string in property value' => ['.new::before{content:"New Entry! "}'], ]); diff --git a/tests/Unit/Css/CssDocumentTest.php b/tests/Unit/Css/CssDocumentTest.php index c70243aa..ca6e87ea 100644 --- a/tests/Unit/Css/CssDocumentTest.php +++ b/tests/Unit/Css/CssDocumentTest.php @@ -572,16 +572,16 @@ public function provideInvalidNonConditionalAtRuleWhichDoesNotCauseException(): return [ '`@font-face` without `font-family`' => [ ' - @font-face { - src: url("/foo-sans.woff2") format("woff2"); - } + @font-face { + src: url("/foo-sans.woff2") format("woff2"); + } ', ], '`@font-face` without `src`' => [ ' - @font-face { - font-family: "Foo Sans"; - } + @font-face { + font-family: "Foo Sans"; + } ', ], '`@import` after style rule' => ['@import "foo.css";', 'p { color: red; }'], diff --git a/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php b/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php index 6aedce12..5e2102ac 100644 --- a/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php +++ b/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php @@ -224,9 +224,9 @@ public function provideHtmlWithOptionalTagsOmitted(): array // broken: OPTGROUP end tag omission with OPTGROUP element following 'OPTGROUP end tag omission at end of list' => [ '', + . '', '', + . '', ], 'OPTION end tag omission with OPTION element following' => [ '', @@ -432,9 +432,9 @@ public function provideContentWithoutHtmlTag(): array 'BODY element with Content-Type in text' => ['Content-Type'], 'body content only with Content-Type in text' => ['

Content-Type

'], 'BODY element containing Content-Type META tag' - => [''], + => [''], 'body content only with Content-Type META tag' - => ['

hello

'], + => ['

hello

'], ]; } @@ -535,22 +535,22 @@ public function provideContentWithoutHeadTag(): array 'BODY element' => [''], 'HEADER element' => ['
'], 'http-equiv META element (implicit HEAD)' - => [''], + => [''], 'viewport META element (implicit HEAD)' - => [''], + => [''], 'META element with Content-Type as a value' => [''], 'BODY element with Content-Type in text' => ['Content-Type'], 'body content only with Content-Type in text' => ['

Content-Type

'], 'http-equiv META element within BODY (not allowed)' - => [''], + => [''], 'http-equiv META element after P (implicit BODY, not allowed)' - => ['

hello

'], + => ['

hello

'], 'http-equiv META element within P (not allowed)' - => ['

'], + => ['

'], 'viewport META element within P (allowed)' - => ['

'], + => ['

'], 'http-equiv META element within HEADER (not allowed)' - => ['
'], + => ['
'], ]; } @@ -585,21 +585,21 @@ public function provideContentWithHeadTag(): array 'HEAD element and HEADER element' => ['
'], 'HEAD element with Content-Type in comment' => [''], 'HEAD element with Content-Type as META value' - => [''], + => [''], 'with BODY element with Content-Type in text' => ['Content-Type'], 'with implicit body content with Content-Type in text' => ['

Content-Type

'], 'with BODY element containing Content-Type META tag' - => [''], + => [''], 'with implicit body content with Content-Type META tag' - => ['

hello

'], + => ['

hello

'], 'with end tag omitted and BODY element containing Content-Type META tag' - => [''], + => [''], 'with end tag omitted and implicit body content with Content-Type META tag' - => ['

hello

'], + => ['

hello

'], 'with Content-Type META tag after end tag' - => [''], + => [''], 'with Content-Type META tag after uppercase end tag' - => [''], + => [''], ]; } @@ -766,15 +766,15 @@ public function normalizedDocumentTypeDataProvider(): array 'HTML5, extra whitespace' => ['', ''], 'HTML 4 transitional, uppercase' => [ '', + . '"http://www.w3.org/TR/REC-html40/loose.dtd">', '', + . '"http://www.w3.org/TR/REC-html40/loose.dtd">', ], 'HTML 4 transitional, lowercase' => [ '', + . '"http://www.w3.org/TR/REC-html40/loose.dtd">', '', + . '"http://www.w3.org/TR/REC-html40/loose.dtd">', ], ]; } @@ -806,13 +806,13 @@ public function provideMalformedContentTypeMetaTag(): array 'extra character before META' => [''], 'extra character after META' => [''], 'extra character before HTTP-EQUIV' - => [''], + => [''], 'extra character after HTTP-EQUIV' - => [''], + => [''], 'extra character before CONTENT-TYPE' - => [''], + => [''], 'extra character after CONTENT-TYPE' - => [''], + => [''], ]; } @@ -854,7 +854,7 @@ public function provideContentTypeMetaTag(): array return [ 'double-quoted attribute values' => [''], 'single-quoted attribute values' - => [''], + => [''], 'unquoted attribute values' => [''], 'reverse order attributes' => [''], 'without charset' => [''], @@ -887,23 +887,23 @@ public function provideHtmlAroundContentType(): array 'HEAD element with TAB after start tag' => ["\t", ''], 'HEAD element with attribute' => ['', ''], 'HTML, HEAD, and BODY with HEADER elements' - => ['', '
'], + => ['', '
'], 'HEAD element with comment' => ['', ''], 'HEAD element with commented-out BODY start tag' => ['', ''], 'HEAD element with BASE element' => ['', ''], 'HEAD element with COMMAND element' => ['', ''], 'HEAD element with LINK element' - => ['', ''], + => ['', ''], 'HEAD element with another META element' => ['', ''], 'HEAD element with NOSCRIPT element' - => ['', ''], + => ['', ''], 'HEAD element with SCRIPT element' => ['', ''], 'HEAD element with STYLE element' => ['', ''], 'HEAD element with TEMPLATE element' - => ['', ''], + => ['', ''], 'HEAD element with TITLE element' => ['Test', ''], 'HEAD element with uppercase TEMPLATE element' - => ['', ''], + => ['', ''], 'HEAD element with uppercase TITLE element' => ['Test', ''], 'Second valid(ish) Content-Type in BODY' => [ '', @@ -1266,8 +1266,8 @@ private static function assertContainsHtml(string $needle, string $haystack, str $needleMatcher = \preg_quote($needle, '%'); $needleMatcherWithNewlines = (new Preg())->replace( '%\\\\<(?:body|ul|dl|optgroup|table|tr|hr' - . '|/(?:li|dd|dt|option|optgroup|caption|colgroup|thead|tbody|tfoot|tr|td|th' - . '|p|dl|h[1-6]|menu|ol|pre|table|ul|address|blockquote|div|fieldset|form))\\\\>%', + . '|/(?:li|dd|dt|option|optgroup|caption|colgroup|thead|tbody|tfoot|tr|td|th' + . '|p|dl|h[1-6]|menu|ol|pre|table|ul|address|blockquote|div|fieldset|form))\\\\>%', '$0\\n?+', $needleMatcher );