dirs = $this->initDirs();
parent::__construct($name, $data, $dataName);
}
private $dirs;
protected $Parsedown;
/**
* @return array
*/
protected function initDirs()
{
$dirs []= \dirname(__FILE__).'/data/';
return $dirs;
}
/**
* @dataProvider data
* @param $test
* @param $dir
*/
public 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);
$Parsedown = new Parsedown(new State([
new SafeMode(\substr($test, 0, 3) === 'xss'),
new StrictMode(\substr($test, 0, 6) === 'strict'),
new Breaks(\substr($test, 0, 14) === 'breaks_enabled'),
]));
$actualMarkup = $Parsedown->text($markdown);
$this->assertEquals($expectedMarkup, $actualMarkup);
}
public function data()
{
$data = [];
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 []= [$basename, $dir];
}
}
}
return $data;
}
public function test_no_markup()
{
$markdownWithHtml = <<
sparse:
<div> <div class="inner"> content </div> </div>
paragraph
<style type="text/css"> p { color: red; } </style>
comment
<!-- html comment -->
EXPECTED_HTML; $parsedownWithNoMarkup = new Parsedown(new State([ BlockTypes::initial()->removing([BlockMarkup::class, Comment::class]), InlineTypes::initial()->removing([InlineMarkup::class]), ])); $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml)); } }