2014-09-06 00:12:33 +04:00
|
|
|
<?php
|
|
|
|
|
2014-09-06 00:28:07 +04:00
|
|
|
/**
|
2014-09-06 02:12:35 +04:00
|
|
|
* Test Parsedown against the CommonMark spec.
|
2014-09-06 00:28:07 +04:00
|
|
|
*
|
|
|
|
* Some code based on the original JavaScript test runner by jgm.
|
|
|
|
*
|
2014-09-14 01:02:11 +04:00
|
|
|
* @link http://commonmark.org/ CommonMark
|
2014-09-06 00:28:07 +04:00
|
|
|
* @link http://git.io/8WtRvQ JavaScript test runner
|
|
|
|
*/
|
2014-09-06 02:12:35 +04:00
|
|
|
class CommonMarkTest extends PHPUnit_Framework_TestCase
|
2014-09-06 00:12:33 +04:00
|
|
|
{
|
|
|
|
const SPEC_URL = 'https://raw.githubusercontent.com/jgm/stmd/master/spec.txt';
|
|
|
|
|
2014-09-06 02:12:35 +04:00
|
|
|
public function getCommonMarkRules()
|
2014-09-06 00:12:33 +04:00
|
|
|
{
|
2014-11-29 21:18:23 +03:00
|
|
|
$spec = file_get_contents(self::SPEC_URL);
|
2014-09-06 00:12:33 +04:00
|
|
|
|
|
|
|
$tests = array();
|
|
|
|
$testsCount = 0;
|
|
|
|
$currentSection = '';
|
|
|
|
|
2014-11-29 21:18:23 +03:00
|
|
|
$spec = strstr($spec, '<!-- END TESTS -->', true);
|
2014-09-06 00:12:33 +04:00
|
|
|
|
|
|
|
preg_replace_callback(
|
|
|
|
'/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/m',
|
|
|
|
function($matches) use (&$tests, &$currentSection, &$testsCount) {
|
|
|
|
if (isset($matches[3]) and $matches[3]) {
|
|
|
|
$currentSection = $matches[3];
|
|
|
|
} else {
|
|
|
|
$testsCount++;
|
|
|
|
$markdown = preg_replace('/→/', "\t", $matches[1]);
|
|
|
|
$tests []= array(
|
|
|
|
$markdown, // markdown
|
|
|
|
$matches[2], // html
|
|
|
|
$currentSection, // section
|
|
|
|
$testsCount, // number
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
$spec
|
|
|
|
);
|
|
|
|
|
|
|
|
return $tests;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-06 02:12:35 +04:00
|
|
|
* @dataProvider getCommonMarkRules
|
2014-09-06 00:12:33 +04:00
|
|
|
*/
|
2014-09-06 02:12:35 +04:00
|
|
|
public function testAgainstCommonMark($markdown, $expectedHtml, $section, $number)
|
2014-09-06 00:12:33 +04:00
|
|
|
{
|
|
|
|
$parsedown = new Parsedown();
|
|
|
|
|
|
|
|
$actualHtml = $parsedown->text($markdown);
|
|
|
|
|
|
|
|
// Trim for better compatibility of the HTML output
|
|
|
|
$actualHtml = trim($actualHtml);
|
|
|
|
$expectedHtml = trim($expectedHtml);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedHtml, $actualHtml);
|
|
|
|
}
|
|
|
|
}
|