GithubMarkdownTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2014 Carsten Brandt
  4. * @license https://github.com/cebe/markdown/blob/master/LICENSE
  5. * @link https://github.com/cebe/markdown#readme
  6. */
  7. namespace cebe\markdown\tests;
  8. use cebe\markdown\GithubMarkdown;
  9. /**
  10. * Test case for the github flavored markdown.
  11. *
  12. * @author Carsten Brandt <mail@cebe.cc>
  13. * @group github
  14. */
  15. class GithubMarkdownTest extends BaseMarkdownTest
  16. {
  17. public function createMarkdown()
  18. {
  19. return new GithubMarkdown();
  20. }
  21. public function getDataPaths()
  22. {
  23. return [
  24. 'markdown-data' => __DIR__ . '/markdown-data',
  25. 'github-data' => __DIR__ . '/github-data',
  26. ];
  27. }
  28. public function testNewlines()
  29. {
  30. $markdown = $this->createMarkdown();
  31. $this->assertEquals("This is text<br />\nnewline\nnewline.", $markdown->parseParagraph("This is text \nnewline\nnewline."));
  32. $markdown->enableNewlines = true;
  33. $this->assertEquals("This is text<br />\nnewline<br />\nnewline.", $markdown->parseParagraph("This is text \nnewline\nnewline."));
  34. $this->assertEquals("<p>This is text</p>\n<p>newline<br />\nnewline.</p>\n", $markdown->parse("This is text\n\nnewline\nnewline."));
  35. }
  36. public function dataFiles()
  37. {
  38. $files = parent::dataFiles();
  39. foreach($files as $i => $f) {
  40. // skip files that are different in github MD
  41. if ($f[0] === 'markdown-data' && (
  42. $f[1] === 'list-marker-in-paragraph' ||
  43. $f[1] === 'dense-block-markers'
  44. )) {
  45. unset($files[$i]);
  46. }
  47. }
  48. return $files;
  49. }
  50. public function testKeepZeroAlive()
  51. {
  52. $parser = $this->createMarkdown();
  53. $this->assertEquals("0", $parser->parseParagraph("0"));
  54. $this->assertEquals("<p>0</p>\n", $parser->parse("0"));
  55. }
  56. public function testAutoLinkLabelingWithEncodedUrl()
  57. {
  58. $parser = $this->createMarkdown();
  59. $utfText = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a";
  60. $utfNaturalUrl = "http://example.com/" . $utfText;
  61. $utfEncodedUrl = "http://example.com/" . urlencode($utfText);
  62. $eucEncodedUrl = "http://example.com/" . urlencode(mb_convert_encoding($utfText, 'EUC-JP', 'UTF-8'));
  63. $this->assertStringEndsWith(">{$utfNaturalUrl}</a>", $parser->parseParagraph($utfNaturalUrl), "Natural UTF-8 URL needs no conversion.");
  64. $this->assertStringEndsWith(">{$utfNaturalUrl}</a>", $parser->parseParagraph($utfEncodedUrl), "Encoded UTF-8 URL will be converted to readable format.");
  65. $this->assertStringEndsWith(">{$eucEncodedUrl}</a>", $parser->parseParagraph($eucEncodedUrl), "Non UTF-8 URL should never be converted.");
  66. // See: \cebe\markdown\inline\UrlLinkTrait::renderAutoUrl
  67. }
  68. }