FootnoteContainerRendererTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * This file is part of the league/commonmark package.
  4. *
  5. * (c) Colin O'Dell <colinodell@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace League\CommonMark\Tests\Unit\Extension\Footnote\Renderer;
  12. use League\CommonMark\Environment\Environment;
  13. use League\CommonMark\Extension\Footnote\FootnoteExtension;
  14. use League\CommonMark\Extension\Footnote\Node\FootnoteContainer;
  15. use League\CommonMark\Extension\Footnote\Renderer\FootnoteContainerRenderer;
  16. use League\CommonMark\Tests\Unit\Renderer\FakeChildNodeRenderer;
  17. use League\Config\ConfigurationInterface;
  18. use PHPUnit\Framework\TestCase;
  19. final class FootnoteContainerRendererTest extends TestCase
  20. {
  21. public function testDefaultSettings(): void
  22. {
  23. $renderer = new FootnoteContainerRenderer();
  24. $renderer->setConfiguration($this->createConfiguration());
  25. $container = new FootnoteContainer();
  26. $output = $renderer->render($container, new FakeChildNodeRenderer());
  27. $this->assertSame('footnotes', $output->getAttribute('class'));
  28. $this->assertSame('doc-endnotes', $output->getAttribute('role'));
  29. $this->assertStringContainsString('<hr />', $output->getContents());
  30. }
  31. public function testCustomClassAddedViaAST(): void
  32. {
  33. $renderer = new FootnoteContainerRenderer();
  34. $renderer->setConfiguration($this->createConfiguration());
  35. $container = new FootnoteContainer();
  36. $container->data->set('attributes/class', 'custom class');
  37. $output = $renderer->render($container, new FakeChildNodeRenderer());
  38. $this->assertSame('custom class footnotes', $output->getAttribute('class'));
  39. }
  40. public function testClassConfiguration(): void
  41. {
  42. $renderer = new FootnoteContainerRenderer();
  43. $renderer->setConfiguration($this->createConfiguration(['footnote' => ['container_class' => 'my-custom-class']]));
  44. $container = new FootnoteContainer();
  45. $output = $renderer->render($container, new FakeChildNodeRenderer());
  46. $this->assertSame('my-custom-class', $output->getAttribute('class'));
  47. }
  48. public function testAddHRConfiguration(): void
  49. {
  50. $renderer = new FootnoteContainerRenderer();
  51. $renderer->setConfiguration($this->createConfiguration(['footnote' => ['container_add_hr' => false]]));
  52. $container = new FootnoteContainer();
  53. $output = $renderer->render($container, new FakeChildNodeRenderer());
  54. $this->assertStringNotContainsString('<hr />', $output->getContents());
  55. }
  56. /**
  57. * @param array<string, mixed> $values
  58. */
  59. private function createConfiguration(array $values = []): ConfigurationInterface
  60. {
  61. $config = Environment::createDefaultConfiguration();
  62. (new FootnoteExtension())->configureSchema($config);
  63. $config->merge($values);
  64. return $config->reader();
  65. }
  66. }