rhymix/common/vendor/michelf/php-markdown/test/integration/PhpMarkdownTest.php
Kijin Sung 5fff6b6eab Move all composer files inside the common directory
- 2022년 3월 개발팀 결정사항 적용
- 모듈 등 서드파티 자료 개발시 composer를 사용하면 상위 경로에 있는 코어의
  composer.json을 수정하고, 코어의 vendor 디렉토리를 건드리는 것이 기본값임
- 이를 방지하기 위해 코어의 composer.json과 vendor를 common 디렉토리 안으로
  이동하여, 모듈 경로에서 상위 폴더로 인식하지 않도록 함
2022-12-26 16:33:32 +09:00

173 lines
4.6 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
use Michelf\Markdown;
use Michelf\MarkdownExtra;
class PhpMarkdownTest extends TestCase
{
/**
* Returns all php-markdown.mdtest tests
* @return array
*/
public function dataProviderForPhpMarkdown() {
$dir = TEST_RESOURCES_ROOT . '/php-markdown.mdtest';
return MarkdownTestHelper::getInputOutputPaths($dir);
}
/**
* Runs php-markdown.mdtest against Markdown::defaultTransform
*
* @dataProvider dataProviderForPhpMarkdown
*
* @param string $inputPath Input markdown path
* @param string $htmlPath File path of expected transformed output (X)HTML
*
* @param bool $xhtml True if XHTML. Otherwise, HTML is assumed.
*
* @return void
*/
public function testTransformingOfPhpMarkdown($inputPath, $htmlPath, $xhtml = false) {
$inputMarkdown = file_get_contents($inputPath);
$expectedHtml = file_get_contents($htmlPath);
$result = Markdown::defaultTransform($inputMarkdown);
MarkdownTestHelper::assertSameNormalized(
$expectedHtml,
$result,
"Markdown in $inputPath converts exactly to expected $htmlPath",
$xhtml
);
}
/**
* Returns all php-markdown.mdtest tests EXCEPT Emphasis test.
* @return array
*/
public function dataProviderForPhpMarkdownExceptEmphasis()
{
$dir = TEST_RESOURCES_ROOT . '/php-markdown.mdtest';
$allTests = MarkdownTestHelper::getInputOutputPaths($dir);
foreach ($allTests as $index => $test) {
// Because MarkdownExtra treats underscore emphasis differently, this one test has to be excluded
if (preg_match('~/Emphasis\.text$~', $test[0])) {
unset($allTests[$index]);
}
}
return array_values($allTests);
}
/**
* Runs php-markdown.mdtest against MarkdownExtra::defaultTransform
*
* @dataProvider dataProviderForPhpMarkdownExceptEmphasis
*
* @param $inputPath
* @param $htmlPath
* @param bool $xhtml
*/
public function testPhpMarkdownMdTestWithMarkdownExtra($inputPath, $htmlPath, $xhtml = false)
{
$inputMarkdown = file_get_contents($inputPath);
$expectedHtml = file_get_contents($htmlPath);
$result = MarkdownExtra::defaultTransform($inputMarkdown);
MarkdownTestHelper::assertSameNormalized(
$expectedHtml,
$result,
"Markdown in $inputPath converts exactly to expected $htmlPath",
$xhtml
);
}
/**
* @return array
*/
public function dataProviderForMarkdownExtra() {
$dir = TEST_RESOURCES_ROOT . '/php-markdown-extra.mdtest';
return MarkdownTestHelper::getInputOutputPaths($dir);
}
/**
* @dataProvider dataProviderForMarkdownExtra
*
* @param string $inputPath Input markdown path
* @param string $htmlPath File path of expected transformed output (X)HTML
*
* @param bool $xhtml True if XHTML. Otherwise, HTML is assumed.
*
* @return void
*/
public function testTransformingOfMarkdownExtra($inputPath, $htmlPath, $xhtml = false) {
$inputMarkdown = file_get_contents($inputPath);
$expectedHtml = file_get_contents($htmlPath);
$result = MarkdownExtra::defaultTransform($inputMarkdown);
MarkdownTestHelper::assertSameNormalized(
$expectedHtml,
$result,
"Markdown in $inputPath converts exactly to expected $htmlPath",
$xhtml
);
}
/**
* @return array
*/
public function dataProviderForRegularMarkdown()
{
$dir = TEST_RESOURCES_ROOT . '/markdown.mdtest';
return MarkdownTestHelper::getInputOutputPaths($dir);
}
/**
* @dataProvider dataProviderForRegularMarkdown
*
* @param string $inputPath Input markdown path
* @param string $htmlPath File path of expected transformed output (X)HTML
*
* @param bool $xhtml True if XHTML. Otherwise, HTML is assumed.
*
* @return void
*/
public function testTransformingOfRegularMarkdown($inputPath, $htmlPath, $xhtml = false)
{
$inputMarkdown = file_get_contents($inputPath);
$expectedHtml = file_get_contents($htmlPath);
$result = Markdown::defaultTransform($inputMarkdown);
MarkdownTestHelper::assertSameNormalized(
$expectedHtml,
$result,
"Markdown in $inputPath converts exactly to expected $htmlPath",
$xhtml
);
}
/**
* Runs markdown.mdtest against MarkdownExtra::defaultTransform
*
* @dataProvider dataProviderForRegularMarkdown
*
* @param $inputPath
* @param $htmlPath
* @param bool $xhtml
*/
public function testMarkdownMdTestWithMarkdownExtra($inputPath, $htmlPath, $xhtml = false)
{
$inputMarkdown = file_get_contents($inputPath);
$expectedHtml = file_get_contents($htmlPath);
$result = MarkdownExtra::defaultTransform($inputMarkdown);
MarkdownTestHelper::assertSameNormalized(
$expectedHtml,
$result,
"Markdown in $inputPath converts exactly to expected $htmlPath",
$xhtml
);
}
}