diff --git a/Readme.php b/Readme.php index e473d73..e2db753 100644 --- a/Readme.php +++ b/Readme.php @@ -21,13 +21,13 @@ $html = Markdown::defaultTransform($text); ?> - - PHP Markdown Lib - Readme - - + + PHP Markdown Lib - Readme + + - + diff --git a/composer.json b/composer.json index 6b1993d..28d2b16 100644 --- a/composer.json +++ b/composer.json @@ -22,5 +22,8 @@ }, "autoload": { "psr-4": { "Michelf\\": "Michelf/" } + }, + "require-dev": { + "phpunit/phpunit": "^5.7" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8f2dab5 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + ./test/unit/ + + + ./test/integration/ + + + + + + Michelf + + + diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..a7b3507 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,6 @@ +loadXML('' . + "" . + "$t_result"); + + $document2 = new DOMDocument(); + $doc_output = $document2->loadXML('' . + "" . + "$t_output"); + + if ($doc_result) { + static::normalizeElementContent($document->documentElement, false); + $n_result = $document->saveXML(); + } else { + $n_result = '--- Expected Result: XML Parse Error ---'; + } + if ($doc_output) { + static::normalizeElementContent($document2->documentElement, false); + $n_output = $document2->saveXML(); + } else { + $n_output = '--- Output: XML Parse Error ---'; + } + } else { + + // '@' suppressors used because some tests have invalid HTML (multiple elements with the same id attribute) + // Perhaps isolate to a separate test and remove this? + + $document = new DOMDocument(); + $doc_result = @$document->loadHTML($t_result); + + $document2 = new DOMDocument(); + $doc_output = @$document2->loadHTML($t_output); + + if ($doc_result) { + static::normalizeElementContent($document->documentElement, false); + $n_result = $document->saveHTML(); + } else { + $n_result = '--- Expected Result: HTML Parse Error ---'; + } + + if ($doc_output) { + static::normalizeElementContent($document2->documentElement, false); + $n_output = $document2->saveHTML(); + } else { + $n_output = '--- Output: HTML Parse Error ---'; + } + } + + $n_result = preg_replace('{^.*?|.*?$}is', '', $n_result); + $n_output = preg_replace('{^.*?|.*?$}is', '', $n_output); + + $c_result = $n_result; + $c_output = $n_output; + + $c_result = trim($c_result) . "\n"; + $c_output = trim($c_output) . "\n"; + + // This will throw a test exception if the strings don't exactly match + TestCase::assertSame($c_result, $c_output, $message); + } + + /** + * @param DOMElement $element Modifies this element by reference + * @param bool $whitespace_preserve Preserve Whitespace + * @return void + */ + protected static function normalizeElementContent($element, $whitespace_preserve) { + # + # Normalize content of HTML DOM $element. The $whitespace_preserve + # argument indicates that whitespace is significant and shouldn't be + # normalized; it should be used for the content of certain elements like + #
 or