From 10fa58b7183f4f23ab454196c81724f15606aab5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 6 Nov 2024 18:24:55 +0100 Subject: [PATCH 1/3] Generators/HTML: move section link creation to own function Move the creation of in-page anchor link text to a separate function as this was done in two separate places. The separate function will make it more straight-forward to safeguard that the anchors and the links to these anchors stay in sync. --- src/Generators/HTML.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index 681699ba65..b0d5c0afea 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -215,7 +215,7 @@ protected function getFormattedToc() $doc->load($file); $documentation = $doc->getElementsByTagName('documentation')->item(0); $title = $this->getTitle($documentation); - $output .= sprintf($listItemTemplate, str_replace(' ', '-', $title), $title); + $output .= sprintf($listItemTemplate, $this->titleToAnchor($title), $title); } $output .= ' '.PHP_EOL; @@ -290,7 +290,7 @@ public function processSniff(DOMNode $doc) if (trim($content) !== '') { $title = $this->getTitle($doc); - echo ' '.PHP_EOL; + echo ' '.PHP_EOL; echo '

'.$title.'

'.PHP_EOL; echo $content; } @@ -298,6 +298,22 @@ public function processSniff(DOMNode $doc) }//end processSniff() + /** + * Transform a title to a string which can be used as an HTML anchor. + * + * @param string $title The title. + * + * @since 3.12.0 + * + * @return string + */ + private function titleToAnchor($title) + { + return str_replace(' ', '-', $title); + + }//end titleToAnchor() + + /** * Print a text block found in a standard. * From d6c20b78b973568c31a1ad5f3cd7a80aad6caa7e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 6 Nov 2024 18:31:42 +0100 Subject: [PATCH 2/3] Generators/HTML: improve anchor links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As things were, the TOC would link to the section headers, but there was no straight-forward way to copy the link to a particular section once a user was viewing the section. This small change adds an invisible `§` character after each section title, which becomes visible when the user hovers over the title and allows for copying the permalink to that section. Includes updated test expectations. --- src/Generators/HTML.php | 20 +++++++++-- ...xpectedOutputCodeComparisonBlankLines.html | 16 +++++++-- ...pectedOutputCodeComparisonBlockLength.html | 16 +++++++-- .../ExpectedOutputCodeComparisonEncoding.html | 16 +++++++-- ...xpectedOutputCodeComparisonLineLength.html | 16 +++++++-- .../ExpectedOutputCodeTitleLineWrapping.html | 16 +++++++-- .../ExpectedOutputCodeTitleWhitespace.html | 16 +++++++-- .../ExpectedOutputDocumentationTitleCase.html | 16 +++++++-- ...xpectedOutputDocumentationTitleLength.html | 16 +++++++-- ...dOutputDocumentationTitlePCREFallback.html | 16 +++++++-- ...validCodeComparisonMismatchedCodeElms.html | 16 +++++++-- ...utInvalidCodeComparisonMissingCodeElm.html | 16 +++++++-- ...ctedOutputInvalidCodeComparisonNoCode.html | 16 +++++++-- ...dOutputInvalidCodeComparisonNoContent.html | 16 +++++++-- ...tInvalidCodeComparisonOneEmptyCodeElm.html | 16 +++++++-- ...InvalidCodeComparisonTwoEmptyCodeElms.html | 16 +++++++-- .../ExpectedOutputInvalidCodeTitleEmpty.html | 16 +++++++-- ...ExpectedOutputInvalidCodeTitleMissing.html | 16 +++++++-- ...dOutputInvalidDocumentationTitleEmpty.html | 16 +++++++-- ...utputInvalidDocumentationTitleMissing.html | 16 +++++++-- ...xpectedOutputInvalidStandardNoContent.html | 16 +++++++-- .../Expectations/ExpectedOutputOneDoc.html | 16 +++++++-- .../ExpectedOutputStandardBlankLines.html | 16 +++++++-- .../ExpectedOutputStandardEncoding.html | 16 +++++++-- .../ExpectedOutputStandardIndent.html | 16 +++++++-- .../ExpectedOutputStandardLineWrapping.html | 16 +++++++-- .../ExpectedOutputStructureDocs.html | 34 +++++++++++-------- ...edOutputUnsupportedOneElmAtWrongLevel.html | 16 +++++++-- ...tputUnsupportedSuperfluousCodeElement.html | 16 +++++++-- 29 files changed, 416 insertions(+), 70 deletions(-) diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index b0d5c0afea..cf0bd43162 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -53,6 +53,19 @@ class HTML extends Generator margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -290,8 +303,11 @@ public function processSniff(DOMNode $doc) if (trim($content) !== '') { $title = $this->getTitle($doc); - echo '
'.PHP_EOL; - echo '

'.$title.'

'.PHP_EOL; + printf( + '

%2$s §

'.PHP_EOL, + $this->titleToAnchor($title), + $title + ); echo $content; } diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html index 7726809fea..535031bddc 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, blank lines

+

Code Comparison, blank lines §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html index 5897d87131..d75506f62b 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, block length

+

Code Comparison, block length §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html index dbf5100ba7..5809ade683 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, char encoding

+

Code Comparison, char encoding §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html index d1b3483535..0c338283cd 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, line length

+

Code Comparison, line length §

Ensure there is no PHP "Warning: str_repeat(): Second argument has to be greater than or equal to 0".
Ref: squizlabs/PHP_CodeSniffer#2522

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html index a2e7c6a97f..bd2a39c489 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Title, line wrapping

+

Code Title, line wrapping §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html index 88eab60199..793e8ae740 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Title, whitespace handling

+

Code Title, whitespace handling §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleCase.html b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleCase.html index e1a11f7bde..e722651973 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleCase.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleCase.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

lowercase title

+

lowercase title §

This is a standard block.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html index b4963bea4f..65b07fa703 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

This is a very very very very very very very very very very very long title

+

This is a very very very very very very very very very very very long title §

This is a standard block.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html index c9abcb1cba..b58219a65f 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Documentation Title PCRE Fallback

+

Documentation Title PCRE Fallback §

Testing the document title can get determined from the sniff name if missing.

This file name contains an acronym on purpose to test the word splitting.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html index 3176ce9dee..c9389e338a 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, mismatched code blocks

+

Code Comparison, mismatched code blocks §

This doc has two code elements, one only has a title, one has actual code. Unbalanced

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html index 1f63a58591..e711e8aff0 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, missing code element

+

Code Comparison, missing code element §

This is a standard block.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html index 964e800232..358cfd2060 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, no code

+

Code Comparison, no code §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html index 0cbe32caf2..a8c9ba3ef6 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, no content

+

Code Comparison, no content §

This is a standard block.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html index 14ad04ad85..8400791c47 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, one empty code element

+

Code Comparison, one empty code element §

This doc has two code elements, but only one of them has a title and actual code.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html index fcf0131ccc..7fd5701ecf 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Comparison, two empty code elements

+

Code Comparison, two empty code elements §

This doc has two code elements, but neither of them contain any information.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html index 6e2af6ae8f..1dc6d7b8ac 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Title, empty

+

Code Title, empty §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html index 8988712a03..d43389f93d 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Code Title, missing

+

Code Title, missing §

This is a standard block.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html index 727e0e0706..1bff43a11e 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Documentation Title Empty

+

Documentation Title Empty §

The above "documentation" element has an empty title attribute.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html index 2da51a0f0d..9a374ad696 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Documentation Title Missing

+

Documentation Title Missing §

The above "documentation" element is missing the title attribute.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html index 9f216091f9..0c48a0fc91 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Standard Element, no content

+

Standard Element, no content §

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html b/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html index 30bcd76501..203885ff0e 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

One Standard Block, No Code

+

One Standard Block, No Code §

Documentation contains one standard block and no code comparison.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html index b23f86921a..b3e0e23412 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Standard Element, blank line handling

+

Standard Element, blank line handling §

There is a blank line at the start of this standard.

And the above blank line is also deliberate to test part of the logic.

Let's also end on a blank line to test that too.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html index 09b98765e2..260576a7fb 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Standard Element, handling of HTML tags

+

Standard Element, handling of HTML tags §

The use of tags in standard descriptions is allowed and their handling should be safeguarded.
Other tags, like <a href="example.com">link</a>, <b>bold</bold>, <script></script> are not allowed and will be encoded for display when the HTML or Markdown report is used.

Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html index a5ae0dbecf..0735e5f7c6 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Standard Element, indentation should be ignored

+

Standard Element, indentation should be ignored §

This line has no indentation.
This line has 4 spaces indentation.
This line has 8 spaces indentation.
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html index 66ebcb091f..6c6cd01814 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

GeneratorTest Coding Standards

- -

Standard Element, line wrapping handling

+

Standard Element, line wrapping handling §

This line has to be exactly 99 chars to test part of the logic.------------------------------------
And this line has to be exactly 100 chars.----------------------------------------------------------
And here we have a line which should start wrapping as it is longer than 100 chars. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pellentesque iaculis enim quis hendrerit. Morbi ultrices in odio pharetra commodo.

diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html b/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html index a7324d80fa..06156a8441 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -86,8 +99,7 @@

Table of Contents

  • Two Standard Blocks, One Code Comparison
  • Two Standard Blocks, Three Code Comparisons
  • - -

    Code Comparison Only, Missing Standard Block

    +

    Code Comparison Only, Missing Standard Block §

    Valid: Lorem ipsum dolor sit amet.
    @@ -98,8 +110,7 @@

    Code Comparison Only, Missing Standard Block

    Valid: Lorem ipsum dolor sit amet. class Comparison {}
    - -

    One Standard Block, Code Comparison

    +

    One Standard Block, Code Comparison §

    Documentation contains one standard block and one code comparison.

    @@ -111,11 +122,9 @@

    One Standard Block, Code Comparison

    class Comparison {}
    - -

    One Standard Block, No Code

    +

    One Standard Block, No Code §

    Documentation contains one standard block and no code comparison.

    - -

    One Standard Block, Two Code Comparisons

    +

    One Standard Block, Two Code Comparisons §

    Documentation contains one standard block and two code comparisons.

    @@ -137,12 +146,10 @@

    One Standard Block, Two Code Comparisons

    $a = 10;
    - -

    Two Standard Blocks, No Code

    +

    Two Standard Blocks, No Code §

    This is standard block one.

    This is standard block two.

    - -

    Two Standard Blocks, One Code Comparison

    +

    Two Standard Blocks, One Code Comparison §

    This is standard block one.

    @@ -155,8 +162,7 @@

    Two Standard Blocks, One Code Comparison

    This is standard block two.

    - -

    Two Standard Blocks, Three Code Comparisons

    +

    Two Standard Blocks, Three Code Comparisons §

    This is standard block one.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html index ff1f5d842e..87443d1eee 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

    GeneratorTest Coding Standards

    - -

    One element correct, one element wrong level

    +

    One element correct, one element wrong level §

    This is a standard block at the correct level.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html index 6cd60d0cac..7fb3615ed9 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html @@ -26,6 +26,19 @@ margin-top: 50px; } + h2 a.sniffanchor, + h2 a.sniffanchor { + color: #006C95; + opacity: 0; + padding: 0 3px; + text-decoration: none; + font-weight: bold; + } + h2:hover a.sniffanchor, + h2:focus a.sniffanchor { + opacity: 1; + } + .code-comparison { width: 100%; } @@ -75,8 +88,7 @@

    GeneratorTest Coding Standards

    - -

    Superfluous code element

    +

    Superfluous code element §

    This is a standard block.

    From 462ff5f5dce6f8d174ab7a90bdfbc69a9c99af4d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 8 Mar 2025 00:53:52 +0100 Subject: [PATCH 3/3] Generators/HTML: slugify anchor links ... to prevent issues with URL encoding. Note: as this _may_ result in duplicate anchor links, this commit includes a protection against this by adding a numeric suffix to the anchor if a duplicate is detected. Includes a test with a variety of non-ascii chars and duplicate titles. Includes updated test expectations for various other tests. --- src/Generators/HTML.php | 26 ++++- tests/Core/Generators/AnchorLinksTest.xml | 10 ++ ...xpectedOutputCodeComparisonBlankLines.html | 2 +- ...pectedOutputCodeComparisonBlockLength.html | 2 +- .../ExpectedOutputCodeComparisonEncoding.html | 2 +- ...xpectedOutputCodeComparisonLineLength.html | 2 +- .../ExpectedOutputCodeTitleLineWrapping.html | 2 +- .../ExpectedOutputCodeTitleWhitespace.html | 2 +- ...xpectedOutputDocumentationTitleLength.html | 2 +- ...dOutputDocumentationTitlePCREFallback.html | 2 +- ...dOutputDocumentationTitleToAnchorSlug.html | 107 ++++++++++++++++++ ...validCodeComparisonMismatchedCodeElms.html | 2 +- ...utInvalidCodeComparisonMissingCodeElm.html | 2 +- ...ctedOutputInvalidCodeComparisonNoCode.html | 2 +- ...dOutputInvalidCodeComparisonNoContent.html | 2 +- ...tInvalidCodeComparisonOneEmptyCodeElm.html | 2 +- ...InvalidCodeComparisonTwoEmptyCodeElms.html | 2 +- .../ExpectedOutputInvalidCodeTitleEmpty.html | 2 +- ...ExpectedOutputInvalidCodeTitleMissing.html | 2 +- ...dOutputInvalidDocumentationTitleEmpty.html | 2 +- ...utputInvalidDocumentationTitleMissing.html | 2 +- ...xpectedOutputInvalidStandardNoContent.html | 2 +- .../Expectations/ExpectedOutputOneDoc.html | 2 +- .../ExpectedOutputStandardBlankLines.html | 2 +- .../ExpectedOutputStandardEncoding.html | 2 +- .../ExpectedOutputStandardIndent.html | 2 +- .../ExpectedOutputStandardLineWrapping.html | 2 +- .../ExpectedOutputStructureDocs.html | 30 ++--- ...edOutputUnsupportedOneElmAtWrongLevel.html | 2 +- ...tputUnsupportedSuperfluousCodeElement.html | 2 +- ...ocumentationTitleToAnchorSlug1Standard.xml | 7 ++ ...ocumentationTitleToAnchorSlug2Standard.xml | 8 ++ ...ocumentationTitleToAnchorSlug3Standard.xml | 8 ++ .../DocumentationTitleToAnchorSlug1Sniff.php | 12 ++ .../DocumentationTitleToAnchorSlug2Sniff.php | 12 ++ .../DocumentationTitleToAnchorSlug3Sniff.php | 12 ++ tests/Core/Generators/HTMLTest.php | 26 +++++ 37 files changed, 268 insertions(+), 42 deletions(-) create mode 100644 tests/Core/Generators/AnchorLinksTest.xml create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleToAnchorSlug.html create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug1Standard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug2Standard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug3Standard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/DocumentationTitleToAnchorSlug1Sniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/DocumentationTitleToAnchorSlug2Sniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/DocumentationTitleToAnchorSlug3Sniff.php diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index cf0bd43162..4e63e4fc0a 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -113,6 +113,13 @@ class HTML extends Generator } '; + /** + * List of seen slugified anchors to ensure uniqueness. + * + * @var array + */ + private $seenAnchors = []; + /** * Generates the documentation for a standard. @@ -132,6 +139,10 @@ public function generate() $content = ob_get_contents(); ob_end_clean(); + // Clear anchor cache after Documentation generation. + // The anchor generation for the TOC anchor links will use the same logic, so should end up with the same unique slugs. + $this->seenAnchors = []; + if (trim($content) !== '') { echo $this->getFormattedHeader(); echo $this->getFormattedToc(); @@ -325,7 +336,20 @@ public function processSniff(DOMNode $doc) */ private function titleToAnchor($title) { - return str_replace(' ', '-', $title); + // Slugify the text. + $title = strtolower($title); + $title = preg_replace('`[^a-z0-9\._-]`', '-', $title); + + if (isset($this->seenAnchors[$title]) === true) { + // Try to find a unique anchor for this title. + for ($i = 2; (isset($this->seenAnchors[$title.'-'.$i]) === true); $i++); + $title .= '-'.$i; + } + + // Add to "seen" list. + $this->seenAnchors[$title] = true; + + return $title; }//end titleToAnchor() diff --git a/tests/Core/Generators/AnchorLinksTest.xml b/tests/Core/Generators/AnchorLinksTest.xml new file mode 100644 index 0000000000..0e66fabc9f --- /dev/null +++ b/tests/Core/Generators/AnchorLinksTest.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html index 535031bddc..a51ad92a86 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlankLines.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, blank lines §

    +

    Code Comparison, blank lines §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html index d75506f62b..881bac305f 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonBlockLength.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, block length §

    +

    Code Comparison, block length §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html index 5809ade683..a325def172 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonEncoding.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, char encoding §

    +

    Code Comparison, char encoding §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html index 0c338283cd..b1e83a42b3 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, line length §

    +

    Code Comparison, line length §

    Ensure there is no PHP "Warning: str_repeat(): Second argument has to be greater than or equal to 0".
    Ref: squizlabs/PHP_CodeSniffer#2522

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html index bd2a39c489..dbe9966de5 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleLineWrapping.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Title, line wrapping §

    +

    Code Title, line wrapping §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html index 793e8ae740..65a5a25f31 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Title, whitespace handling §

    +

    Code Title, whitespace handling §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html index 65b07fa703..2640a6bfd6 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleLength.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    This is a very very very very very very very very very very very long title §

    +

    This is a very very very very very very very very very very very long title §

    This is a standard block.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html index b58219a65f..b83b5e6795 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitlePCREFallback.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Documentation Title PCRE Fallback §

    +

    Documentation Title PCRE Fallback §

    Testing the document title can get determined from the sniff name if missing.

    This file name contains an acronym on purpose to test the word splitting.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleToAnchorSlug.html b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleToAnchorSlug.html new file mode 100644 index 0000000000..1d99239917 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputDocumentationTitleToAnchorSlug.html @@ -0,0 +1,107 @@ + + + GeneratorTest Coding Standards + + + +

    GeneratorTest Coding Standards

    +

    Table of Contents

    + +

    URL enc@de non-àscíï chars §

    +

    The documentation title has non-ascii characters, which will be slugified for use in an HTML anchor link.

    +

    URL enc@de non-àscíï chars §

    +

    The documentation title has non-ascii characters, which will be slugified for use in an HTML anchor link.
    +A duplicate anchor link will get a numeric suffix.

    +

    URL enc@de non-àscíï chars §

    +

    The documentation title has non-ascii characters, which will be slugified for use in an HTML anchor link.
    +A duplicate anchor link will get a numeric suffix.

    +
    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    + + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html index c9389e338a..59fcc7eb97 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, mismatched code blocks §

    +

    Code Comparison, mismatched code blocks §

    This doc has two code elements, one only has a title, one has actual code. Unbalanced

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html index e711e8aff0..9f29d6af63 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, missing code element §

    +

    Code Comparison, missing code element §

    This is a standard block.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html index 358cfd2060..35d9144ac9 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, no code §

    +

    Code Comparison, no code §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html index a8c9ba3ef6..b09f3ccf73 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoContent.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, no content §

    +

    Code Comparison, no content §

    This is a standard block.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html index 8400791c47..7ee4bee477 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonOneEmptyCodeElm.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, one empty code element §

    +

    Code Comparison, one empty code element §

    This doc has two code elements, but only one of them has a title and actual code.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html index 7fd5701ecf..4cc553d4c0 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonTwoEmptyCodeElms.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Comparison, two empty code elements §

    +

    Code Comparison, two empty code elements §

    This doc has two code elements, but neither of them contain any information.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html index 1dc6d7b8ac..0efa0572fc 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleEmpty.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Title, empty §

    +

    Code Title, empty §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html index d43389f93d..755f5a18e1 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeTitleMissing.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Code Title, missing §

    +

    Code Title, missing §

    This is a standard block.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html index 1bff43a11e..7d0d9aa554 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleEmpty.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Documentation Title Empty §

    +

    Documentation Title Empty §

    The above "documentation" element has an empty title attribute.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html index 9a374ad696..2f51fd4741 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidDocumentationTitleMissing.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Documentation Title Missing §

    +

    Documentation Title Missing §

    The above "documentation" element is missing the title attribute.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html index 0c48a0fc91..2eecc8ae8c 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Standard Element, no content §

    +

    Standard Element, no content §

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html b/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html index 203885ff0e..798ae63733 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    One Standard Block, No Code §

    +

    One Standard Block, No Code §

    Documentation contains one standard block and no code comparison.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html index b3e0e23412..ceaab32a68 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Standard Element, blank line handling §

    +

    Standard Element, blank line handling §

    There is a blank line at the start of this standard.

    And the above blank line is also deliberate to test part of the logic.

    Let's also end on a blank line to test that too.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html index 260576a7fb..93a77d455c 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Standard Element, handling of HTML tags §

    +

    Standard Element, handling of HTML tags §

    The use of tags in standard descriptions is allowed and their handling should be safeguarded.
    Other tags, like <a href="example.com">link</a>, <b>bold</bold>, <script></script> are not allowed and will be encoded for display when the HTML or Markdown report is used.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html index 0735e5f7c6..8cf7c3419c 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Standard Element, indentation should be ignored §

    +

    Standard Element, indentation should be ignored §

    This line has no indentation.
    This line has 4 spaces indentation.
    This line has 8 spaces indentation.
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html index 6c6cd01814..b9f4038a1f 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Standard Element, line wrapping handling §

    +

    Standard Element, line wrapping handling §

    This line has to be exactly 99 chars to test part of the logic.------------------------------------
    And this line has to be exactly 100 chars.----------------------------------------------------------
    And here we have a line which should start wrapping as it is longer than 100 chars. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pellentesque iaculis enim quis hendrerit. Morbi ultrices in odio pharetra commodo.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html b/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html index 06156a8441..9aa1d6209b 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStructureDocs.html @@ -90,16 +90,16 @@

    GeneratorTest Coding Standards

    Table of Contents

    -

    Code Comparison Only, Missing Standard Block §

    +

    Code Comparison Only, Missing Standard Block §

    Valid: Lorem ipsum dolor sit amet.
    @@ -110,7 +110,7 @@

    Code Comparison Only, Miss

    Valid: Lorem ipsum dolor sit amet.class Comparison {}
    -

    One Standard Block, Code Comparison §

    +

    One Standard Block, Code Comparison §

    Documentation contains one standard block and one code comparison.

    @@ -122,9 +122,9 @@

    One Standard Block, Code Comparison

    class Comparison {}
    -

    One Standard Block, No Code §

    +

    One Standard Block, No Code §

    Documentation contains one standard block and no code comparison.

    -

    One Standard Block, Two Code Comparisons §

    +

    One Standard Block, Two Code Comparisons §

    Documentation contains one standard block and two code comparisons.

    @@ -146,10 +146,10 @@

    One Standard Block, Two Code C

    $a = 10;
    -

    Two Standard Blocks, No Code §

    +

    Two Standard Blocks, No Code §

    This is standard block one.

    This is standard block two.

    -

    Two Standard Blocks, One Code Comparison §

    +

    Two Standard Blocks, One Code Comparison §

    This is standard block one.

    @@ -162,7 +162,7 @@

    Two Standard Blocks, One Code

    This is standard block two.

    -

    Two Standard Blocks, Three Code Comparisons §

    +

    Two Standard Blocks, Three Code Comparisons §

    This is standard block one.

    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html index 87443d1eee..82fe75004f 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    One element correct, one element wrong level §

    +

    One element correct, one element wrong level §

    This is a standard block at the correct level.

    Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
    diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html index 7fb3615ed9..de06568db9 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html @@ -88,7 +88,7 @@

    GeneratorTest Coding Standards

    -

    Superfluous code element §

    +

    Superfluous code element §

    This is a standard block.

    diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug1Standard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug1Standard.xml new file mode 100644 index 0000000000..4edae6918d --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug1Standard.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug2Standard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug2Standard.xml new file mode 100644 index 0000000000..43956e3fc0 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug2Standard.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug3Standard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug3Standard.xml new file mode 100644 index 0000000000..43956e3fc0 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/DocumentationTitleToAnchorSlug3Standard.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/DocumentationTitleToAnchorSlug1Sniff.php b/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/DocumentationTitleToAnchorSlug1Sniff.php new file mode 100644 index 0000000000..472e23648c --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/DocumentationTitleToAnchorSlug1Sniff.php @@ -0,0 +1,12 @@ +assertNotFalse($expected, 'Output expectation file could not be found'); + + // Make the test OS independent. + $expected = str_replace("\n", PHP_EOL, $expected); + $this->expectOutputString($expected); + + $generator = new HTMLDouble($ruleset); + $generator->generate(); + + }//end testAnchorLinks() + + /** * Test the generated footer. *