grav = $grav(); $this->pages = $this->grav['pages']; $this->config = $this->grav['config']; $this->uri = $this->grav['uri']; $this->language = $this->grav['language']; $this->old_home = $this->config->get('system.home.alias'); $this->config->set('system.home.alias', '/item1'); $this->config->set('system.absolute_urls', false); $this->config->set('system.languages.supported', []); unset($this->grav['language']); $this->grav['language'] = new Language($this->grav); /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false); $this->pages->init(); $defaults = [ 'markdown' => [ 'extra' => false, 'auto_line_breaks' => false, 'auto_url_links' => false, 'escape_markup' => false, 'special_chars' => ['>' => 'gt', '<' => 'lt'], ], 'images' => $this->config->get('system.images', []) ]; $page = $this->pages->find('/item2/item2-2'); $excerpts = new Excerpts($page, $defaults); $this->parsedown = new Parsedown($excerpts); } protected function _after(): void { $this->config->set('system.home.alias', $this->old_home); } public function testImages(): void { $this->config->set('system.languages.supported', ['fr','en']); unset($this->grav['language']); $this->grav['language'] = new Language($this->grav); $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init(); self::assertSame( '
', $this->parsedown->text('![](sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)') ); $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '
', $this->parsedown->text('![](sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)') ); self::assertRegexp( '|
<\/p>|', $this->parsedown->text('![](/home-cache-image.jpg?cache)') ); self::assertSame( '
', $this->parsedown->text('![](missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](/home-missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](/home-missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg)') ); } public function testImagesSubDir(): void { $this->config->set('system.images.cache_all', false); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](/home-cache-image.jpg?cache)') ); self::assertSame( '
', $this->parsedown->text('![](sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](cache-image.jpg?cache)') ); self::assertSame( '
', $this->parsedown->text('![](missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](/home-missing-image.jpg)') ); } public function testImagesAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](cache-image.jpg?cache)') ); self::assertRegexp( '|
<\/p>|', $this->parsedown->text('![](/home-cache-image.jpg?cache)') ); self::assertSame( '
', $this->parsedown->text('![](missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](/home-missing-image.jpg)') ); } public function testImagesSubDirAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](cache-image.jpg?cache)') ); self::assertRegexp( '|
<\/p>|', $this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)') ); self::assertSame( '
', $this->parsedown->text('![](missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](/home-missing-image.jpg)') ); } public function testImagesAttributes(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg "My Title")') ); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg?classes=foo)') ); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg?classes=foo,bar)') ); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg?id=foo)') ); self::assertSame( '', $this->parsedown->text('![Alt Text](sample-image.jpg?id=foo)') ); self::assertSame( '', $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo)') ); self::assertSame( '', $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo "My Title")') ); } public function testRootImages(): void { $this->uri->initializeWithURL('http://testing.dev/')->init(); $defaults = [ 'markdown' => [ 'extra' => false, 'auto_line_breaks' => false, 'auto_url_links' => false, 'escape_markup' => false, 'special_chars' => ['>' => 'gt', '<' => 'lt'], ], 'images' => $this->config->get('system.images', []) ]; $page = $this->pages->find('/'); $excerpts = new Excerpts($page, $defaults); $this->parsedown = new Parsedown($excerpts); self::assertSame( '', $this->parsedown->text('![](home-sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](home-cache-image.jpg?cache)') ); self::assertRegexp( '|
<\/p>|', $this->parsedown->text('![](home-cache-image.jpg?cropResize=200,200&foo)') ); self::assertSame( '
', $this->parsedown->text('![](/home-missing-image.jpg)') ); $this->config->set('system.languages.supported', ['fr','en']); unset($this->grav['language']); $this->grav['language'] = new Language($this->grav); $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('![](home-sample-image.jpg)') ); } public function testRootImagesSubDirAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('![](sample-image.jpg)') ); self::assertRegexp( '|<\/p>|', $this->parsedown->text('![](cache-image.jpg?cache)') ); self::assertRegexp( '|
<\/p>|', $this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)') ); self::assertSame( '
', $this->parsedown->text('![](missing-image.jpg)') ); self::assertSame( '', $this->parsedown->text('![](/home-missing-image.jpg)') ); } public function testRootAbsoluteLinks(): void { $this->uri->initializeWithURL('http://testing.dev/')->init(); $defaults = [ 'markdown' => [ 'extra' => false, 'auto_line_breaks' => false, 'auto_url_links' => false, 'escape_markup' => false, 'special_chars' => ['>' => 'gt', '<' => 'lt'], ], 'images' => $this->config->get('system.images', []) ]; $page = $this->pages->find('/'); $excerpts = new Excerpts($page, $defaults); $this->parsedown = new Parsedown($excerpts); self::assertSame( '', $this->parsedown->text('[Down a Level](item1-3)') ); self::assertSame( '', $this->parsedown->text('[Peer Page](../item2)') ); self::assertSame( '', $this->parsedown->text('[With Query](?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[With Param](/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[With Anchor](#foo)') ); $this->config->set('system.languages.supported', ['fr','en']); unset($this->grav['language']); $this->grav['language'] = new Language($this->grav); $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Peer Page](../item2)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](item1-3)') ); self::assertSame( '', $this->parsedown->text('[With Query](?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[With Param](/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[With Anchor](#foo)') ); } public function testAnchorLinksLangRelativeUrls(): void { $this->config->set('system.languages.supported', ['fr','en']); unset($this->grav['language']); $this->grav['language'] = new Language($this->grav); $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); } public function testAnchorLinksLangAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->config->set('system.languages.supported', ['fr','en']); unset($this->grav['language']); $this->grav['language'] = new Language($this->grav); $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); } public function testExternalLinks(): void { self::assertSame( '', $this->parsedown->text('[cnn.com](http://www.cnn.com)') ); self::assertSame( '', $this->parsedown->text('[google.com](https://www.google.com)') ); self::assertSame( '', $this->parsedown->text('[complex url](https://github.com/getgrav/grav/issues/new?title=[add-resource]%20New%20Plugin/Theme&body=Hello%20**There**)') ); } public function testExternalLinksSubDir(): void { $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[cnn.com](http://www.cnn.com)') ); self::assertSame( '', $this->parsedown->text('[google.com](https://www.google.com)') ); } public function testExternalLinksSubDirAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[cnn.com](http://www.cnn.com)') ); self::assertSame( '', $this->parsedown->text('[google.com](https://www.google.com)') ); } public function testAnchorLinksRelativeUrls(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); } public function testAnchorLinksAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); } public function testAnchorLinksWithPortAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithURL('http://testing.dev:8080/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); } public function testAnchorLinksSubDirRelativeUrls(): void { $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); } public function testAnchorLinksSubDirAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Peer Anchor](../item2-1#foo)') ); self::assertSame( '', $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)') ); self::assertSame( '', $this->parsedown->text('[Current Anchor](#foo)') ); self::assertSame( '', $this->parsedown->text('[Root Anchor](/#foo)') ); } public function testSlugRelativeLinks(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Up to Root Level](../..)') ); self::assertSame( '', $this->parsedown->text('[Peer Page](../item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](..)') ); self::assertSame( '', $this->parsedown->text('[Up and Down](../../item3/item3-3)') ); self::assertSame( '', $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up a Level with Query](../?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)') ); } public function testSlugRelativeLinksAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Peer Page](../item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](..)') ); self::assertSame( '', $this->parsedown->text('[Up to Root Level](../..)') ); self::assertSame( '', $this->parsedown->text('[Up and Down](../../item3/item3-3)') ); self::assertSame( '', $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up a Level with Query](../?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)') ); } public function testSlugRelativeLinksSubDir(): void { $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Peer Page](../item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](..)') ); self::assertSame( '', $this->parsedown->text('[Up to Root Level](../..)') ); self::assertSame( '', $this->parsedown->text('[Up and Down](../../item3/item3-3)') ); self::assertSame( '', $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up a Level with Query](../?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)') ); } public function testSlugRelativeLinksSubDirAbsoluteUrls(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Peer Page](../item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](..)') ); self::assertSame( '', $this->parsedown->text('[Up to Root Level](../..)') ); self::assertSame( '', $this->parsedown->text('[Up and Down](../../item3/item3-3)') ); self::assertSame( '', $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up a Level with Query](../?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)') ); } public function testDirectoryRelativeLinks(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[Peer Page](../01.item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](01.item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)') ); self::assertSame( '', $this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)') ); } public function testAbsoluteLinks(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Root](/)') ); self::assertSame( '', $this->parsedown->text('[Peer Page](/item2/item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](/item2)') ); self::assertSame( '', $this->parsedown->text('[With Query](/item2?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[With Param](/item2/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[With Anchor](/item2#foo)') ); } public function testDirectoryAbsoluteLinksSubDir(): void { $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Root](/)') ); self::assertSame( '', $this->parsedown->text('[Peer Page](/item2/item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](/item2)') ); self::assertSame( '', $this->parsedown->text('[With Query](/item2?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[With Param](/item2/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[With Anchor](/item2#foo)') ); } public function testDirectoryAbsoluteLinksSubDirAbsoluteUrl(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Root](/)') ); self::assertSame( '', $this->parsedown->text('[Peer Page](/item2/item2-1)') ); self::assertSame( '', $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)') ); self::assertSame( '', $this->parsedown->text('[Up a Level](/item2)') ); self::assertSame( '', $this->parsedown->text('[With Query](/item2?foo=bar)') ); self::assertSame( '', $this->parsedown->text('[With Param](/item2/foo:bar)') ); self::assertSame( '', $this->parsedown->text('[With Anchor](/item2#foo)') ); } public function testSpecialProtocols(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[mailto](mailto:user@domain.com)') ); self::assertSame( '', $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)') ); self::assertSame( '', $this->parsedown->text('[tel](tel:123-555-12345)') ); self::assertSame( '', $this->parsedown->text('[sms](sms:123-555-12345)') ); self::assertSame( '', $this->parsedown->text('[ts.example.com](rdp://ts.example.com)') ); } public function testSpecialProtocolsSubDir(): void { $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[mailto](mailto:user@domain.com)') ); self::assertSame( '', $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)') ); self::assertSame( '', $this->parsedown->text('[tel](tel:123-555-12345)') ); self::assertSame( '', $this->parsedown->text('[sms](sms:123-555-12345)') ); self::assertSame( '', $this->parsedown->text('[ts.example.com](rdp://ts.example.com)') ); } public function testSpecialProtocolsSubDirAbsoluteUrl(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[mailto](mailto:user@domain.com)') ); self::assertSame( '', $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)') ); self::assertSame( '', $this->parsedown->text('[tel](tel:123-555-12345)') ); self::assertSame( '', $this->parsedown->text('[sms](sms:123-555-12345)') ); self::assertSame( '', $this->parsedown->text('[ts.example.com](rdp://ts.example.com)') ); } public function testReferenceLinks(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); $sample = '[relative link][r_relative] [r_relative]: ../item2-3#blah'; self::assertSame( '', $this->parsedown->text($sample) ); $sample = '[absolute link][r_absolute] [r_absolute]: /item3#blah'; self::assertSame( '', $this->parsedown->text($sample) ); $sample = '[external link][r_external] [r_external]: http://www.cnn.com'; self::assertSame( '', $this->parsedown->text($sample) ); } public function testAttributeLinks(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Anchor Class](?classes=button#something)') ); self::assertSame( '', $this->parsedown->text('[Relative Class](../item2-3?classes=button)') ); self::assertSame( '', $this->parsedown->text('[Relative ID](../item2-3?id=unique)') ); self::assertSame( '', $this->parsedown->text('[External](https://github.com/getgrav/grav?classes=button,big)') ); self::assertSame( '', $this->parsedown->text('[Relative Noprocess](../item2-3?id=unique&noprocess)') ); self::assertSame( '', $this->parsedown->text('[Relative Target](../item2-3?target=_blank)') ); self::assertSame( '', $this->parsedown->text('[Relative Rel](../item2-3?rel=nofollow)') ); self::assertSame( '', $this->parsedown->text('[Relative Mixed](../item2-3?foo=bar&baz=qux&rel=nofollow&class=button)') ); } public function testInvalidLinks(): void { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); self::assertSame( '', $this->parsedown->text('[Non Existent Page](no-page)') ); self::assertSame( '', $this->parsedown->text('[Existent File](existing-file.zip)') ); self::assertSame( '', $this->parsedown->text('[Non Existent File](missing-file.zip)') ); } public function testInvalidLinksSubDir(): void { $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Non Existent Page](no-page)') ); self::assertSame( '', $this->parsedown->text('[Existent File](existing-file.zip)') ); self::assertSame( '', $this->parsedown->text('[Non Existent File](missing-file.zip)') ); } public function testInvalidLinksSubDirAbsoluteUrl(): void { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); self::assertSame( '', $this->parsedown->text('[Non Existent Page](no-page)') ); self::assertSame( '', $this->parsedown->text('[Existent File](existing-file.zip)') ); self::assertSame( '', $this->parsedown->text('[Non Existent File](missing-file.zip)') ); } /** * @param $string * * @return mixed */ private function stripLeadingWhitespace($string) { return preg_replace('/^\s*(.*)/', '', $string); } }