ParagraphRendererTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Node\Block\AbstractBlock;
  17. use League\CommonMark\Node\Block\Paragraph;
  18. use League\CommonMark\Renderer\Block\ParagraphRenderer;
  19. use League\CommonMark\Tests\Unit\Renderer\FakeChildNodeRenderer;
  20. use League\CommonMark\Util\HtmlElement;
  21. use PHPUnit\Framework\TestCase;
  22. final class ParagraphRendererTest extends TestCase
  23. {
  24. private ParagraphRenderer $renderer;
  25. protected function setUp(): void
  26. {
  27. $this->renderer = new ParagraphRenderer();
  28. }
  29. public function testRender(): void
  30. {
  31. $block = new Paragraph();
  32. $block->data->set('attributes/id', 'foo');
  33. $fakeRenderer = new FakeChildNodeRenderer();
  34. $fakeRenderer->pretendChildrenExist();
  35. $result = $this->renderer->render($block, $fakeRenderer);
  36. $this->assertTrue($result instanceof HtmlElement);
  37. $this->assertEquals('p', $result->getTagName());
  38. $this->assertStringContainsString('::children::', $result->getContents(true));
  39. $this->assertEquals(['id' => 'foo'], $result->getAllAttributes());
  40. }
  41. public function testRenderWithInvalidType(): void
  42. {
  43. $this->expectException(InvalidArgumentException::class);
  44. $inline = $this->getMockForAbstractClass(AbstractBlock::class);
  45. $fakeRenderer = new FakeChildNodeRenderer();
  46. $this->renderer->render($inline, $fakeRenderer);
  47. }
  48. }