MarkdownTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Markdown;
  9. /**
  10. * Test case for traditional markdown.
  11. *
  12. * @author Carsten Brandt <mail@cebe.cc>
  13. * @group default
  14. */
  15. class MarkdownTest extends BaseMarkdownTest
  16. {
  17. public function createMarkdown()
  18. {
  19. return new Markdown();
  20. }
  21. public function getDataPaths()
  22. {
  23. return [
  24. 'markdown-data' => __DIR__ . '/markdown-data',
  25. ];
  26. }
  27. public function testEdgeCases()
  28. {
  29. $this->assertEquals("<p>&amp;</p>\n", $this->createMarkdown()->parse('&'));
  30. $this->assertEquals("<p>&lt;</p>\n", $this->createMarkdown()->parse('<'));
  31. }
  32. public function testKeepZeroAlive()
  33. {
  34. $parser = $this->createMarkdown();
  35. $this->assertEquals("0", $parser->parseParagraph("0"));
  36. $this->assertEquals("<p>0</p>\n", $parser->parse("0"));
  37. }
  38. public function testAutoLinkLabelingWithEncodedUrl()
  39. {
  40. $parser = $this->createMarkdown();
  41. $utfText = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a";
  42. $utfNaturalUrl = "http://example.com/" . $utfText;
  43. $utfEncodedUrl = "http://example.com/" . urlencode($utfText);
  44. $eucEncodedUrl = "http://example.com/" . urlencode(mb_convert_encoding($utfText, 'EUC-JP', 'UTF-8'));
  45. $this->assertStringEndsWith(">{$utfNaturalUrl}</a>", $parser->parseParagraph("<{$utfNaturalUrl}>"), "Natural UTF-8 URL needs no conversion.");
  46. $this->assertStringEndsWith(">{$utfNaturalUrl}</a>", $parser->parseParagraph("<{$utfEncodedUrl}>"), "Encoded UTF-8 URL will be converted to readable format.");
  47. $this->assertStringEndsWith(">{$eucEncodedUrl}</a>", $parser->parseParagraph("<{$eucEncodedUrl}>"), "Non UTF-8 URL should never be converted.");
  48. // See: \cebe\markdown\inline\LinkTrait::renderUrl
  49. }
  50. }