123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- class ParsedownTest extends PHPUnit_Framework_TestCase
- {
- final function __construct($name = null, array $data = array(), $dataName = '')
- {
- $this->dirs = $this->initDirs();
- $this->Parsedown = $this->initParsedown();
- parent::__construct($name, $data, $dataName);
- }
- private $dirs, $Parsedown;
- /**
- * @return array
- */
- protected function initDirs()
- {
- $dirs []= dirname(__FILE__).'/data/';
- return $dirs;
- }
- /**
- * @return Parsedown
- */
- protected function initParsedown()
- {
- $Parsedown = new Parsedown();
- return $Parsedown;
- }
- /**
- * @dataProvider data
- * @param $test
- * @param $dir
- */
- function test_($test, $dir)
- {
- $markdown = file_get_contents($dir . $test . '.md');
- $expectedMarkup = file_get_contents($dir . $test . '.html');
- $expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
- $expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
- $actualMarkup = $this->Parsedown->text($markdown);
- $this->assertEquals($expectedMarkup, $actualMarkup);
- }
- function data()
- {
- $data = array();
- foreach ($this->dirs as $dir)
- {
- $Folder = new DirectoryIterator($dir);
- foreach ($Folder as $File)
- {
- /** @var $File DirectoryIterator */
- if ( ! $File->isFile())
- {
- continue;
- }
- $filename = $File->getFilename();
- $extension = pathinfo($filename, PATHINFO_EXTENSION);
- if ($extension !== 'md')
- {
- continue;
- }
- $basename = $File->getBasename('.md');
- if (file_exists($dir . $basename . '.html'))
- {
- $data []= array($basename, $dir);
- }
- }
- }
- return $data;
- }
- public function test_no_markup()
- {
- $markdownWithHtml = <<<MARKDOWN_WITH_MARKUP
- <div>_content_</div>
- sparse:
- <div>
- <div class="inner">
- _content_
- </div>
- </div>
- paragraph
- <style type="text/css">
- p {
- color: red;
- }
- </style>
- comment
- <!-- html comment -->
- MARKDOWN_WITH_MARKUP;
- $expectedHtml = <<<EXPECTED_HTML
- <p><div><em>content</em></div></p>
- <p>sparse:</p>
- <p><div>
- <div class="inner">
- <em>content</em>
- </div>
- </div></p>
- <p>paragraph</p>
- <p><style type="text/css">
- p {
- color: red;
- }
- </style></p>
- <p>comment</p>
- <p><!-- html comment --></p>
- EXPECTED_HTML;
- $parsedownWithNoMarkup = new Parsedown();
- $parsedownWithNoMarkup->setMarkupEscaped(true);
- $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
- }
- public function testLateStaticBinding()
- {
- include __DIR__ . '/TestParsedown.php';
- $parsedown = Parsedown::instance();
- $this->assertInstanceOf('Parsedown', $parsedown);
- // After instance is already called on Parsedown
- // subsequent calls with the same arguments return the same instance
- $sameParsedown = TestParsedown::instance();
- $this->assertInstanceOf('Parsedown', $sameParsedown);
- $this->assertSame($parsedown, $sameParsedown);
- $testParsedown = TestParsedown::instance('test late static binding');
- $this->assertInstanceOf('TestParsedown', $testParsedown);
- $sameInstanceAgain = TestParsedown::instance('test late static binding');
- $this->assertSame($testParsedown, $sameInstanceAgain);
- }
- }
|