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