ParsedownTest.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. <?php
  2. use Codeception\Util\Fixtures;
  3. use Grav\Common\Grav;
  4. use Grav\Common\Page\Markdown\Excerpts;
  5. use Grav\Common\Uri;
  6. use Grav\Common\Config\Config;
  7. use Grav\Common\Page\Pages;
  8. use Grav\Common\Markdown\Parsedown;
  9. use Grav\Common\Language\Language;
  10. /**
  11. * Class ParsedownTest
  12. */
  13. class ParsedownTest extends \Codeception\TestCase\Test
  14. {
  15. /** @var Parsedown $parsedown */
  16. protected $parsedown;
  17. /** @var Grav $grav */
  18. protected $grav;
  19. /** @var Pages $pages */
  20. protected $pages;
  21. /** @var Config $config */
  22. protected $config;
  23. /** @var Uri $uri */
  24. protected $uri;
  25. /** @var Language $language */
  26. protected $language;
  27. protected $old_home;
  28. protected function _before()
  29. {
  30. $grav = Fixtures::get('grav');
  31. $this->grav = $grav();
  32. $this->pages = $this->grav['pages'];
  33. $this->config = $this->grav['config'];
  34. $this->uri = $this->grav['uri'];
  35. $this->language = $this->grav['language'];
  36. $this->old_home = $this->config->get('system.home.alias');
  37. $this->config->set('system.home.alias', '/item1');
  38. $this->config->set('system.absolute_urls', false);
  39. $this->config->set('system.languages.supported', []);
  40. unset($this->grav['language']);
  41. $this->grav['language'] = new Language($this->grav);
  42. /** @var UniformResourceLocator $locator */
  43. $locator = $this->grav['locator'];
  44. $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
  45. $this->pages->init();
  46. $defaults = [
  47. 'markdown' => [
  48. 'extra' => false,
  49. 'auto_line_breaks' => false,
  50. 'auto_url_links' => false,
  51. 'escape_markup' => false,
  52. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  53. ],
  54. 'images' => $this->config->get('system.images', [])
  55. ];
  56. $page = $this->pages->dispatch('/item2/item2-2');
  57. $excerpts = new Excerpts($page, $defaults);
  58. $this->parsedown = new Parsedown($excerpts);
  59. }
  60. protected function _after()
  61. {
  62. $this->config->set('system.home.alias', $this->old_home);
  63. }
  64. public function testImages()
  65. {
  66. $this->config->set('system.languages.supported', ['fr','en']);
  67. unset($this->grav['language']);
  68. $this->grav['language'] = new Language($this->grav);
  69. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  70. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  71. $this->parsedown->text('![](sample-image.jpg)'));
  72. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
  73. $this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
  74. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  75. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  76. $this->parsedown->text('![](sample-image.jpg)'));
  77. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
  78. $this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
  79. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  80. $this->parsedown->text('![](/home-cache-image.jpg?cache)'));
  81. $this->assertSame('<p><img src="/item2/item2-2/missing-image.jpg" alt="" /></p>',
  82. $this->parsedown->text('![](missing-image.jpg)'));
  83. $this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
  84. $this->parsedown->text('![](/home-missing-image.jpg)'));
  85. $this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
  86. $this->parsedown->text('![](/home-missing-image.jpg)'));
  87. $this->assertSame('<p><img src="https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg" alt="" /></p>',
  88. $this->parsedown->text('![](https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg)'));
  89. }
  90. public function testImagesSubDir()
  91. {
  92. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  93. $this->assertRegexp('|<p><img alt="" src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  94. $this->parsedown->text('![](/home-cache-image.jpg?cache)'));
  95. $this->assertSame('<p><img alt="" src="/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  96. $this->parsedown->text('![](sample-image.jpg)'));
  97. $this->assertRegexp('|<p><img alt="" src="\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  98. $this->parsedown->text('![](cache-image.jpg?cache)'));
  99. $this->assertSame('<p><img src="/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
  100. $this->parsedown->text('![](missing-image.jpg)'));
  101. $this->assertSame('<p><img src="/subdir/home-missing-image.jpg" alt="" /></p>',
  102. $this->parsedown->text('![](/home-missing-image.jpg)'));
  103. }
  104. public function testImagesAbsoluteUrls()
  105. {
  106. $this->config->set('system.absolute_urls', true);
  107. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  108. $this->assertSame('<p><img alt="" src="http://testing.dev/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  109. $this->parsedown->text('![](sample-image.jpg)'));
  110. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  111. $this->parsedown->text('![](cache-image.jpg?cache)'));
  112. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  113. $this->parsedown->text('![](/home-cache-image.jpg?cache)'));
  114. $this->assertSame('<p><img src="http://testing.dev/item2/item2-2/missing-image.jpg" alt="" /></p>',
  115. $this->parsedown->text('![](missing-image.jpg)'));
  116. $this->assertSame('<p><img src="http://testing.dev/home-missing-image.jpg" alt="" /></p>',
  117. $this->parsedown->text('![](/home-missing-image.jpg)'));
  118. }
  119. public function testImagesSubDirAbsoluteUrls()
  120. {
  121. $this->config->set('system.absolute_urls', true);
  122. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  123. $this->assertSame('<p><img alt="" src="http://testing.dev/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  124. $this->parsedown->text('![](sample-image.jpg)'));
  125. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  126. $this->parsedown->text('![](cache-image.jpg?cache)'));
  127. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  128. $this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)'));
  129. $this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
  130. $this->parsedown->text('![](missing-image.jpg)'));
  131. $this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
  132. $this->parsedown->text('![](/home-missing-image.jpg)'));
  133. }
  134. public function testImagesAttributes()
  135. {
  136. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  137. $this->assertSame('<p><img title="My Title" alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  138. $this->parsedown->text('![](sample-image.jpg "My Title")'));
  139. $this->assertSame('<p><img alt="" class="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  140. $this->parsedown->text('![](sample-image.jpg?classes=foo)'));
  141. $this->assertSame('<p><img alt="" class="foo bar" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  142. $this->parsedown->text('![](sample-image.jpg?classes=foo,bar)'));
  143. $this->assertSame('<p><img alt="" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  144. $this->parsedown->text('![](sample-image.jpg?id=foo)'));
  145. $this->assertSame('<p><img alt="Alt Text" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  146. $this->parsedown->text('![Alt Text](sample-image.jpg?id=foo)'));
  147. $this->assertSame('<p><img alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  148. $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo)'));
  149. $this->assertSame('<p><img title="My Title" alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  150. $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo "My Title")'));
  151. }
  152. public function testRootImages()
  153. {
  154. $this->uri->initializeWithURL('http://testing.dev/')->init();
  155. $defaults = [
  156. 'markdown' => [
  157. 'extra' => false,
  158. 'auto_line_breaks' => false,
  159. 'auto_url_links' => false,
  160. 'escape_markup' => false,
  161. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  162. ],
  163. 'images' => $this->config->get('system.images', [])
  164. ];
  165. $page = $this->pages->dispatch('/');
  166. $excerpts = new Excerpts($page, $defaults);
  167. $this->parsedown = new Parsedown($excerpts);
  168. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
  169. $this->parsedown->text('![](home-sample-image.jpg)'));
  170. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  171. $this->parsedown->text('![](home-cache-image.jpg?cache)'));
  172. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-home-cache-image.jpe?g\?foo=1" \/><\/p>|',
  173. $this->parsedown->text('![](home-cache-image.jpg?cropResize=200,200&foo)'));
  174. $this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
  175. $this->parsedown->text('![](/home-missing-image.jpg)'));
  176. $this->config->set('system.languages.supported', ['fr','en']);
  177. unset($this->grav['language']);
  178. $this->grav['language'] = new Language($this->grav);
  179. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  180. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
  181. $this->parsedown->text('![](home-sample-image.jpg)'));
  182. }
  183. public function testRootImagesSubDirAbsoluteUrls()
  184. {
  185. $this->config->set('system.absolute_urls', true);
  186. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  187. $this->assertSame('<p><img alt="" src="http://testing.dev/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  188. $this->parsedown->text('![](sample-image.jpg)'));
  189. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  190. $this->parsedown->text('![](cache-image.jpg?cache)'));
  191. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  192. $this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)'));
  193. $this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
  194. $this->parsedown->text('![](missing-image.jpg)'));
  195. $this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
  196. $this->parsedown->text('![](/home-missing-image.jpg)'));
  197. }
  198. public function testRootAbsoluteLinks()
  199. {
  200. $this->uri->initializeWithURL('http://testing.dev/')->init();
  201. $defaults = [
  202. 'markdown' => [
  203. 'extra' => false,
  204. 'auto_line_breaks' => false,
  205. 'auto_url_links' => false,
  206. 'escape_markup' => false,
  207. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  208. ],
  209. 'images' => $this->config->get('system.images', [])
  210. ];
  211. $page = $this->pages->dispatch('/');
  212. $excerpts = new Excerpts($page, $defaults);
  213. $this->parsedown = new Parsedown($excerpts);
  214. $this->assertSame('<p><a href="/item1/item1-3">Down a Level</a></p>',
  215. $this->parsedown->text('[Down a Level](item1-3)'));
  216. $this->assertSame('<p><a href="/item2">Peer Page</a></p>',
  217. $this->parsedown->text('[Peer Page](../item2)'));
  218. $this->assertSame('<p><a href="/?foo=bar">With Query</a></p>',
  219. $this->parsedown->text('[With Query](?foo=bar)'));
  220. $this->assertSame('<p><a href="/foo:bar">With Param</a></p>',
  221. $this->parsedown->text('[With Param](/foo:bar)'));
  222. $this->assertSame('<p><a href="#foo">With Anchor</a></p>',
  223. $this->parsedown->text('[With Anchor](#foo)'));
  224. $this->config->set('system.languages.supported', ['fr','en']);
  225. unset($this->grav['language']);
  226. $this->grav['language'] = new Language($this->grav);
  227. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  228. $this->assertSame('<p><a href="/fr/item2">Peer Page</a></p>',
  229. $this->parsedown->text('[Peer Page](../item2)'));
  230. $this->assertSame('<p><a href="/fr/item1/item1-3">Down a Level</a></p>',
  231. $this->parsedown->text('[Down a Level](item1-3)'));
  232. $this->assertSame('<p><a href="/fr/?foo=bar">With Query</a></p>',
  233. $this->parsedown->text('[With Query](?foo=bar)'));
  234. $this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>',
  235. $this->parsedown->text('[With Param](/foo:bar)'));
  236. $this->assertSame('<p><a href="#foo">With Anchor</a></p>',
  237. $this->parsedown->text('[With Anchor](#foo)'));
  238. }
  239. public function testAnchorLinksLangRelativeUrls()
  240. {
  241. $this->config->set('system.languages.supported', ['fr','en']);
  242. unset($this->grav['language']);
  243. $this->grav['language'] = new Language($this->grav);
  244. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  245. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  246. $this->parsedown->text('[Current Anchor](#foo)'));
  247. $this->assertSame('<p><a href="/fr/#foo">Root Anchor</a></p>',
  248. $this->parsedown->text('[Root Anchor](/#foo)'));
  249. $this->assertSame('<p><a href="/fr/item2/item2-1#foo">Peer Anchor</a></p>',
  250. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  251. $this->assertSame('<p><a href="/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
  252. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  253. }
  254. public function testAnchorLinksLangAbsoluteUrls()
  255. {
  256. $this->config->set('system.absolute_urls', true);
  257. $this->config->set('system.languages.supported', ['fr','en']);
  258. unset($this->grav['language']);
  259. $this->grav['language'] = new Language($this->grav);
  260. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  261. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  262. $this->parsedown->text('[Current Anchor](#foo)'));
  263. $this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor</a></p>',
  264. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  265. $this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
  266. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  267. $this->assertSame('<p><a href="http://testing.dev/fr/#foo">Root Anchor</a></p>',
  268. $this->parsedown->text('[Root Anchor](/#foo)'));
  269. }
  270. public function testExternalLinks()
  271. {
  272. $this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
  273. $this->parsedown->text('[cnn.com](http://www.cnn.com)'));
  274. $this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
  275. $this->parsedown->text('[google.com](https://www.google.com)'));
  276. $this->assertSame('<p><a href="https://github.com/getgrav/grav/issues/new?title=%5Badd-resource%5D%20New%20Plugin%2FTheme&body=Hello%20%2A%2AThere%2A%2A">complex url</a></p>',
  277. $this->parsedown->text('[complex url](https://github.com/getgrav/grav/issues/new?title=[add-resource]%20New%20Plugin/Theme&body=Hello%20**There**)'));
  278. }
  279. public function testExternalLinksSubDir()
  280. {
  281. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  282. $this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
  283. $this->parsedown->text('[cnn.com](http://www.cnn.com)'));
  284. $this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
  285. $this->parsedown->text('[google.com](https://www.google.com)'));
  286. }
  287. public function testExternalLinksSubDirAbsoluteUrls()
  288. {
  289. $this->config->set('system.absolute_urls', true);
  290. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  291. $this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
  292. $this->parsedown->text('[cnn.com](http://www.cnn.com)'));
  293. $this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
  294. $this->parsedown->text('[google.com](https://www.google.com)'));
  295. }
  296. public function testAnchorLinksRelativeUrls()
  297. {
  298. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  299. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  300. $this->parsedown->text('[Current Anchor](#foo)'));
  301. $this->assertSame('<p><a href="/#foo">Root Anchor</a></p>',
  302. $this->parsedown->text('[Root Anchor](/#foo)'));
  303. $this->assertSame('<p><a href="/item2/item2-1#foo">Peer Anchor</a></p>',
  304. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  305. $this->assertSame('<p><a href="/item2/item2-1#foo">Peer Anchor 2</a></p>',
  306. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  307. }
  308. public function testAnchorLinksAbsoluteUrls()
  309. {
  310. $this->config->set('system.absolute_urls', true);
  311. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  312. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  313. $this->parsedown->text('[Current Anchor](#foo)'));
  314. $this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor</a></p>',
  315. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  316. $this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor 2</a></p>',
  317. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  318. $this->assertSame('<p><a href="http://testing.dev/#foo">Root Anchor</a></p>',
  319. $this->parsedown->text('[Root Anchor](/#foo)'));
  320. }
  321. public function testAnchorLinksWithPortAbsoluteUrls()
  322. {
  323. $this->config->set('system.absolute_urls', true);
  324. $this->uri->initializeWithURL('http://testing.dev:8080/item2/item2-2')->init();
  325. $this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor</a></p>',
  326. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  327. $this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor 2</a></p>',
  328. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  329. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  330. $this->parsedown->text('[Current Anchor](#foo)'));
  331. $this->assertSame('<p><a href="http://testing.dev:8080/#foo">Root Anchor</a></p>',
  332. $this->parsedown->text('[Root Anchor](/#foo)'));
  333. }
  334. public function testAnchorLinksSubDirRelativeUrls()
  335. {
  336. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  337. $this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor</a></p>',
  338. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  339. $this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
  340. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  341. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  342. $this->parsedown->text('[Current Anchor](#foo)'));
  343. $this->assertSame('<p><a href="/subdir/#foo">Root Anchor</a></p>',
  344. $this->parsedown->text('[Root Anchor](/#foo)'));
  345. }
  346. public function testAnchorLinksSubDirAbsoluteUrls()
  347. {
  348. $this->config->set('system.absolute_urls', true);
  349. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  350. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor</a></p>',
  351. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  352. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
  353. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  354. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  355. $this->parsedown->text('[Current Anchor](#foo)'));
  356. $this->assertSame('<p><a href="http://testing.dev/subdir/#foo">Root Anchor</a></p>',
  357. $this->parsedown->text('[Root Anchor](/#foo)'));
  358. }
  359. public function testSlugRelativeLinks()
  360. {
  361. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  362. $this->assertSame('<p><a href="/">Up to Root Level</a></p>',
  363. $this->parsedown->text('[Up to Root Level](../..)'));
  364. $this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
  365. $this->parsedown->text('[Peer Page](../item2-1)'));
  366. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
  367. $this->parsedown->text('[Down a Level](item2-2-1)'));
  368. $this->assertSame('<p><a href="/item2">Up a Level</a></p>',
  369. $this->parsedown->text('[Up a Level](..)'));
  370. $this->assertSame('<p><a href="/item3/item3-3">Up and Down</a></p>',
  371. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  372. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  373. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  374. $this->assertSame('<p><a href="/item2?foo=bar">Up a Level with Query</a></p>',
  375. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  376. $this->assertSame('<p><a href="/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  377. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  378. $this->assertSame('<p><a href="/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  379. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  380. $this->assertSame('<p><a href="/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  381. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  382. }
  383. public function testSlugRelativeLinksAbsoluteUrls()
  384. {
  385. $this->config->set('system.absolute_urls', true);
  386. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  387. $this->assertSame('<p><a href="http://testing.dev/item2/item2-1">Peer Page</a></p>',
  388. $this->parsedown->text('[Peer Page](../item2-1)'));
  389. $this->assertSame('<p><a href="http://testing.dev/item2/item2-2/item2-2-1">Down a Level</a></p>',
  390. $this->parsedown->text('[Down a Level](item2-2-1)'));
  391. $this->assertSame('<p><a href="http://testing.dev/item2">Up a Level</a></p>',
  392. $this->parsedown->text('[Up a Level](..)'));
  393. $this->assertSame('<p><a href="http://testing.dev/">Up to Root Level</a></p>',
  394. $this->parsedown->text('[Up to Root Level](../..)'));
  395. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3">Up and Down</a></p>',
  396. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  397. $this->assertSame('<p><a href="http://testing.dev/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  398. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  399. $this->assertSame('<p><a href="http://testing.dev/item2?foo=bar">Up a Level with Query</a></p>',
  400. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  401. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  402. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  403. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  404. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  405. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  406. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  407. }
  408. public function testSlugRelativeLinksSubDir()
  409. {
  410. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  411. $this->assertSame('<p><a href="/subdir/item2/item2-1">Peer Page</a></p>',
  412. $this->parsedown->text('[Peer Page](../item2-1)'));
  413. $this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  414. $this->parsedown->text('[Down a Level](item2-2-1)'));
  415. $this->assertSame('<p><a href="/subdir/item2">Up a Level</a></p>',
  416. $this->parsedown->text('[Up a Level](..)'));
  417. $this->assertSame('<p><a href="/subdir">Up to Root Level</a></p>',
  418. $this->parsedown->text('[Up to Root Level](../..)'));
  419. $this->assertSame('<p><a href="/subdir/item3/item3-3">Up and Down</a></p>',
  420. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  421. $this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  422. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  423. $this->assertSame('<p><a href="/subdir/item2?foo=bar">Up a Level with Query</a></p>',
  424. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  425. $this->assertSame('<p><a href="/subdir/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  426. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  427. $this->assertSame('<p><a href="/subdir/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  428. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  429. $this->assertSame('<p><a href="/subdir/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  430. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  431. }
  432. public function testSlugRelativeLinksSubDirAbsoluteUrls()
  433. {
  434. $this->config->set('system.absolute_urls', true);
  435. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  436. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1">Peer Page</a></p>',
  437. $this->parsedown->text('[Peer Page](../item2-1)'));
  438. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  439. $this->parsedown->text('[Down a Level](item2-2-1)'));
  440. $this->assertSame('<p><a href="http://testing.dev/subdir/item2">Up a Level</a></p>',
  441. $this->parsedown->text('[Up a Level](..)'));
  442. $this->assertSame('<p><a href="http://testing.dev/subdir">Up to Root Level</a></p>',
  443. $this->parsedown->text('[Up to Root Level](../..)'));
  444. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3">Up and Down</a></p>',
  445. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  446. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  447. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  448. $this->assertSame('<p><a href="http://testing.dev/subdir/item2?foo=bar">Up a Level with Query</a></p>',
  449. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  450. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  451. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  452. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  453. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  454. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  455. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  456. }
  457. public function testDirectoryRelativeLinks()
  458. {
  459. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  460. $this->assertSame('<p><a href="/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  461. $this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)'));
  462. $this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
  463. $this->parsedown->text('[Peer Page](../01.item2-1)'));
  464. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
  465. $this->parsedown->text('[Down a Level](01.item2-2-1)'));
  466. $this->assertSame('<p><a href="/item3/item3-3">Up and Down</a></p>',
  467. $this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)'));
  468. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  469. $this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)'));
  470. $this->assertSame('<p><a href="/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  471. $this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)'));
  472. $this->assertSame('<p><a href="/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  473. $this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)'));
  474. }
  475. public function testAbsoluteLinks()
  476. {
  477. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  478. $this->assertSame('<p><a href="/">Root</a></p>',
  479. $this->parsedown->text('[Root](/)'));
  480. $this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
  481. $this->parsedown->text('[Peer Page](/item2/item2-1)'));
  482. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
  483. $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
  484. $this->assertSame('<p><a href="/item2">Up a Level</a></p>',
  485. $this->parsedown->text('[Up a Level](/item2)'));
  486. $this->assertSame('<p><a href="/item2?foo=bar">With Query</a></p>',
  487. $this->parsedown->text('[With Query](/item2?foo=bar)'));
  488. $this->assertSame('<p><a href="/item2/foo:bar">With Param</a></p>',
  489. $this->parsedown->text('[With Param](/item2/foo:bar)'));
  490. $this->assertSame('<p><a href="/item2#foo">With Anchor</a></p>',
  491. $this->parsedown->text('[With Anchor](/item2#foo)'));
  492. }
  493. public function testDirectoryAbsoluteLinksSubDir()
  494. {
  495. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  496. $this->assertSame('<p><a href="/subdir/">Root</a></p>',
  497. $this->parsedown->text('[Root](/)'));
  498. $this->assertSame('<p><a href="/subdir/item2/item2-1">Peer Page</a></p>',
  499. $this->parsedown->text('[Peer Page](/item2/item2-1)'));
  500. $this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  501. $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
  502. $this->assertSame('<p><a href="/subdir/item2">Up a Level</a></p>',
  503. $this->parsedown->text('[Up a Level](/item2)'));
  504. $this->assertSame('<p><a href="/subdir/item2?foo=bar">With Query</a></p>',
  505. $this->parsedown->text('[With Query](/item2?foo=bar)'));
  506. $this->assertSame('<p><a href="/subdir/item2/foo:bar">With Param</a></p>',
  507. $this->parsedown->text('[With Param](/item2/foo:bar)'));
  508. $this->assertSame('<p><a href="/subdir/item2#foo">With Anchor</a></p>',
  509. $this->parsedown->text('[With Anchor](/item2#foo)'));
  510. }
  511. public function testDirectoryAbsoluteLinksSubDirAbsoluteUrl()
  512. {
  513. $this->config->set('system.absolute_urls', true);
  514. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  515. $this->assertSame('<p><a href="http://testing.dev/subdir/">Root</a></p>',
  516. $this->parsedown->text('[Root](/)'));
  517. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1">Peer Page</a></p>',
  518. $this->parsedown->text('[Peer Page](/item2/item2-1)'));
  519. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  520. $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
  521. $this->assertSame('<p><a href="http://testing.dev/subdir/item2">Up a Level</a></p>',
  522. $this->parsedown->text('[Up a Level](/item2)'));
  523. $this->assertSame('<p><a href="http://testing.dev/subdir/item2?foo=bar">With Query</a></p>',
  524. $this->parsedown->text('[With Query](/item2?foo=bar)'));
  525. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/foo:bar">With Param</a></p>',
  526. $this->parsedown->text('[With Param](/item2/foo:bar)'));
  527. $this->assertSame('<p><a href="http://testing.dev/subdir/item2#foo">With Anchor</a></p>',
  528. $this->parsedown->text('[With Anchor](/item2#foo)'));
  529. }
  530. public function testSpecialProtocols()
  531. {
  532. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  533. $this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
  534. $this->parsedown->text('[mailto](mailto:user@domain.com)'));
  535. $this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
  536. $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
  537. $this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
  538. $this->parsedown->text('[tel](tel:123-555-12345)'));
  539. $this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
  540. $this->parsedown->text('[sms](sms:123-555-12345)'));
  541. $this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
  542. $this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
  543. }
  544. public function testSpecialProtocolsSubDir()
  545. {
  546. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  547. $this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
  548. $this->parsedown->text('[mailto](mailto:user@domain.com)'));
  549. $this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
  550. $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
  551. $this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
  552. $this->parsedown->text('[tel](tel:123-555-12345)'));
  553. $this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
  554. $this->parsedown->text('[sms](sms:123-555-12345)'));
  555. $this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
  556. $this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
  557. }
  558. public function testSpecialProtocolsSubDirAbsoluteUrl()
  559. {
  560. $this->config->set('system.absolute_urls', true);
  561. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  562. $this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
  563. $this->parsedown->text('[mailto](mailto:user@domain.com)'));
  564. $this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
  565. $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
  566. $this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
  567. $this->parsedown->text('[tel](tel:123-555-12345)'));
  568. $this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
  569. $this->parsedown->text('[sms](sms:123-555-12345)'));
  570. $this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
  571. $this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
  572. }
  573. public function testReferenceLinks()
  574. {
  575. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  576. $sample = '[relative link][r_relative]
  577. [r_relative]: ../item2-3#blah';
  578. $this->assertSame('<p><a href="/item2/item2-3#blah">relative link</a></p>',
  579. $this->parsedown->text($sample));
  580. $sample = '[absolute link][r_absolute]
  581. [r_absolute]: /item3#blah';
  582. $this->assertSame('<p><a href="/item3#blah">absolute link</a></p>',
  583. $this->parsedown->text($sample));
  584. $sample = '[external link][r_external]
  585. [r_external]: http://www.cnn.com';
  586. $this->assertSame('<p><a href="http://www.cnn.com">external link</a></p>',
  587. $this->parsedown->text($sample));
  588. }
  589. public function testAttributeLinks()
  590. {
  591. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  592. $this->assertSame('<p><a href="#something" class="button">Anchor Class</a></p>',
  593. $this->parsedown->text('[Anchor Class](?classes=button#something)'));
  594. $this->assertSame('<p><a href="/item2/item2-3" class="button">Relative Class</a></p>',
  595. $this->parsedown->text('[Relative Class](../item2-3?classes=button)'));
  596. $this->assertSame('<p><a href="/item2/item2-3" id="unique">Relative ID</a></p>',
  597. $this->parsedown->text('[Relative ID](../item2-3?id=unique)'));
  598. $this->assertSame('<p><a href="https://github.com/getgrav/grav" class="button big">External</a></p>',
  599. $this->parsedown->text('[External](https://github.com/getgrav/grav?classes=button,big)'));
  600. $this->assertSame('<p><a href="/item2/item2-3?id=unique">Relative Noprocess</a></p>',
  601. $this->parsedown->text('[Relative Noprocess](../item2-3?id=unique&noprocess)'));
  602. $this->assertSame('<p><a href="/item2/item2-3" target="_blank">Relative Target</a></p>',
  603. $this->parsedown->text('[Relative Target](../item2-3?target=_blank)'));
  604. $this->assertSame('<p><a href="/item2/item2-3" rel="nofollow">Relative Rel</a></p>',
  605. $this->parsedown->text('[Relative Rel](../item2-3?rel=nofollow)'));
  606. $this->assertSame('<p><a href="/item2/item2-3?foo=bar&baz=qux" rel="nofollow" class="button">Relative Mixed</a></p>',
  607. $this->parsedown->text('[Relative Mixed](../item2-3?foo=bar&baz=qux&rel=nofollow&class=button)'));
  608. }
  609. public function testInvalidLinks()
  610. {
  611. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  612. $this->assertSame('<p><a href="/item2/item2-2/no-page">Non Existent Page</a></p>',
  613. $this->parsedown->text('[Non Existent Page](no-page)'));
  614. $this->assertSame('<p><a href="/item2/item2-2/existing-file.zip">Existent File</a></p>',
  615. $this->parsedown->text('[Existent File](existing-file.zip)'));
  616. $this->assertSame('<p><a href="/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
  617. $this->parsedown->text('[Non Existent File](missing-file.zip)'));
  618. }
  619. public function testInvalidLinksSubDir()
  620. {
  621. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  622. $this->assertSame('<p><a href="/subdir/item2/item2-2/no-page">Non Existent Page</a></p>',
  623. $this->parsedown->text('[Non Existent Page](no-page)'));
  624. $this->assertSame('<p><a href="/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>',
  625. $this->parsedown->text('[Existent File](existing-file.zip)'));
  626. $this->assertSame('<p><a href="/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
  627. $this->parsedown->text('[Non Existent File](missing-file.zip)'));
  628. }
  629. public function testInvalidLinksSubDirAbsoluteUrl()
  630. {
  631. $this->config->set('system.absolute_urls', true);
  632. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  633. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/no-page">Non Existent Page</a></p>',
  634. $this->parsedown->text('[Non Existent Page](no-page)'));
  635. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>',
  636. $this->parsedown->text('[Existent File](existing-file.zip)'));
  637. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
  638. $this->parsedown->text('[Non Existent File](missing-file.zip)'));
  639. }
  640. /**
  641. * @param $string
  642. *
  643. * @return mixed
  644. */
  645. private function stripLeadingWhitespace($string)
  646. {
  647. return preg_replace('/^\s*(.*)/', '', $string);
  648. }
  649. }