ParsedownTest.php 42 KB

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