aboutsummaryrefslogtreecommitdiffstats
path: root/library/parsedown/test/ParsedownTest.php
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-05-21 14:56:42 -0400
committerAndrew Manning <tamanning@zoho.com>2016-05-21 14:56:42 -0400
commitc6aa42773a17d53b4572488967b99666ab97ef97 (patch)
tree8ba4a4071c3a8941e7d851ad80d48cee9c3f71bd /library/parsedown/test/ParsedownTest.php
parent4979a451207c7072785c114a09fdd394f2a97734 (diff)
downloadvolse-hubzilla-c6aa42773a17d53b4572488967b99666ab97ef97.tar.gz
volse-hubzilla-c6aa42773a17d53b4572488967b99666ab97ef97.tar.bz2
volse-hubzilla-c6aa42773a17d53b4572488967b99666ab97ef97.zip
Trying to fix wiki branch starting fresh from dev
Diffstat (limited to 'library/parsedown/test/ParsedownTest.php')
-rw-r--r--library/parsedown/test/ParsedownTest.php159
1 files changed, 159 insertions, 0 deletions
diff --git a/library/parsedown/test/ParsedownTest.php b/library/parsedown/test/ParsedownTest.php
new file mode 100644
index 000000000..c922ab1f2
--- /dev/null
+++ b/library/parsedown/test/ParsedownTest.php
@@ -0,0 +1,159 @@
+<?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>&lt;div&gt;<em>content</em>&lt;/div&gt;</p>
+<p>sparse:</p>
+<p>&lt;div&gt;
+&lt;div class=&quot;inner&quot;&gt;
+<em>content</em>
+&lt;/div&gt;
+&lt;/div&gt;</p>
+<p>paragraph</p>
+<p>&lt;style type=&quot;text/css&quot;&gt;
+p {
+color: red;
+}
+&lt;/style&gt;</p>
+<p>comment</p>
+<p>&lt;!-- html comment --&gt;</p>
+EXPECTED_HTML;
+ $parsedownWithNoMarkup = new Parsedown();
+ $parsedownWithNoMarkup->setMarkupEscaped(true);
+ $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
+ }
+
+ public function testLateStaticBinding()
+ {
+ include 'test/TestParsedown.php';
+
+ $parsedown = Parsedown::instance();
+ $this->assertInstanceOf('Parsedown', $parsedown);
+
+ // After instance is already called on Parsedown
+ // subsequent calls with the same arguments return the same instance
+ $sameParsedown = TestParsedown::instance();
+ $this->assertInstanceOf('Parsedown', $sameParsedown);
+ $this->assertSame($parsedown, $sameParsedown);
+
+ $testParsedown = TestParsedown::instance('test late static binding');
+ $this->assertInstanceOf('TestParsedown', $testParsedown);
+
+ $sameInstanceAgain = TestParsedown::instance('test late static binding');
+ $this->assertSame($testParsedown, $sameInstanceAgain);
+ }
+}