2017-11-11 07:22:27 +01:00
|
|
|
<?php
|
2018-09-27 10:13:43 +02:00
|
|
|
|
|
|
|
namespace Todaymade\Daux\Format\HTML\Test;
|
2017-01-09 17:35:13 +01:00
|
|
|
|
|
|
|
use Todaymade\Daux\Config as MainConfig;
|
|
|
|
use \Todaymade\Daux\Format\HTML\ContentTypes\Markdown\CommonMarkConverter;
|
2017-11-11 07:22:27 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-01-09 17:35:13 +01:00
|
|
|
|
2017-12-11 22:02:20 +01:00
|
|
|
class Engine {
|
|
|
|
function render($template, $data) {
|
|
|
|
return $data['content'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Template {
|
|
|
|
function getEngine() {
|
|
|
|
return new Engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 07:22:27 +01:00
|
|
|
class TableOfContentsTest extends TestCase
|
2017-01-09 17:35:13 +01:00
|
|
|
{
|
2017-12-11 22:02:20 +01:00
|
|
|
function getConfig() {
|
|
|
|
$config = new MainConfig;
|
|
|
|
$config->templateRenderer = new Template;
|
|
|
|
|
|
|
|
return ['daux' => $config];
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:35:13 +01:00
|
|
|
function testNoTOCByDefault() {
|
2017-12-11 22:02:20 +01:00
|
|
|
$converter = new CommonMarkConverter($this->getConfig());
|
2017-01-09 17:35:13 +01:00
|
|
|
|
|
|
|
$this->assertEquals("<h1 id=\"page_Test\">Test</h1>\n", $converter->convertToHtml('# Test'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTOCToken() {
|
2017-12-11 22:02:20 +01:00
|
|
|
$converter = new CommonMarkConverter($this->getConfig());
|
2017-01-09 17:35:13 +01:00
|
|
|
|
|
|
|
$source = "[TOC]\n# Title";
|
|
|
|
$expected = <<<EXPECTED
|
|
|
|
<ul class="TableOfContents">
|
|
|
|
<li>
|
|
|
|
<p><a href="#page_Title">Title</a></p>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<h1 id="page_Title">Title</h1>
|
|
|
|
|
|
|
|
EXPECTED;
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $converter->convertToHtml($source));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnicodeTOC() {
|
2017-12-11 22:02:20 +01:00
|
|
|
$converter = new CommonMarkConverter($this->getConfig());
|
2017-01-09 17:35:13 +01:00
|
|
|
|
2017-05-18 23:43:02 +02:00
|
|
|
$source = "[TOC]\n# 基础操作\n# 操作基础";
|
2017-01-09 17:35:13 +01:00
|
|
|
$expected = <<<EXPECTED
|
|
|
|
<ul class="TableOfContents">
|
|
|
|
<li>
|
2019-12-29 20:41:13 +01:00
|
|
|
<p><a href="#page_ji_chu_cao_zuo">基础操作</a></p>
|
2017-05-18 23:43:02 +02:00
|
|
|
</li>
|
|
|
|
<li>
|
2019-12-29 20:41:13 +01:00
|
|
|
<p><a href="#page_cao_zuo_ji_chu">操作基础</a></p>
|
2017-05-18 23:43:02 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
2019-12-29 20:41:13 +01:00
|
|
|
<h1 id="page_ji_chu_cao_zuo">基础操作</h1>
|
|
|
|
<h1 id="page_cao_zuo_ji_chu">操作基础</h1>
|
2017-05-18 23:43:02 +02:00
|
|
|
|
|
|
|
EXPECTED;
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $converter->convertToHtml($source));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDuplicatedTOC() {
|
2017-12-11 22:02:20 +01:00
|
|
|
$converter = new CommonMarkConverter($this->getConfig());
|
2017-05-18 23:43:02 +02:00
|
|
|
|
|
|
|
$source = "[TOC]\n# Test\n# Test";
|
|
|
|
$expected = <<<EXPECTED
|
|
|
|
<ul class="TableOfContents">
|
|
|
|
<li>
|
|
|
|
<p><a href="#page_Test">Test</a></p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<p><a href="#page_Test-2">Test</a></p>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<h1 id="page_Test">Test</h1>
|
|
|
|
<h1 id="page_Test-2">Test</h1>
|
|
|
|
|
|
|
|
EXPECTED;
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $converter->convertToHtml($source));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testEscapedTOC() {
|
2017-12-11 22:02:20 +01:00
|
|
|
$converter = new CommonMarkConverter($this->getConfig());
|
2017-05-18 23:43:02 +02:00
|
|
|
|
|
|
|
$source = "[TOC]\n# TEST : Test";
|
|
|
|
$expected = <<<EXPECTED
|
|
|
|
<ul class="TableOfContents">
|
|
|
|
<li>
|
2019-12-29 20:41:13 +01:00
|
|
|
<p><a href="#page_TEST_Test">TEST : Test</a></p>
|
2017-01-09 17:35:13 +01:00
|
|
|
</li>
|
|
|
|
</ul>
|
2019-12-29 20:41:13 +01:00
|
|
|
<h1 id="page_TEST_Test">TEST : Test</h1>
|
2017-01-09 17:35:13 +01:00
|
|
|
|
|
|
|
EXPECTED;
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $converter->convertToHtml($source));
|
|
|
|
}
|
|
|
|
}
|