1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Add some component level tests

This commit is contained in:
Aidan Woods 2019-02-11 00:12:19 +00:00
parent c0792947a6
commit d8d483bd6a
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
6 changed files with 166 additions and 10 deletions

View File

@ -3,7 +3,8 @@
<testsuites> <testsuites>
<testsuite name="ParsedownTests"> <testsuite name="ParsedownTests">
<file>tests/ParsedownTest.php</file> <file>tests/ParsedownTest.php</file>
<file>tests/CommonMarkTest.php</file> <file>tests/CommonMarkTest.php</file>
<directory suffix="Test.php">./tests/src</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<groups> <groups>

View File

@ -13,16 +13,7 @@
<PossiblyUnusedMethod> <PossiblyUnusedMethod>
<errorLevel type="suppress"> <errorLevel type="suppress">
<directory name="tests" /> <directory name="tests" />
<referencedMethod name="Erusev\Parsedown\Components\Inlines\PlainText::text" />
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Container::contents" />
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Element::create" />
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Element::attributes" />
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Element::settingName" />
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Element::settingAttributes" />
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Element::settingContents" />
<referencedMethod name="Erusev\Parsedown\Parsing\Lines::appendingContext" /> <referencedMethod name="Erusev\Parsedown\Parsing\Lines::appendingContext" />
<referencedMethod name="Erusev\Parsedown\Parsing\Lines::last" />
<referencedMethod name="Erusev\Parsedown\State::mergingWith" />
<referencedMethod name="Erusev\Parsedown\Html\Sanitisation\Escaper::htmlElementValue" /> <referencedMethod name="Erusev\Parsedown\Html\Sanitisation\Escaper::htmlElementValue" />
<referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingHighPrecedence" /> <referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingHighPrecedence" />
<referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingLowPrecedence" /> <referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingLowPrecedence" />
@ -37,5 +28,17 @@
<PropertyNotSetInConstructor> <PropertyNotSetInConstructor>
<errorLevel type="suppress"><directory name="tests" /></errorLevel> <errorLevel type="suppress"><directory name="tests" /></errorLevel>
</PropertyNotSetInConstructor> </PropertyNotSetInConstructor>
<UnusedClass>
<errorLevel type="suppress"><directory name="tests/src" /></errorLevel>
</UnusedClass>
<UndefinedInterfaceMethod>
<errorLevel type="suppress"><directory name="tests/src" /></errorLevel>
</UndefinedInterfaceMethod>
<PossiblyNullArrayAccess>
<errorLevel type="suppress"><directory name="tests/src" /></errorLevel>
</PossiblyNullArrayAccess>
<PossiblyNullReference>
<errorLevel type="suppress"><directory name="tests/src" /></errorLevel>
</PossiblyNullReference>
</issueHandlers> </issueHandlers>
</psalm> </psalm>

View File

@ -0,0 +1,22 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\PlainText;
use Erusev\Parsedown\Parsing\Excerpt;
use PHPUnit\Framework\TestCase;
final class PlainTextTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testPlainTextText()
{
$Plaintext = Plaintext::build(new Excerpt('foo', 0));
$this->assertSame('foo', $Plaintext->text());
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Erusev\Parsedown\Tests\Html\Renderables;
use Erusev\Parsedown\Html\Renderables\Container;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use PHPUnit\Framework\TestCase;
final class ContainerTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testContainerContents()
{
$Container = new Container([
new Element('foo', [], null),
new Text('bar'),
]);
$Contents = $Container->contents();
$this->assertTrue($Contents[0] instanceof Element);
$this->assertSame($Contents[0]->name(), 'foo');
$this->assertTrue($Contents[1] instanceof Text);
$this->assertSame($Contents[1]->getHtml(), 'bar');
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace Erusev\Parsedown\Tests\Html\Renderables;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use PHPUnit\Framework\TestCase;
final class ElementTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testElementProperties()
{
$Element = new Element(
'foo',
[
'bar' => 'baz',
'boo' => 'bim',
],
[new Text('zoo')]
);
$this->assertSame($Element->name(), 'foo');
$this->assertSame(
$Element->attributes(),
[
'bar' => 'baz',
'boo' => 'bim',
]
);
$this->assertTrue($Element->contents()[0] instanceof Text);
$this->assertSame($Element->contents()[0]->getHtml(), 'zoo');
}
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testSettingElementProperties()
{
$Element = new Element(
'foo',
[
'bar' => 'baz',
'boo' => 'bim',
],
[new Text('zoo')]
);
$Element = $Element
->settingAttributes(['bar' => 'bim'])
->settingContents(null)
;
$this->assertSame($Element->name(), 'foo');
$this->assertSame($Element->attributes(), ['bar' => 'bim']);
$this->assertSame($Element->contents(), null);
$Element = $Element->settingName('foo1');
$this->assertSame($Element->name(), 'foo1');
}
}

32
tests/src/StateTest.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace Erusev\Parsedown\Tests;
use Erusev\Parsedown\Configurables\Breaks;
use Erusev\Parsedown\Configurables\SafeMode;
use Erusev\Parsedown\Configurables\StrictMode;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class StateTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testStateMerge()
{
$State = new State;
$this->assertFalse($State->get(SafeMode::class)->isEnabled());
$this->assertFalse($State->get(StrictMode::class)->isEnabled());
$this->assertFalse($State->get(Breaks::class)->isEnabled());
$UpdatedState = $State->mergingWith(new State([SafeMode::enabled()]));
$this->assertTrue($UpdatedState->get(SafeMode::class)->isEnabled());
$this->assertFalse($UpdatedState->get(StrictMode::class)->isEnabled());
$this->assertFalse($UpdatedState->get(Breaks::class)->isEnabled());
}
}