Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generators: add initial set of tests #671

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ showFound: true
ignores:
- "node_modules/"
- "vendor/"
- "tests/Core/Generators/Expectations/"

# Disable inline config comments.
noInlineConfig: true
Expand Down
7 changes: 6 additions & 1 deletion src/Generators/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* to each sniff.
*
* @author Greg Sherwood <[email protected]>
* @author Juliette Reinders Folmer <[email protected]>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @copyright 2024 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

Expand Down Expand Up @@ -133,7 +135,7 @@ protected function printHeader()
echo '<html>'.PHP_EOL;
echo ' <head>'.PHP_EOL;
echo " <title>$standard Coding Standards</title>".PHP_EOL;
echo ' '.self::STYLESHEET.PHP_EOL;
echo ' '.str_replace("\n", PHP_EOL, self::STYLESHEET).PHP_EOL;
echo ' </head>'.PHP_EOL;
echo ' <body>'.PHP_EOL;
echo " <h1>$standard Coding Standards</h1>".PHP_EOL;
Expand Down Expand Up @@ -226,6 +228,9 @@ protected function printTextBlock(DOMNode $node)
$content = trim($node->nodeValue);
$content = htmlspecialchars($content);

// Use the correct line endings based on the OS.
$content = str_replace("\n", PHP_EOL, $content);

// Allow em tags only.
$content = str_replace('&lt;em&gt;', '<em>', $content);
$content = str_replace('&lt;/em&gt;', '</em>', $content);
Expand Down
9 changes: 7 additions & 2 deletions src/Generators/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* A doc generator that outputs documentation in Markdown format.
*
* @author Stefano Kowalke <[email protected]>
* @author Juliette Reinders Folmer <[email protected]>
* @copyright 2014 Arroba IT
* @copyright 2024 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

Expand Down Expand Up @@ -111,6 +113,9 @@ protected function printTextBlock(DOMNode $node)
$content = trim($node->nodeValue);
$content = htmlspecialchars($content);

// Use the correct line endings based on the OS.
$content = str_replace("\n", PHP_EOL, $content);

$content = str_replace('&lt;em&gt;', '*', $content);
$content = str_replace('&lt;/em&gt;', '*', $content);

Expand All @@ -132,13 +137,13 @@ protected function printCodeComparisonBlock(DOMNode $node)

$firstTitle = $codeBlocks->item(0)->getAttribute('title');
$first = trim($codeBlocks->item(0)->nodeValue);
$first = str_replace("\n", "\n ", $first);
$first = str_replace("\n", PHP_EOL.' ', $first);
$first = str_replace('<em>', '', $first);
$first = str_replace('</em>', '', $first);

$secondTitle = $codeBlocks->item(1)->getAttribute('title');
$second = trim($codeBlocks->item(1)->nodeValue);
$second = str_replace("\n", "\n ", $second);
$second = str_replace("\n", PHP_EOL.' ', $second);
$second = str_replace('<em>', '', $second);
$second = str_replace('</em>', '', $second);

Expand Down
Empty file.
78 changes: 78 additions & 0 deletions tests/Core/Generators/Expectations/ExpectedOutputNoDocs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<html>
<head>
<title>GeneratorTest Coding Standards</title>
<style>
body {
background-color: #FFFFFF;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #000000;
}

h1 {
color: #666666;
font-size: 20px;
font-weight: bold;
margin-top: 0px;
background-color: #E6E7E8;
padding: 20px;
border: 1px solid #BBBBBB;
}

h2 {
color: #00A5E3;
font-size: 16px;
font-weight: normal;
margin-top: 50px;
}

.code-comparison {
width: 100%;
}

.code-comparison td {
border: 1px solid #CCCCCC;
}

.code-comparison-title, .code-comparison-code {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
vertical-align: top;
padding: 4px;
width: 50%;
background-color: #F1F1F1;
line-height: 15px;
}

.code-comparison-code {
font-family: Courier;
background-color: #F9F9F9;
}

.code-comparison-highlight {
background-color: #DDF1F7;
border: 1px solid #00A5E3;
line-height: 15px;
}

.tag-line {
text-align: center;
width: 100%;
margin-top: 30px;
font-size: 12px;
}

.tag-line a {
color: #000000;
}
</style>
</head>
<body>
<h1>GeneratorTest Coding Standards</h1>
<h2>Table of Contents</h2>
<ul class="toc">
</ul>
<div class="tag-line">Documentation generated on #REDACTED# by <a href="https://github.com/PHPCSStandards/PHP_CodeSniffer">PHP_CodeSniffer #VERSION#</a></div>
</body>
</html>
2 changes: 2 additions & 0 deletions tests/Core/Generators/Expectations/ExpectedOutputNoDocs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GeneratorTest Coding Standard
Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer)
82 changes: 82 additions & 0 deletions tests/Core/Generators/Expectations/ExpectedOutputOneDoc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<html>
<head>
<title>GeneratorTest Coding Standards</title>
<style>
body {
background-color: #FFFFFF;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #000000;
}

h1 {
color: #666666;
font-size: 20px;
font-weight: bold;
margin-top: 0px;
background-color: #E6E7E8;
padding: 20px;
border: 1px solid #BBBBBB;
}

h2 {
color: #00A5E3;
font-size: 16px;
font-weight: normal;
margin-top: 50px;
}

.code-comparison {
width: 100%;
}

.code-comparison td {
border: 1px solid #CCCCCC;
}

.code-comparison-title, .code-comparison-code {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
vertical-align: top;
padding: 4px;
width: 50%;
background-color: #F1F1F1;
line-height: 15px;
}

.code-comparison-code {
font-family: Courier;
background-color: #F9F9F9;
}

.code-comparison-highlight {
background-color: #DDF1F7;
border: 1px solid #00A5E3;
line-height: 15px;
}

.tag-line {
text-align: center;
width: 100%;
margin-top: 30px;
font-size: 12px;
}

.tag-line a {
color: #000000;
}
</style>
</head>
<body>
<h1>GeneratorTest Coding Standards</h1>
<h2>Table of Contents</h2>
<ul class="toc">
<li><a href="#One-Standard-Block,-No-Code">One Standard Block, No Code</a></li>
</ul>
<a name="One-Standard-Block,-No-Code" />
<h2>One Standard Block, No Code</h2>
<p class="text">Documentation contains one standard block and no code comparison.</p>
<div class="tag-line">Documentation generated on #REDACTED# by <a href="https://github.com/PHPCSStandards/PHP_CodeSniffer">PHP_CodeSniffer #VERSION#</a></div>
</body>
</html>
5 changes: 5 additions & 0 deletions tests/Core/Generators/Expectations/ExpectedOutputOneDoc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# GeneratorTest Coding Standard

## One Standard Block, No Code
Documentation contains one standard block and no code comparison.
Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer)
7 changes: 7 additions & 0 deletions tests/Core/Generators/Expectations/ExpectedOutputOneDoc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

--------------------------------------------------------------
| GENERATORTEST CODING STANDARD: ONE STANDARD BLOCK, NO CODE |
--------------------------------------------------------------

Documentation contains one standard block and no code comparison.

Loading