diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1edb0a6..c1207fb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,12 @@ tests/ParsedownTest.php + tests/CommonMarkTest.php + + + update + + diff --git a/tests/CommonMarkTest.php b/tests/CommonMarkTest.php new file mode 100644 index 0000000..67a41f2 --- /dev/null +++ b/tests/CommonMarkTest.php @@ -0,0 +1,110 @@ + $id, + 'section' => $section, + 'markdown' => $markdown, + 'expectedHtml' => $expectedHtml + ]; + } + } + } + } else { + $this->fail('The CommonMark cache folder ' . $dir . ' is empty or not readable.'); + } + + return $data; + } + + /** + * @group update + * @dataProvider dataUpdate + * @param $id + * @param $section + * @param $markdown + * @param $expectedHtml + */ + public function testUpdateDatabase($id, $section, $markdown, $expectedHtml) + { + parent::testExample($id, $section, $markdown, $expectedHtml); + + // you can only get here when the test passes + $dir = static::getDataDir(true); + $basename = $id . '-' . \preg_replace('/[^\w-.]/', '_', $section); + \file_put_contents($dir . $basename . '.md', $markdown); + \file_put_contents($dir . $basename . '.html', $expectedHtml); + } + + /** + * @return array + */ + public function dataUpdate() + { + return parent::data(); + } + + public static function getDataDir($mkdir = false) + { + $dir = __DIR__ . '/commonmark/'; + + if ($mkdir) { + if (!\file_exists($dir)) { + @\mkdir($dir); + } + if (!\is_dir($dir)) { + static::fail('Unable to create CommonMark cache folder ' . $dir . '.'); + } + } + + return $dir; + } +}