StrikethroughExtensionTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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> and uAfrica.com (http://uafrica.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\Functional\Extension\Strikethrough;
  12. use League\CommonMark\Environment\Environment;
  13. use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
  14. use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
  15. use League\CommonMark\Parser\MarkdownParser;
  16. use League\CommonMark\Renderer\HtmlRenderer;
  17. use PHPUnit\Framework\TestCase;
  18. final class StrikethroughExtensionTest extends TestCase
  19. {
  20. /**
  21. * @dataProvider dataForIntegrationTest
  22. */
  23. public function testStrikethrough(string $string, string $expected): void
  24. {
  25. $environment = new Environment();
  26. $environment->addExtension(new CommonMarkCoreExtension());
  27. $environment->addExtension(new StrikethroughExtension());
  28. $parser = new MarkdownParser($environment);
  29. $renderer = new HtmlRenderer($environment);
  30. $document = $parser->parse($string);
  31. $html = (string) $renderer->renderDocument($document);
  32. $this->assertSame($expected, $html);
  33. }
  34. /**
  35. * @return array<array<string>>
  36. */
  37. public function dataForIntegrationTest(): array
  38. {
  39. return [
  40. ['~~Hi~~ Hello, ~there~ world!', "<p><del>Hi</del> Hello, <del>there</del> world!</p>\n"],
  41. ['This is a test without any strikethroughs', "<p>This is a test without any strikethroughs</p>\n"],
  42. ['This is a test with ~valid~ strikethroughs', "<p>This is a test with <del>valid</del> strikethroughs</p>\n"],
  43. ['This is a test `with` ~valid~ strikethroughs', "<p>This is a test <code>with</code> <del>valid</del> strikethroughs</p>\n"],
  44. ['This is a ~~unit~~ integration test', "<p>This is a <del>unit</del> integration test</p>\n"],
  45. ['~~Strikethrough~~ on the left', "<p><del>Strikethrough</del> on the left</p>\n"],
  46. ['Strikethrough on the ~~right~~', "<p>Strikethrough on the <del>right</del></p>\n"],
  47. ['~~Strikethrough everywhere~~', "<p><del>Strikethrough everywhere</del></p>\n"],
  48. ['This ~~test has no ending match', "<p>This ~~test has no ending match</p>\n"],
  49. ['This ~~test~~~ has mismatched tildes', "<p>This ~~test~~~ has mismatched tildes</p>\n"],
  50. ['This ~~~test~~ also has mismatched tildes', "<p>This ~~~test~~ also has mismatched tildes</p>\n"],
  51. ['This one has ~~~three~~~ tildes', "<p>This one has ~~~three~~~ tildes</p>\n"],
  52. ["This ~~has a\n\nnew paragraph~~.", "<p>This ~~has a</p>\n<p>new paragraph~~.</p>\n"],
  53. ['Hello ~~ ~~ world', "<p>Hello ~~ ~~ world</p>\n"],
  54. ['This **is ~~a little** test of mismatched delimiters~~', "<p>This <strong>is ~~a little</strong> test of mismatched delimiters~~</p>\n"],
  55. ['Из: твоя ~~тест~~ ветка', "<p>Из: твоя <del>тест</del> ветка</p>\n"],
  56. ['This one combines ~~nested ~~strikethrough~~ text~~', "<p>This one combines <del>nested <del>strikethrough</del> text</del></p>\n"],
  57. ['Here we have **emphasized text containing a ~~strikethrough~~**', "<p>Here we have <strong>emphasized text containing a <del>strikethrough</del></strong></p>\n"],
  58. ['Four trailing tildes ~~~~', "<p>Four trailing tildes ~~~~</p>\n"],
  59. ['~~Unmatched left', "<p>~~Unmatched left</p>\n"],
  60. ['Unmatched right~~', "<p>Unmatched right~~</p>\n"],
  61. ['~~foo~bar~~', "<p><del>foo~bar</del></p>\n"],
  62. ['~~foo~~bar~~', "<p><del>foo</del>bar~~</p>\n"],
  63. ['~~foo~~~bar~~', "<p><del>foo~~~bar</del></p>\n"],
  64. ['~~foo~~~~bar~~', "<p><del>foo~~~~bar</del></p>\n"],
  65. ['~~foo~~~~~bar~~', "<p><del>foo~~~~~bar</del></p>\n"],
  66. ['~~foo~~~~~~bar~~', "<p><del>foo~~~~~~bar</del></p>\n"],
  67. ['~~foo~~~~~~~bar~~', "<p><del>foo~~~~~~~bar</del></p>\n"],
  68. ['> inside a ~~blockquote~~', "<blockquote>\n<p>inside a <del>blockquote</del></p>\n</blockquote>\n"],
  69. ];
  70. }
  71. }