Skip to content

Commit c62365a

Browse files
committed
improve extensibility of test case
1 parent bb7a3f4 commit c62365a

3 files changed

Lines changed: 134 additions & 108 deletions

File tree

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit bootstrap="test/bootstrap.php" colors="true">
33
<testsuites>
44
<testsuite>
5-
<file>test/Test.php</file>
5+
<file>test/ParsedownTest.php</file>
66
</testsuite>
77
</testsuites>
88
</phpunit>

test/ParsedownTest.php

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
class ParsedownTest extends PHPUnit_Framework_TestCase
4+
{
5+
final function __construct($name = null, array $data = array(), $dataName = '')
6+
{
7+
$this->dirs = $this->initDirs();
8+
$this->Parsedown = $this->initParsedown();
9+
10+
parent::__construct($name, $data, $dataName);
11+
}
12+
13+
private $dirs, $Parsedown;
14+
15+
/**
16+
* @return array
17+
*/
18+
protected function initDirs()
19+
{
20+
$dirs []= dirname(__FILE__).'/data/';
21+
22+
return $dirs;
23+
}
24+
25+
/**
26+
* @return Parsedown
27+
*/
28+
protected function initParsedown()
29+
{
30+
$Parsedown = new Parsedown();
31+
32+
return $Parsedown;
33+
}
34+
35+
/**
36+
* @dataProvider data
37+
* @param $test
38+
* @param $dir
39+
*/
40+
function test_($test, $dir)
41+
{
42+
$markdown = file_get_contents($dir . $test . '.md');
43+
44+
$expectedMarkup = file_get_contents($dir . $test . '.html');
45+
46+
$expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
47+
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
48+
49+
$actualMarkup = $this->Parsedown->text($markdown);
50+
51+
$this->assertEquals($expectedMarkup, $actualMarkup);
52+
}
53+
54+
function data()
55+
{
56+
$data = array();
57+
58+
foreach ($this->dirs as $dir)
59+
{
60+
$Folder = new DirectoryIterator($dir);
61+
62+
foreach ($Folder as $File)
63+
{
64+
/** @var $File DirectoryIterator */
65+
66+
if ( ! $File->isFile())
67+
{
68+
continue;
69+
}
70+
71+
$filename = $File->getFilename();
72+
73+
$extension = pathinfo($filename, PATHINFO_EXTENSION);
74+
75+
if ($extension !== 'md')
76+
{
77+
continue;
78+
}
79+
80+
$basename = $File->getBasename('.md');
81+
82+
if (file_exists($dir . $basename . '.html'))
83+
{
84+
$data []= array($basename, $dir);
85+
}
86+
}
87+
}
88+
89+
return $data;
90+
}
91+
92+
public function test_no_markup()
93+
{
94+
$markdownWithHtml = <<<MARKDOWN_WITH_MARKUP
95+
<div>_content_</div>
96+
97+
sparse:
98+
99+
<div>
100+
<div class="inner">
101+
_content_
102+
</div>
103+
</div>
104+
105+
paragraph
106+
107+
<style type="text/css">
108+
p {
109+
color: red;
110+
}
111+
</style>
112+
MARKDOWN_WITH_MARKUP;
113+
114+
$expectedHtml = <<<EXPECTED_HTML
115+
<p>&lt;div><em>content</em>&lt;/div></p>
116+
<p>sparse:</p>
117+
<p>&lt;div>
118+
&lt;div class="inner">
119+
<em>content</em>
120+
&lt;/div>
121+
&lt;/div></p>
122+
<p>paragraph</p>
123+
<p>&lt;style type="text/css"></p>
124+
<pre><code>p {
125+
color: red;
126+
}</code></pre>
127+
<p>&lt;/style></p>
128+
EXPECTED_HTML;
129+
$parsedownWithNoMarkup = new Parsedown();
130+
$parsedownWithNoMarkup->setMarkupEscaped(true);
131+
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
132+
}
133+
}

test/Test.php

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)