diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-06 06:41:47 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-06 06:41:47 -0500 |
commit | c80c15dcc33a70acc2b177691d33f088f8c2541e (patch) | |
tree | bc3e44e35b97b751c145cc5797a0faf356922244 /vendor/erusev/parsedown/test/ParsedownTest.php | |
parent | c91ff61cdfa8b5eb76783927e5b8710f2a9f2601 (diff) |
Include all vendor files in the repo to be easier for people
Diffstat (limited to 'vendor/erusev/parsedown/test/ParsedownTest.php')
-rw-r--r-- | vendor/erusev/parsedown/test/ParsedownTest.php | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/vendor/erusev/parsedown/test/ParsedownTest.php b/vendor/erusev/parsedown/test/ParsedownTest.php new file mode 100644 index 00000000..d094f2da --- /dev/null +++ b/vendor/erusev/parsedown/test/ParsedownTest.php @@ -0,0 +1,139 @@ +<?php + +class ParsedownTest extends PHPUnit_Framework_TestCase +{ + final function __construct($name = null, array $data = array(), $dataName = '') + { + $this->dirs = $this->initDirs(); + $this->Parsedown = $this->initParsedown(); + + parent::__construct($name, $data, $dataName); + } + + private $dirs, $Parsedown; + + /** + * @return array + */ + protected function initDirs() + { + $dirs []= dirname(__FILE__).'/data/'; + + return $dirs; + } + + /** + * @return Parsedown + */ + protected function initParsedown() + { + $Parsedown = new Parsedown(); + + return $Parsedown; + } + + /** + * @dataProvider data + * @param $test + * @param $dir + */ + function test_($test, $dir) + { + $markdown = file_get_contents($dir . $test . '.md'); + + $expectedMarkup = file_get_contents($dir . $test . '.html'); + + $expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup); + $expectedMarkup = str_replace("\r", "\n", $expectedMarkup); + + $actualMarkup = $this->Parsedown->text($markdown); + + $this->assertEquals($expectedMarkup, $actualMarkup); + } + + function data() + { + $data = array(); + + foreach ($this->dirs as $dir) + { + $Folder = new DirectoryIterator($dir); + + foreach ($Folder as $File) + { + /** @var $File DirectoryIterator */ + + if ( ! $File->isFile()) + { + continue; + } + + $filename = $File->getFilename(); + + $extension = pathinfo($filename, PATHINFO_EXTENSION); + + if ($extension !== 'md') + { + continue; + } + + $basename = $File->getBasename('.md'); + + if (file_exists($dir . $basename . '.html')) + { + $data []= array($basename, $dir); + } + } + } + + return $data; + } + + public function test_no_markup() + { + $markdownWithHtml = <<<MARKDOWN_WITH_MARKUP +<div>_content_</div> + +sparse: + +<div> +<div class="inner"> +_content_ +</div> +</div> + +paragraph + +<style type="text/css"> + p { + color: red; + } +</style> + +comment + +<!-- html comment --> +MARKDOWN_WITH_MARKUP; + + $expectedHtml = <<<EXPECTED_HTML +<p><div><em>content</em></div></p> +<p>sparse:</p> +<p><div> +<div class="inner"> +<em>content</em> +</div> +</div></p> +<p>paragraph</p> +<p><style type="text/css"></p> +<pre><code>p { + color: red; +}</code></pre> +<p></style></p> +<p>comment</p> +<p><!-- html comment --></p> +EXPECTED_HTML; + $parsedownWithNoMarkup = new Parsedown(); + $parsedownWithNoMarkup->setMarkupEscaped(true); + $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml)); + } +} |