2014-09-26 03:04:25 +04:00
|
|
|
<?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>
|
2014-10-10 22:07:41 +04:00
|
|
|
|
|
|
|
comment
|
|
|
|
|
|
|
|
<!-- html comment -->
|
2014-09-26 03:04:25 +04:00
|
|
|
MARKDOWN_WITH_MARKUP;
|
|
|
|
|
|
|
|
$expectedHtml = <<<EXPECTED_HTML
|
2014-12-03 00:53:19 +03:00
|
|
|
<p><div><em>content</em></div></p>
|
2014-09-26 03:04:25 +04:00
|
|
|
<p>sparse:</p>
|
2014-12-03 00:53:19 +03:00
|
|
|
<p><div>
|
2014-12-15 01:56:22 +03:00
|
|
|
<div class="inner">
|
2014-09-26 03:04:25 +04:00
|
|
|
<em>content</em>
|
2014-12-03 00:53:19 +03:00
|
|
|
</div>
|
|
|
|
</div></p>
|
2014-09-26 03:04:25 +04:00
|
|
|
<p>paragraph</p>
|
2014-12-15 01:56:22 +03:00
|
|
|
<p><style type="text/css">
|
2014-12-15 01:52:03 +03:00
|
|
|
p {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
</style></p>
|
2014-10-10 22:07:41 +04:00
|
|
|
<p>comment</p>
|
2014-12-03 00:53:19 +03:00
|
|
|
<p><!-- html comment --></p>
|
2014-09-26 03:04:25 +04:00
|
|
|
EXPECTED_HTML;
|
|
|
|
$parsedownWithNoMarkup = new Parsedown();
|
|
|
|
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
|
|
|
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
|
|
|
}
|
2015-07-20 17:30:15 +03:00
|
|
|
|
|
|
|
public function testLateStaticBinding()
|
|
|
|
{
|
2016-11-01 20:27:37 +03:00
|
|
|
include __DIR__ . '/TestParsedown.php';
|
2015-07-20 17:30:15 +03:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
2014-09-26 03:04:25 +04:00
|
|
|
}
|