diff options
Diffstat (limited to 'www/wiki/extensions/Mermaid/tests/phpunit/Unit/MermaidParserFunctionTest.php')
-rw-r--r-- | www/wiki/extensions/Mermaid/tests/phpunit/Unit/MermaidParserFunctionTest.php | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/www/wiki/extensions/Mermaid/tests/phpunit/Unit/MermaidParserFunctionTest.php b/www/wiki/extensions/Mermaid/tests/phpunit/Unit/MermaidParserFunctionTest.php new file mode 100644 index 00000000..2a819c17 --- /dev/null +++ b/www/wiki/extensions/Mermaid/tests/phpunit/Unit/MermaidParserFunctionTest.php @@ -0,0 +1,109 @@ +<?php + +namespace Mermaid\Tests; + +use Mermaid\MermaidParserFunction; + +/** + * @covers \Mermaid\MermaidParserFunction + * @group mermaid + * + * @license GNU GPL v2+ + * @since 1.0 + * + * @author mwjames + */ +class MermaidParserFunctionTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $parser = $this->getMockBuilder( '\Parser' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + MermaidParserFunction::class, + new MermaidParserFunction( $parser ) + ); + } + + public function testInitCallback() { + + $callback = MermaidParserFunction::newCallback( 'foo' ); + + $this->assertInstanceOf( + '\Closure', + $callback + ); + + $parserOutput = $this->getMockBuilder( '\ParserOutput' ) + ->disableOriginalConstructor() + ->getMock(); + + $parser = $this->getMockBuilder( '\Parser' ) + ->disableOriginalConstructor() + ->getMock(); + + $parser->expects( $this->any() ) + ->method( 'getOutput' ) + ->will( $this->returnValue( $parserOutput ) ); + + $this->assertNotEmpty( + call_user_func_array( $callback, [ $parser ] ) + ); + } + + /** + * @dataProvider textProvider + */ + public function testParse( $text, $expected ) { + + $parserOutput = $this->getMockBuilder( '\ParserOutput' ) + ->disableOriginalConstructor() + ->getMock(); + + $parserOutput->expects( $this->once() ) + ->method( 'setExtensionData' ) + ->with( + $this->equalTo( 'ext-mermaid' ), + $this->equalTo( true ) ); + + $parser = $this->getMockBuilder( '\Parser' ) + ->disableOriginalConstructor() + ->getMock(); + + $parser->expects( $this->any() ) + ->method( 'getOutput' ) + ->will( $this->returnValue( $parserOutput ) ); + + $instance = new MermaidParserFunction( + $parser + ); + + $this->assertContains( + $expected, + $instance->parse( $text ) + ); + } + + public function textProvider() { + + yield [ + [ 'sequenceDiagram...', 'config.theme=foo' ], + 'class="ext-mermaid" data-mermaid="{"content":"sequenceDiagram...","config":{"theme":"foo"}}"><div class="mermaid-dots"></div></div>' + ]; + + // [ ... ] + yield [ + [ 'sequenceDiagram id1["This is the (text) in the box"]', 'config.theme=foo' ], + 'data-mermaid="{"content":"sequenceDiagram id1[\"This is the (text) in the box\"]' + ]; + + // | + yield [ + [ 'A[Hard edge] -->|Link text| B(Round edge)' ], + 'data-mermaid="{"content":"A[Hard edge] -->|Link text| B(Round edge)"' + ]; + } + +} |