DocumentRendererTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. *
  8. * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
  9. * - (c) John MacFarlane
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace League\CommonMark\Tests\Unit\Renderer\Block;
  15. use League\CommonMark\Exception\InvalidArgumentException;
  16. use League\CommonMark\Extension\CommonMark\Node\Block\ThematicBreak;
  17. use League\CommonMark\Node\Block\AbstractBlock;
  18. use League\CommonMark\Node\Block\Document;
  19. use League\CommonMark\Renderer\Block\DocumentRenderer;
  20. use League\CommonMark\Tests\Unit\Renderer\FakeChildNodeRenderer;
  21. use PHPUnit\Framework\TestCase;
  22. final class DocumentRendererTest extends TestCase
  23. {
  24. private DocumentRenderer $renderer;
  25. protected function setUp(): void
  26. {
  27. $this->renderer = new DocumentRenderer();
  28. }
  29. public function testRenderEmptyDocument(): void
  30. {
  31. $block = new Document();
  32. $fakeRenderer = new FakeChildNodeRenderer();
  33. $result = $this->renderer->render($block, $fakeRenderer);
  34. $this->assertIsString($result);
  35. $this->assertSame('', $result);
  36. }
  37. public function testRenderDocument(): void
  38. {
  39. $block = new Document();
  40. $block->appendChild(new ThematicBreak());
  41. $fakeRenderer = new FakeChildNodeRenderer();
  42. $result = $this->renderer->render($block, $fakeRenderer);
  43. $this->assertIsString($result);
  44. $this->assertStringContainsString('::children::', $result);
  45. }
  46. public function testRenderWithInvalidType(): void
  47. {
  48. $this->expectException(InvalidArgumentException::class);
  49. $inline = $this->getMockForAbstractClass(AbstractBlock::class);
  50. $fakeRenderer = new FakeChildNodeRenderer();
  51. $this->renderer->render($inline, $fakeRenderer);
  52. }
  53. }