389 lines
9.1 KiB
PHP
389 lines
9.1 KiB
PHP
<?php
|
|
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Markdown;
|
|
|
|
/** Test the Markdown.php file */
|
|
class MarkdownTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
// TitleSeText
|
|
public function testTitleSeText1()
|
|
{
|
|
$this->expectOutputString("<h1>test</h1>");
|
|
$md = new Markdown();
|
|
printf($md->html("test\n====\n"), true);
|
|
}
|
|
|
|
public function testTitleSeText2()
|
|
{
|
|
$this->expectOutputString("<h2>test</h2>");
|
|
$md = new Markdown();
|
|
printf($md->html("test\n----\n"), true);
|
|
}
|
|
|
|
// Titles Sharp
|
|
public function testTitleSharp1()
|
|
{
|
|
$this->expectOutputString("<h1>test</h1>");
|
|
$md = new Markdown();
|
|
printf($md->html("# test #"));
|
|
}
|
|
|
|
public function testTitleSharp2()
|
|
{
|
|
$this->expectOutputString("<h2>test</h2>");
|
|
$md = new Markdown();
|
|
printf($md->html("## test ##"));
|
|
}
|
|
|
|
public function testTitleSharp3()
|
|
{
|
|
$this->expectOutputString("<h3>test</h3>");
|
|
$md = new Markdown();
|
|
printf($md->html("### test ###"));
|
|
}
|
|
|
|
public function testTitleSharp4()
|
|
{
|
|
$this->expectOutputString("<h4>test</h4>");
|
|
$md = new Markdown();
|
|
printf($md->html("#### test ####"));
|
|
}
|
|
|
|
public function testTitleSharp5()
|
|
{
|
|
$this->expectOutputString("<h5>test</h5>");
|
|
$md = new Markdown();
|
|
printf($md->html("##### test #####"));
|
|
}
|
|
|
|
public function testTitleSharp6()
|
|
{
|
|
$this->expectOutputString("<h6>test</h6>");
|
|
$md = new Markdown();
|
|
printf($md->html("###### test #######"));
|
|
}
|
|
|
|
// Separator
|
|
public function testSeparator1()
|
|
{
|
|
$this->expectOutputString("<hr/>");
|
|
$md = new Markdown();
|
|
printf($md->html("---\n"), true);
|
|
}
|
|
|
|
public function testSeparator2()
|
|
{
|
|
$this->expectOutputString("<hr/>");
|
|
$md = new Markdown();
|
|
printf($md->html("___\n"), true);
|
|
}
|
|
|
|
public function testSeparator3()
|
|
{
|
|
$this->expectOutputString("<hr/>");
|
|
$md = new Markdown();
|
|
printf($md->html("***\n"), true);
|
|
}
|
|
|
|
public function testSeparator4()
|
|
{
|
|
$this->expectOutputString("<hr/>");
|
|
$md = new Markdown();
|
|
printf($md->html("- - -\n"), true);
|
|
}
|
|
|
|
public function testSeparator5()
|
|
{
|
|
$this->expectOutputString("<hr/>");
|
|
$md = new Markdown();
|
|
printf($md->html("_ _ _\n"), true);
|
|
}
|
|
|
|
public function testSeparator6()
|
|
{
|
|
$this->expectOutputString("<hr/>");
|
|
$md = new Markdown();
|
|
printf($md->html("* * *\n"), true);
|
|
}
|
|
|
|
// Simple Text
|
|
public function testSimpleText()
|
|
{
|
|
$this->expectOutputString("<p>text</p>");
|
|
$md = new Markdown();
|
|
printf($md->html("text"), true);
|
|
}
|
|
|
|
// Emphasis
|
|
public function testEmphasisStrong1()
|
|
{
|
|
$this->expectOutputString("<p><strong>text</strong></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("__text__"));
|
|
}
|
|
|
|
public function testEmphasisStrong2()
|
|
{
|
|
$this->expectOutputString("<p><strong>text</strong></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("**text**"));
|
|
}
|
|
|
|
public function testEmphasisEM1()
|
|
{
|
|
$this->expectOutputString("<p><em>text</em></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("_text_"));
|
|
}
|
|
|
|
public function testEmphasisEM2()
|
|
{
|
|
$this->expectOutputString("<p><em>file1.php</em> or <em>file2.php</em></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("_file1.php_ or _file2.php_"));
|
|
}
|
|
|
|
public function testEmphasisEM3()
|
|
{
|
|
$this->expectOutputString("<p><em>text</em></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("*text*"));
|
|
}
|
|
|
|
public function testEmphasisEM4()
|
|
{
|
|
$this->expectOutputString("<p><em>text</em> or <em>text2</em></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("*text* or *text2*"));
|
|
}
|
|
|
|
// Unnumbered lists
|
|
public function testUnnumbered1()
|
|
{
|
|
$this->expectOutputString("<ul>
|
|
<li>Case1</li>
|
|
<li>Case2</li>
|
|
<li>Case3</li>
|
|
</ul>");
|
|
$md = new Markdown();
|
|
printf($md->html("* Case1\n* Case2\n* Case3"), true);
|
|
}
|
|
|
|
public function testUnnumbered2()
|
|
{
|
|
$this->expectOutputString("<ul>
|
|
<li>Case1</li>
|
|
<li>Case2</li>
|
|
<li>Case3</li>
|
|
</ul>");
|
|
$md = new Markdown();
|
|
printf($md->html("- Case1\n- Case2\n- Case3"), true);
|
|
}
|
|
|
|
public function testUnnumbered3()
|
|
{
|
|
$this->expectOutputString("<ul>
|
|
<li>Case1</li>
|
|
<li>Case2</li>
|
|
<li>Case3</li>
|
|
</ul>");
|
|
$md = new Markdown();
|
|
printf($md->html("+ Case1\n+ Case2\n+ Case3"), true);
|
|
}
|
|
|
|
public function testUnnumberredMultiline1()
|
|
{
|
|
$this->expectOutputString("<ul>
|
|
<li>line1 end</li>
|
|
<li>line2 end</li>
|
|
</ul>");
|
|
$md = new Markdown();
|
|
printf($md->html("* line1
|
|
end
|
|
* line2
|
|
end"));
|
|
}
|
|
|
|
public function testUnnumberedListMultiple1()
|
|
{
|
|
$this->expectOutputString("<ul>
|
|
<li>line1</li>
|
|
<li>line2
|
|
<ul>
|
|
<li>NEW lineA</li>
|
|
<li>NEW lineB</li>
|
|
</ul>
|
|
</li>
|
|
<li>line3</li>
|
|
</ul>");
|
|
$md = new Markdown();
|
|
printf($md->html("* line1
|
|
* line2
|
|
* NEW lineA
|
|
* NEW lineB
|
|
* line3"));
|
|
}
|
|
|
|
// Numbered lists
|
|
public function testNumbered1()
|
|
{
|
|
$this->expectOutputString("<ol>
|
|
<li>Case1</li>
|
|
<li>Case2</li>
|
|
<li>Case3</li>
|
|
</ol>");
|
|
$md = new Markdown();
|
|
printf($md->html("1. Case1\n2. Case2\n3. Case3"), true);
|
|
}
|
|
|
|
// Code
|
|
public function testCode1()
|
|
{
|
|
$this->expectOutputString("<pre><code>test
|
|
indent
|
|
base</code></pre>");
|
|
$md = new Markdown();
|
|
printf($md->html(" test
|
|
indent
|
|
base"));
|
|
}
|
|
|
|
// Inline code
|
|
public function testInlineCode1()
|
|
{
|
|
$this->expectOutputString("<p><code>code</code></p>");
|
|
$md = new Markdown();
|
|
printf($md->html("`code`"));
|
|
}
|
|
|
|
// Links
|
|
public function testLinkHTTP1()
|
|
{
|
|
$this->expectOutputString(
|
|
"<p><a href='http://example.com'>http://example.com</a></p>"
|
|
);
|
|
$md = new Markdown();
|
|
printf($md->html("<http://example.com>"));
|
|
}
|
|
|
|
public function testLinkHTTP2()
|
|
{
|
|
$this->expectOutputString(
|
|
"<p><a href='https://example.com'>https://example.com</a></p>"
|
|
);
|
|
$md = new Markdown();
|
|
printf($md->html("<https://example.com>"));
|
|
}
|
|
|
|
public function testLinkHTTP3()
|
|
{
|
|
$this->expectOutputString(
|
|
"<p><a href='mailto:test@example.com'>test@example.com</a></p>"
|
|
);
|
|
$md = new Markdown();
|
|
printf($md->html("<test@example.com>"));
|
|
}
|
|
|
|
public function testLinkHTTP4()
|
|
{
|
|
$this->expectOutputString(
|
|
"<p><a href='mailto:test_with_underscore@example.com'>test_with_underscore@example.com</a></p>"
|
|
);
|
|
$md = new Markdown();
|
|
printf($md->html("<test_with_underscore@example.com>"));
|
|
}
|
|
|
|
// Chaining
|
|
public function testChain1()
|
|
{
|
|
$this->expectOutputString("<h1>t1</h1><h2>t2</h2>");
|
|
$md = new Markdown();
|
|
printf($md->html("# t1\n## t2"));
|
|
}
|
|
|
|
public function testChainCode1()
|
|
{
|
|
$this->expectOutputString("<pre><code>
|
|
* OK</code></pre>");
|
|
$md = new Markdown();
|
|
printf($md->html(" \n * OK"));
|
|
}
|
|
|
|
public function testChainCode2()
|
|
{
|
|
$this->expectOutputString("<pre><code>
|
|
* * * * * www-data OK</code></pre>");
|
|
$md = new Markdown();
|
|
printf($md->html(" \n * * * * * www-data OK"));
|
|
}
|
|
|
|
public function testChainCode3()
|
|
{
|
|
$this->expectOutputString("<p>To write</p>
|
|
<pre><code>* * * * * www-data OK</code></pre>");
|
|
$md = new Markdown();
|
|
printf($md->html("To write
|
|
|
|
* * * * * www-data OK"));
|
|
}
|
|
|
|
public function testUnnumberredAndText1()
|
|
{
|
|
$this->expectOutputString("<p>Hi</p>
|
|
<ul>
|
|
<li>line1</li>
|
|
<li>line2 end</li>
|
|
</ul>");
|
|
$md = new Markdown();
|
|
printf($md->html("Hi
|
|
* line1
|
|
* line2
|
|
end"));
|
|
}
|
|
|
|
public function testCarriageReturn1()
|
|
{
|
|
$this->expectOutputString("<p>line1 line2</p>");
|
|
$md = new Markdown();
|
|
printf($md->html("line1\nline2\n"));
|
|
}
|
|
|
|
public function testCarriageReturn2()
|
|
{
|
|
$this->expectOutputString("<p>line1<br/>line2</p>");
|
|
$md = new Markdown();
|
|
printf($md->html("line1 \nline2\n"));
|
|
}
|
|
|
|
public function testCarriageReturn3()
|
|
{
|
|
$this->expectOutputString("<p>line1 line2 line3.</p>");
|
|
$md = new Markdown();
|
|
printf($md->html("line1
|
|
line2
|
|
line3."));
|
|
}
|
|
|
|
public function testHTMLSpecialChars1()
|
|
{
|
|
$this->expectOutputString("<p>toto&titi</p>");
|
|
$md = new Markdown();
|
|
printf($md->html("toto&titi"));
|
|
}
|
|
|
|
public function testHTMLSpecialChars2()
|
|
{
|
|
$this->expectOutputString("<p>totoétiti</p>");
|
|
$md = new Markdown();
|
|
printf($md->html("totoétiti"));
|
|
}
|
|
}
|