diff --git a/src/Site/Test/LibMarkdown.php b/src/Site/Test/LibMarkdown.php new file mode 100644 index 0000000..a183f13 --- /dev/null +++ b/src/Site/Test/LibMarkdown.php @@ -0,0 +1,234 @@ + true, + 'verboseOutput' => true +]); + +function mkfile(string $body): void { + $post = fopen(ROOT."/blog/dietrannynigger.md", "w"); + fwrite($post, "title: 【】\n"); + fwrite($post, "uuid: ".uuid()."\n"); + fwrite($post, "author: 諏訪子\n"); + fwrite($post, "date: ".date("Y-m-d H:i:s")."\n"); + fwrite($post, "thumbnail: \n"); + fwrite($post, "thumborient: center\n"); + fwrite($post, "category: \n"); + fwrite($post, "----\n"); + fwrite($post, $body); + fclose($post); +} + +function rmfile(): void { + unlink(ROOT."/blog/dietrannynigger.md"); +} + +class Constants { + public const START = "

"; + public const END = "

"; +} + +$test->describe('マークダウン', function($test): void { + + $test->it('メタデータをパーシング出来るはず', function($test): void { + $md = new Markdown('feature-test', '/blog/'); + $test->assertNotNull($md); + + $meta = $md->getMetadata(); + $test->assertNotNull($meta); + + $expect = new \stdClass; + $expect->title = '【マークダウン】関数'; + $expect->uuid = 'a8c04518-4181-4ec6-9ef0-3f88f23b84b6'; + $expect->author = '諏訪子'; + $expect->date = '2025-11-07 20:33:42'; + $expect->thumbnail = 'o_53803618dc1691.28179609-orig.jpg'; + $expect->thumborient = 'center'; + $expect->category = ['test', 'おちんちん', 'でっかいおっぱい']; + $expect->css = ['code', 'blockquote', 'table', 'blink']; + + $test->assertEquals($expect, $meta); + }); + + $test->it('横線はHTMLに交換出来るはず', function($test): void { + mkfile('----'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "
"; + $actual = str_replace("\n", '', trim($body)); + + $test->assertEquals($expect, $actual); + }); + + $test->it('ヘッダーはHTMLに交換出来るはず', function($test): void { + mkfile('# ケロケロ'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "

ケロケロ

"; + $actual = trim($body); + + $test->assertEquals($expect, $actual); + + // --------------- + + mkfile('## ケロケロ'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "

ケロケロ

"; + $actual = trim($body); + + $test->assertEquals($expect, $actual); + + // --------------- + + mkfile('### ケロケロ'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "

ケロケロ

"; + $actual = trim($body); + + $test->assertEquals($expect, $actual); + + // --------------- + + mkfile('#### ケロケロ'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "

ケロケロ

"; + $actual = trim($body); + + $test->assertEquals($expect, $actual); + + // --------------- + + mkfile('##### ケロケロ'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "
ケロケロ
"; + $actual = trim($body); + + $test->assertEquals($expect, $actual); + + // --------------- + + mkfile('###### ケロケロ'); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = "
ケロケロ
"; + $actual = trim($body); + + $test->assertEquals($expect, $actual); + }); + + $test->skip('コメントはHTMLに交換出来るはず', '作成中・・・'); + + $test->it('画像、音楽、動画はHTMLに交換出来るはず', function($test): void { + mkfile("![](https://ass.technicalsuwako.moe/banner.png)\n +![ケロケロ](https://ass.technicalsuwako.moe/banner.png)\n +![ケロケロ#max-width: 200px;](https://ass.technicalsuwako.moe/banner.png)\n +$[audio/ogg](https://ass.technicalsuwako.moe/砕月着信音.ogg)\n +#[video/mp4](https://ass.technicalsuwako.moe/フリーズ.mp4)"); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = '

' + . '

ケロケロ

' + . '

ケロケロ

' + . '

' + . '

'; + $actual = str_replace("\n", '', str_replace(' ', '', trim($body))); + + $test->assertEquals($expect, $actual); + }); + + $test->it('基本的なマークダウンはHTMLに交換出来るはず', function($test): void { + mkfile("**太文字**\n +*イタリック*\n +_下線_\n +~取消線~\n +!:(5)明滅文字:!\n +^(72)フォントサイズ^\n +%(ff00ff)フォントカラー%"); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = '

太文字

' + . '

イタリック

' + . '

下線

' + . '

取消線

' + . '

明滅文字

' + . '

フォントサイズ

' + . '

フォントカラー

'; + $actual = str_replace("\n", '', trim($body)); + + $test->assertEquals($expect, $actual); + }); + + $test->it('複数マークダウンはHTMLに交換出来るはず', function($test): void { + mkfile("[^(500)(すわこ)](https://techsuwako.jp/)^"); + + $md = new Markdown('dietrannynigger', '/blog/'); + $test->assertNotNull($md); + + $body = $md->parse(); + $test->assertNotNull($body); + + $expect = Constants::START.'God(すわこ)'.Constants::END; + $actual = str_replace("\n", '', trim($body)); + + $test->assertEquals($expect, $actual); + }); + + rmfile(); +}); + +$test->printSummary(); \ No newline at end of file