and uAfrica.com (http://uafrica.com) * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Tests\Functional\Extension\Footnote; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\Footnote\FootnoteExtension; use League\CommonMark\MarkdownConverter; use PHPUnit\Framework\TestCase; final class FootnoteExtensionTest extends TestCase { /** * @dataProvider dataForIntegrationTest * * @param array $config */ public function testFootnote(string $string, string $expected, array $config = []): void { $environment = new Environment(['footnote' => $config]); $environment->addExtension(new CommonMarkCoreExtension()); $environment->addExtension(new FootnoteExtension()); $converter = new MarkdownConverter($environment); $html = \trim((string) $converter->convert($string)); $this->assertSame($expected, $html); } /** * @return array> */ public function dataForIntegrationTest(): array { return [ [ "Here[^note1]\n\n[^note1]: There", '

Here1


  1. There 

', ], [ "Here[^note1]\n\n[^note1]: There", '

Here1


  1. There 

', ['ref_id_prefix' => 'customfnref:', 'footnote_id_prefix' => 'customfn:'], ], ]; } /** * @dataProvider dataProviderForTestFootnotesWithCustomOptions */ public function testFootnotesWithCustomOptions(string $input, string $expected): void { $environment = new Environment([ 'footnote' => [ 'backref_class' => 'custom-backref', // Ensure multiple characters are allowed (including multibyte) and special HTML characters are escaped. 'backref_symbol' => '↩ 🦄️ <3 You', 'container_add_hr' => false, 'container_class' => 'custom-notes', 'ref_class' => 'custom-ref', 'ref_id_prefix' => 'fnref:', 'footnote_class' => 'custom-footnote', 'footnote_id_prefix' => 'fn:', ], ]); $environment->addExtension(new CommonMarkCoreExtension()); $environment->addExtension(new FootnoteExtension()); $converter = new MarkdownConverter($environment); $this->assertEquals($expected, \trim((string) $converter->convert($input))); } public function dataProviderForTestFootnotesWithCustomOptions(): \Generator { yield ["Here[^note1]\n\n[^note1]: There", '

Here1

' . "\n" . '']; yield ["_Here_[^note1]\n\n[^note1]: **There**", '

Here1

' . "\n" . '']; } public function testFootnotesWithEmptySymbol(): void { $environment = new Environment([ 'footnote' => [ 'backref_symbol' => '', ], ]); $environment->addExtension(new CommonMarkCoreExtension()); $environment->addExtension(new FootnoteExtension()); $converter = new MarkdownConverter($environment); $input = "Here[^note1]\n\n[^note1]: There"; $expected = '

Here1

' . "\n" . '

  1. There 

'; $this->assertEquals($expected, \trim((string) $converter->convert($input))); } }