From 3f33a50bc30ad101c79cce94a7395ea6556062c3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 Nov 2024 09:57:22 +0100 Subject: [PATCH] Generators: add tests for handling element This adds dedicated tests for specific issues which can be encountered in a `` XML element. This initial set of tests for this documents the current behaviour. This behaviour may not always be the desired behaviour, in which case, this will be fixed in follow-up commits. --- .../ExpectedOutputStandardBlankLines.html | 82 +++++++++++++++++++ .../ExpectedOutputStandardBlankLines.md | 10 +++ .../ExpectedOutputStandardBlankLines.txt | 11 +++ .../ExpectedOutputStandardEncoding.html | 79 ++++++++++++++++++ .../ExpectedOutputStandardEncoding.md | 7 ++ .../ExpectedOutputStandardEncoding.txt | 9 ++ .../ExpectedOutputStandardIndent.html | 81 ++++++++++++++++++ .../ExpectedOutputStandardIndent.md | 9 ++ .../ExpectedOutputStandardIndent.txt | 10 +++ .../ExpectedOutputStandardLineWrapping.html | 80 ++++++++++++++++++ .../ExpectedOutputStandardLineWrapping.md | 8 ++ .../ExpectedOutputStandardLineWrapping.txt | 11 +++ .../Content/StandardBlankLinesStandard.xml | 13 +++ .../Docs/Content/StandardEncodingStandard.xml | 8 ++ .../Docs/Content/StandardIndentStandard.xml | 10 +++ .../Content/StandardLineWrappingStandard.xml | 9 ++ .../Content/StandardBlankLinesSniff.php | 12 +++ .../Sniffs/Content/StandardEncodingSniff.php | 12 +++ .../Sniffs/Content/StandardIndentSniff.php | 12 +++ .../Content/StandardLineWrappingSniff.php | 12 +++ tests/Core/Generators/HTMLTest.php | 20 ++++- tests/Core/Generators/MarkdownTest.php | 20 ++++- tests/Core/Generators/TextTest.php | 20 ++++- 23 files changed, 539 insertions(+), 6 deletions(-) create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.txt create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.txt create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.txt create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.txt create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardBlankLinesStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardEncodingStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardIndentStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardLineWrappingStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardBlankLinesSniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardEncodingSniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardIndentSniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardLineWrappingSniff.php diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html new file mode 100644 index 0000000000..5c6539d0ca --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html @@ -0,0 +1,82 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

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/ExpectedOutputStandardBlankLines.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md new file mode 100644 index 0000000000..43ba99d2db --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md @@ -0,0 +1,10 @@ +# GeneratorTest Coding Standard + +## 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. + +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.txt b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.txt new file mode 100644 index 0000000000..1cdad0b11a --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.txt @@ -0,0 +1,11 @@ + +------------------------------------------------------------------------ +| GENERATORTEST CODING STANDARD: 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 new file mode 100644 index 0000000000..5b1c8ca3c3 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.html @@ -0,0 +1,79 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

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.

+
+ + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md new file mode 100644 index 0000000000..f04de7f096 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md @@ -0,0 +1,7 @@ +# GeneratorTest Coding Standard + +## 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*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.txt b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.txt new file mode 100644 index 0000000000..a464b86e29 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.txt @@ -0,0 +1,9 @@ + +-------------------------------------------------------------------------- +| GENERATORTEST CODING STANDARD: STANDARD ELEMENT, HANDLING OF HTML TAGS | +-------------------------------------------------------------------------- + +The use of *tags* in standard descriptions is allowed and their handling should be *safeguarded*. +Other tags, like link, bold, are not allowed +and will be encoded for display when the HTML or Markdown report is used. + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html new file mode 100644 index 0000000000..4c4bcb54ac --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.html @@ -0,0 +1,81 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

Standard Element, indentation should be ignored

+

This line has no indentation. + This line has 4 spaces indentation. + This line has 8 spaces indentation. + This line has 4 spaces indentation.

+
+ + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md new file mode 100644 index 0000000000..77c7244a12 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md @@ -0,0 +1,9 @@ +# GeneratorTest Coding Standard + +## Standard Element, indentation should be ignored +This line has no indentation. + This line has 4 spaces indentation. + This line has 8 spaces indentation. + This line has 4 spaces indentation. + +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.txt b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.txt new file mode 100644 index 0000000000..fef00b9dc9 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.txt @@ -0,0 +1,10 @@ + +---------------------------------------------------------------------------------- +| GENERATORTEST CODING STANDARD: STANDARD ELEMENT, INDENTATION SHOULD BE IGNORED | +---------------------------------------------------------------------------------- + +This line has no indentation. +This line has 4 spaces indentation. +This line has 8 spaces indentation. +This line has 4 spaces indentation. + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html new file mode 100644 index 0000000000..8ca982efc1 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.html @@ -0,0 +1,80 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

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/ExpectedOutputStandardLineWrapping.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md new file mode 100644 index 0000000000..68703400cc --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md @@ -0,0 +1,8 @@ +# GeneratorTest Coding Standard + +## 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. + +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.txt b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.txt new file mode 100644 index 0000000000..6f09fbe335 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.txt @@ -0,0 +1,11 @@ + +--------------------------------------------------------------------------- +| GENERATORTEST CODING STANDARD: 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/Fixtures/StandardWithDocs/Docs/Content/StandardBlankLinesStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardBlankLinesStandard.xml new file mode 100644 index 0000000000..10c47bf46a --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardBlankLinesStandard.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardEncodingStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardEncodingStandard.xml new file mode 100644 index 0000000000..3e34c3f9f7 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardEncodingStandard.xml @@ -0,0 +1,8 @@ + + + tags in standard descriptions is allowed and their handling should be safeguarded. + Other tags, like link, bold, are not allowed and will be encoded for display when the HTML or Markdown report is used. + ]]> + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardIndentStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardIndentStandard.xml new file mode 100644 index 0000000000..b2ec6c5e3c --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardIndentStandard.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardLineWrappingStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardLineWrappingStandard.xml new file mode 100644 index 0000000000..66bbb96275 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Content/StandardLineWrappingStandard.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardBlankLinesSniff.php b/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardBlankLinesSniff.php new file mode 100644 index 0000000000..dfd4b57001 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Content/StandardBlankLinesSniff.php @@ -0,0 +1,12 @@ + [ + 'Documentation title: case' => [ 'sniffs' => 'StandardWithDocs.Content.DocumentationTitleCase', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputDocumentationTitleCase.html', ], - 'Documentation title: length' => [ + 'Documentation title: length' => [ 'sniffs' => 'StandardWithDocs.Content.DocumentationTitleLength', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputDocumentationTitleLength.html', ], + 'Standard Element: blank line handling' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardBlankLines', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardBlankLines.html', + ], + 'Standard Element: encoding of special characters' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardEncoding', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardEncoding.html', + ], + 'Standard Element: indent handling' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardIndent', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardIndent.html', + ], + 'Standard Element: line wrapping' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardLineWrapping', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardLineWrapping.html', + ], ]; }//end dataDocSpecifics() diff --git a/tests/Core/Generators/MarkdownTest.php b/tests/Core/Generators/MarkdownTest.php index b7ba2f5fb1..c93beb4416 100644 --- a/tests/Core/Generators/MarkdownTest.php +++ b/tests/Core/Generators/MarkdownTest.php @@ -125,14 +125,30 @@ public function testDocSpecifics($sniffs, $pathToExpected) public static function dataDocSpecifics() { return [ - 'Documentation title: case' => [ + 'Documentation title: case' => [ 'sniffs' => 'StandardWithDocs.Content.DocumentationTitleCase', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputDocumentationTitleCase.md', ], - 'Documentation title: length' => [ + 'Documentation title: length' => [ 'sniffs' => 'StandardWithDocs.Content.DocumentationTitleLength', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputDocumentationTitleLength.md', ], + 'Standard Element: blank line handling' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardBlankLines', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardBlankLines.md', + ], + 'Standard Element: encoding of special characters' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardEncoding', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardEncoding.md', + ], + 'Standard Element: indent handling' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardIndent', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardIndent.md', + ], + 'Standard Element: line wrapping' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardLineWrapping', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardLineWrapping.md', + ], ]; }//end dataDocSpecifics() diff --git a/tests/Core/Generators/TextTest.php b/tests/Core/Generators/TextTest.php index f571aff71d..d9740bda22 100644 --- a/tests/Core/Generators/TextTest.php +++ b/tests/Core/Generators/TextTest.php @@ -125,14 +125,30 @@ public function testDocSpecifics($sniffs, $pathToExpected) public static function dataDocSpecifics() { return [ - 'Documentation title: case' => [ + 'Documentation title: case' => [ 'sniffs' => 'StandardWithDocs.Content.DocumentationTitleCase', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputDocumentationTitleCase.txt', ], - 'Documentation title: length' => [ + 'Documentation title: length' => [ 'sniffs' => 'StandardWithDocs.Content.DocumentationTitleLength', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputDocumentationTitleLength.txt', ], + 'Standard Element: blank line handling' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardBlankLines', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardBlankLines.txt', + ], + 'Standard Element: encoding of special characters' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardEncoding', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardEncoding.txt', + ], + 'Standard Element: indent handling' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardIndent', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardIndent.txt', + ], + 'Standard Element: line wrapping' => [ + 'sniffs' => 'StandardWithDocs.Content.StandardLineWrapping', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputStandardLineWrapping.txt', + ], ]; }//end dataDocSpecifics()