* * 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\InlinesOnly; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension; use League\CommonMark\MarkdownConverter; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * Tests the extension against sample files */ final class InlinesOnlyFunctionalTest extends TestCase { private MarkdownConverter $converter; protected function setUp(): void { $environment = new Environment(); $environment->addExtension(new InlinesOnlyExtension()); $this->converter = new MarkdownConverter($environment); } /** * @dataProvider dataProvider * * @param string $markdown Markdown to parse * @param string $html Expected result */ #[DataProvider('dataProvider')] public function testExample(string $markdown, string $html): void { $actualResult = $this->converter->convert($markdown); $failureMessage = 'Unexpected result'; $failureMessage .= "\n=== markdown ===============\n" . $markdown; $failureMessage .= "\n=== expected ===============\n" . $html; $failureMessage .= "\n=== got ====================\n" . $actualResult; $this->assertEquals($html, $actualResult, $failureMessage); } /** * @return array> */ public static function dataProvider(): array { $markdown = \file_get_contents(__DIR__ . '/inlines.md'); $html = \file_get_contents(__DIR__ . '/inlines.html'); return [ [$markdown, $html], ]; } /** * The unordered_list_markers option is part of the shared 'commonmark' config * schema. InlinesOnlyExtension reuses that config key, so setting the option * must be accepted even though this extension does not render lists. * * @see https://github.com/thephpleague/commonmark/issues/1015 */ public function testUnorderedListMarkersConfigIsAccepted(): void { $environment = new Environment(['commonmark' => ['unordered_list_markers' => ['*']]]); $environment->addExtension(new InlinesOnlyExtension()); $converter = new MarkdownConverter($environment); $this->assertSame(['*'], $environment->getConfiguration()->get('commonmark/unordered_list_markers')); $this->assertSame('foo', \trim($converter->convert('*foo*')->getContent())); } }