diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index 681699ba65..4e63e4fc0a 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%; } @@ -100,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. @@ -119,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(); @@ -215,7 +239,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,14 +314,46 @@ 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; } }//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) + { + // 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() + + /** * Print a text block found in a standard. * 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 7726809fea..a51ad92a86 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..881bac305f 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..a325def172 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..b1e83a42b3 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..dbe9966de5 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..65a5a25f31 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..2640a6bfd6 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..b83b5e6795 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/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 3176ce9dee..59fcc7eb97 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..9f29d6af63 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..35d9144ac9 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..b09f3ccf73 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..7ee4bee477 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..4cc553d4c0 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..0efa0572fc 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..755f5a18e1 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..7d0d9aa554 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..2f51fd4741 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..2eecc8ae8c 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..798ae63733 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..ceaab32a68 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..93a77d455c 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..8cf7c3419c 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..b9f4038a1f 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..9aa1d6209b 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%; } @@ -77,17 +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.
@@ -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..82fe75004f 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..de06568db9 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.

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. *