SafeLinksTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\Functional;
  15. use League\CommonMark\CommonMarkConverter;
  16. use PHPUnit\Framework\TestCase;
  17. final class SafeLinksTest extends TestCase
  18. {
  19. public function testDefaultConfig(): void
  20. {
  21. $input = \file_get_contents(__DIR__ . '/data/safe_links/input.md');
  22. $expectedOutput = \trim(\file_get_contents(__DIR__ . '/data/safe_links/unsafe_output.html'));
  23. $converter = new CommonMarkConverter();
  24. $actualOutput = \trim((string) $converter->convert($input));
  25. $this->assertEquals($expectedOutput, $actualOutput);
  26. }
  27. public function testSafeConfig(): void
  28. {
  29. $input = \file_get_contents(__DIR__ . '/data/safe_links/input.md');
  30. $expectedOutput = \trim(\file_get_contents(__DIR__ . '/data/safe_links/safe_output.html'));
  31. $converter = new CommonMarkConverter(['allow_unsafe_links' => false]);
  32. $actualOutput = \trim((string) $converter->convert($input));
  33. $this->assertEquals($expectedOutput, $actualOutput);
  34. }
  35. }