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