TableSectionRendererTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace League\CommonMark\Tests\Unit\Extension\Table;
  12. use League\CommonMark\Exception\InvalidArgumentException;
  13. use League\CommonMark\Extension\Table\TableCell;
  14. use League\CommonMark\Extension\Table\TableRow;
  15. use League\CommonMark\Extension\Table\TableSection;
  16. use League\CommonMark\Extension\Table\TableSectionRenderer;
  17. use League\CommonMark\Tests\Unit\Renderer\FakeChildNodeRenderer;
  18. use PHPUnit\Framework\TestCase;
  19. final class TableSectionRendererTest extends TestCase
  20. {
  21. public function testRenderWithTableSection(): void
  22. {
  23. $tableSection = new TableSection(TableSection::TYPE_BODY);
  24. $tableSection->data->set('attributes/class', 'foo');
  25. $tableSection->appendChild(new TableRow());
  26. $childRenderer = new FakeChildNodeRenderer();
  27. $childRenderer->pretendChildrenExist();
  28. $renderer = new TableSectionRenderer();
  29. $this->assertSame('<tbody class="foo">::children::</tbody>', (string) $renderer->render($tableSection, $childRenderer));
  30. }
  31. public function testRenderWithEmptyTableSection(): void
  32. {
  33. $tableSection = new TableSection(TableSection::TYPE_BODY);
  34. $childRenderer = new FakeChildNodeRenderer();
  35. $renderer = new TableSectionRenderer();
  36. $this->assertSame('', (string) $renderer->render($tableSection, $childRenderer));
  37. }
  38. public function testRenderWithWrongType(): void
  39. {
  40. $this->expectException(InvalidArgumentException::class);
  41. (new TableSectionRenderer())->render(new TableCell(), new FakeChildNodeRenderer());
  42. }
  43. }