mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Adjust tests for new API
Remove tests that test old core and extension features Comment out test for no markup independent of safe mode
This commit is contained in:
parent
e2c9b2fa2b
commit
04816a9944
@ -2,7 +2,10 @@
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
use Erusev\Parsedown\Configurables\SafeMode;
|
||||
use Erusev\Parsedown\Configurables\StrictMode;
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
use Erusev\Parsedown\State;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParsedownTest extends TestCase
|
||||
@ -10,7 +13,6 @@ class ParsedownTest extends TestCase
|
||||
final public function __construct($name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
$this->dirs = $this->initDirs();
|
||||
$this->Parsedown = $this->initParsedown();
|
||||
|
||||
parent::__construct($name, $data, $dataName);
|
||||
}
|
||||
@ -28,16 +30,6 @@ class ParsedownTest extends TestCase
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Parsedown
|
||||
*/
|
||||
protected function initParsedown()
|
||||
{
|
||||
$Parsedown = new TestParsedown();
|
||||
|
||||
return $Parsedown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
* @param $test
|
||||
@ -52,48 +44,16 @@ class ParsedownTest extends TestCase
|
||||
$expectedMarkup = \str_replace("\r\n", "\n", $expectedMarkup);
|
||||
$expectedMarkup = \str_replace("\r", "\n", $expectedMarkup);
|
||||
|
||||
$this->Parsedown->setSafeMode(\substr($test, 0, 3) === 'xss');
|
||||
$this->Parsedown->setStrictMode(\substr($test, 0, 6) === 'strict');
|
||||
$Parsedown = new Parsedown(new State([
|
||||
new SafeMode(\substr($test, 0, 3) === 'xss'),
|
||||
new StrictMode(\substr($test, 0, 6) === 'strict'),
|
||||
]));
|
||||
|
||||
$actualMarkup = $this->Parsedown->text($markdown);
|
||||
$actualMarkup = $Parsedown->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
}
|
||||
|
||||
public function testRawHtml()
|
||||
{
|
||||
$markdown = "```php\nfoobar\n```";
|
||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||
$expectedSafeMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||
|
||||
$unsafeExtension = new SampleExtensions\UnsafeExtension;
|
||||
$actualMarkup = $unsafeExtension->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
|
||||
$unsafeExtension->setSafeMode(true);
|
||||
$actualSafeMarkup = $unsafeExtension->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
|
||||
}
|
||||
|
||||
public function testTrustDelegatedRawHtml()
|
||||
{
|
||||
$markdown = "```php\nfoobar\n```";
|
||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||
$expectedSafeMarkup = $expectedMarkup;
|
||||
|
||||
$unsafeExtension = new SampleExtensions\TrustDelegatedExtension;
|
||||
$actualMarkup = $unsafeExtension->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
|
||||
$unsafeExtension->setSafeMode(true);
|
||||
$actualSafeMarkup = $unsafeExtension->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
|
||||
}
|
||||
|
||||
public function data()
|
||||
{
|
||||
$data = [];
|
||||
@ -127,70 +87,52 @@ class ParsedownTest extends TestCase
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function test_no_markup()
|
||||
{
|
||||
$markdownWithHtml = <<<MARKDOWN_WITH_MARKUP
|
||||
<div>_content_</div>
|
||||
// public function test_no_markup()
|
||||
// {
|
||||
// $markdownWithHtml = <<<MARKDOWN_WITH_MARKUP
|
||||
// <div>_content_</div>
|
||||
|
||||
sparse:
|
||||
// sparse:
|
||||
|
||||
<div>
|
||||
<div class="inner">
|
||||
_content_
|
||||
</div>
|
||||
</div>
|
||||
// <div>
|
||||
// <div class="inner">
|
||||
// _content_
|
||||
// </div>
|
||||
// </div>
|
||||
|
||||
paragraph
|
||||
// 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 TestParsedown();
|
||||
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
||||
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
||||
}
|
||||
|
||||
public function testLateStaticBinding()
|
||||
{
|
||||
$parsedown = Parsedown::instance();
|
||||
$this->assertInstanceOf('Erusev\Parsedown\Parsedown', $parsedown);
|
||||
|
||||
// After instance is already called on Parsedown
|
||||
// subsequent calls with the same arguments return the same instance
|
||||
$sameParsedown = TestParsedown::instance();
|
||||
$this->assertInstanceOf('Erusev\Parsedown\Parsedown', $sameParsedown);
|
||||
$this->assertSame($parsedown, $sameParsedown);
|
||||
|
||||
$testParsedown = TestParsedown::instance('test late static binding');
|
||||
$this->assertInstanceOf('Erusev\Parsedown\Parsedown', $testParsedown);
|
||||
|
||||
$sameInstanceAgain = TestParsedown::instance('test late static binding');
|
||||
$this->assertSame($testParsedown, $sameInstanceAgain);
|
||||
}
|
||||
// <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 TestParsedown();
|
||||
// $parsedownWithNoMarkup->setMarkupEscaped(true);
|
||||
// $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
||||
// }
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
|
||||
class TestParsedown extends Parsedown
|
||||
{
|
||||
public function getTextLevelElements()
|
||||
{
|
||||
return $this->textLevelElements;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user