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 = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
];
$page = $this->pages->dispatch('/item2/item2-2');
$this->parsedown = new Parsedown($page, $defaults);
}
protected function _after()
{
$this->config->set('system.home.alias', $this->old_home);
}
public function testImages()
{
$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();
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testImagesSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testImagesAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testImagesSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testImagesAttributes()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testRootImages()
{
$this->uri->initializeWithURL('http://testing.dev/')->init();
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
];
$page = $this->pages->dispatch('/');
$this->parsedown = new Parsedown($page, $defaults);
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$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();
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testRootImagesSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('
',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertSame('
',
$this->parsedown->text(''));
}
public function testRootAbsoluteLinks()
{
$this->uri->initializeWithURL('http://testing.dev/')->init();
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
];
$page = $this->pages->dispatch('/');
$this->parsedown = new Parsedown($page, $defaults);
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](item1-3)'));
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../item2)'));
$this->assertSame('With Query
',
$this->parsedown->text('[With Query](?foo=bar)'));
$this->assertSame('With Param
',
$this->parsedown->text('[With Param](/foo:bar)'));
$this->assertSame('With Anchor
',
$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();
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../item2)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](item1-3)'));
$this->assertSame('With Query
',
$this->parsedown->text('[With Query](?foo=bar)'));
$this->assertSame('With Param
',
$this->parsedown->text('[With Param](/foo:bar)'));
$this->assertSame('With Anchor
',
$this->parsedown->text('[With Anchor](#foo)'));
}
public function testAnchorLinksLangRelativeUrls()
{
$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();
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
}
public function testAnchorLinksLangAbsoluteUrls()
{
$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();
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testExternalLinks()
{
$this->assertSame('cnn.com
',
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
$this->assertSame('google.com
',
$this->parsedown->text('[google.com](https://www.google.com)'));
$this->assertSame('complex url
',
$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()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('cnn.com
',
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
$this->assertSame('google.com
',
$this->parsedown->text('[google.com](https://www.google.com)'));
}
public function testExternalLinksSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('cnn.com
',
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
$this->assertSame('google.com
',
$this->parsedown->text('[google.com](https://www.google.com)'));
}
public function testAnchorLinksRelativeUrls()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
}
public function testAnchorLinksAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksWithPortAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev:8080/item2/item2-2')->init();
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksSubDirRelativeUrls()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testSlugRelativeLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('Up and Down with Anchor
',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testSlugRelativeLinksAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('Up and Down with Anchor
',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testSlugRelativeLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('Up and Down with Anchor
',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testSlugRelativeLinksSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('Up and Down with Anchor
',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testDirectoryRelativeLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)'));
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](../01.item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](01.item2-2-1)'));
$this->assertSame('Up and Down
',
$this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)'));
$this->assertSame('Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)'));
$this->assertSame('Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)'));
$this->assertSame('Up and Down with Anchor
',
$this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)'));
}
public function testAbsoluteLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Root
',
$this->parsedown->text('[Root](/)'));
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](/item2/item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](/item2)'));
$this->assertSame('With Query
',
$this->parsedown->text('[With Query](/item2?foo=bar)'));
$this->assertSame('With Param
',
$this->parsedown->text('[With Param](/item2/foo:bar)'));
$this->assertSame('With Anchor
',
$this->parsedown->text('[With Anchor](/item2#foo)'));
}
public function testDirectoryAbsoluteLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Root
',
$this->parsedown->text('[Root](/)'));
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](/item2/item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](/item2)'));
$this->assertSame('With Query
',
$this->parsedown->text('[With Query](/item2?foo=bar)'));
$this->assertSame('With Param
',
$this->parsedown->text('[With Param](/item2/foo:bar)'));
$this->assertSame('With Anchor
',
$this->parsedown->text('[With Anchor](/item2#foo)'));
}
public function testDirectoryAbsoluteLinksSubDirAbsoluteUrl()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Root
',
$this->parsedown->text('[Root](/)'));
$this->assertSame('Peer Page
',
$this->parsedown->text('[Peer Page](/item2/item2-1)'));
$this->assertSame('Down a Level
',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
$this->assertSame('Up a Level
',
$this->parsedown->text('[Up a Level](/item2)'));
$this->assertSame('With Query
',
$this->parsedown->text('[With Query](/item2?foo=bar)'));
$this->assertSame('With Param
',
$this->parsedown->text('[With Param](/item2/foo:bar)'));
$this->assertSame('With Anchor
',
$this->parsedown->text('[With Anchor](/item2#foo)'));
}
public function testSpecialProtocols()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('mailto
',
$this->parsedown->text('[mailto](mailto:user@domain.com)'));
$this->assertSame('xmpp
',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
$this->assertSame('tel
',
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('sms
',
$this->parsedown->text('[sms](sms:123-555-12345)'));
$this->assertSame('ts.example.com
',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
public function testSpecialProtocolsSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('mailto
',
$this->parsedown->text('[mailto](mailto:user@domain.com)'));
$this->assertSame('xmpp
',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
$this->assertSame('tel
',
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('sms
',
$this->parsedown->text('[sms](sms:123-555-12345)'));
$this->assertSame('ts.example.com
',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
public function testSpecialProtocolsSubDirAbsoluteUrl()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('mailto
',
$this->parsedown->text('[mailto](mailto:user@domain.com)'));
$this->assertSame('xmpp
',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
$this->assertSame('tel
',
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('sms
',
$this->parsedown->text('[sms](sms:123-555-12345)'));
$this->assertSame('ts.example.com
',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
public function testReferenceLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$sample = '[relative link][r_relative]
[r_relative]: ../item2-3#blah';
$this->assertSame('relative link
',
$this->parsedown->text($sample));
$sample = '[absolute link][r_absolute]
[r_absolute]: /item3#blah';
$this->assertSame('absolute link
',
$this->parsedown->text($sample));
$sample = '[external link][r_external]
[r_external]: http://www.cnn.com';
$this->assertSame('external link
',
$this->parsedown->text($sample));
}
public function testAttributeLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Anchor Class
',
$this->parsedown->text('[Anchor Class](?classes=button#something)'));
$this->assertSame('Relative Class
',
$this->parsedown->text('[Relative Class](../item2-3?classes=button)'));
$this->assertSame('Relative ID
',
$this->parsedown->text('[Relative ID](../item2-3?id=unique)'));
$this->assertSame('External
',
$this->parsedown->text('[External](https://github.com/getgrav/grav?classes=button,big)'));
$this->assertSame('Relative Noprocess
',
$this->parsedown->text('[Relative Noprocess](../item2-3?id=unique&noprocess)'));
$this->assertSame('Relative Target
',
$this->parsedown->text('[Relative Target](../item2-3?target=_blank)'));
$this->assertSame('Relative Rel
',
$this->parsedown->text('[Relative Rel](../item2-3?rel=nofollow)'));
$this->assertSame('Relative Mixed
',
$this->parsedown->text('[Relative Mixed](../item2-3?foo=bar&baz=qux&rel=nofollow&class=button)'));
}
public function testInvalidLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('Non Existent Page
',
$this->parsedown->text('[Non Existent Page](no-page)'));
$this->assertSame('Existent File
',
$this->parsedown->text('[Existent File](existing-file.zip)'));
$this->assertSame('Non Existent File
',
$this->parsedown->text('[Non Existent File](missing-file.zip)'));
}
public function testInvalidLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Non Existent Page
',
$this->parsedown->text('[Non Existent Page](no-page)'));
$this->assertSame('Existent File
',
$this->parsedown->text('[Existent File](existing-file.zip)'));
$this->assertSame('Non Existent File
',
$this->parsedown->text('[Non Existent File](missing-file.zip)'));
}
public function testInvalidLinksSubDirAbsoluteUrl()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('Non Existent Page
',
$this->parsedown->text('[Non Existent Page](no-page)'));
$this->assertSame('Existent File
',
$this->parsedown->text('[Existent File](existing-file.zip)'));
$this->assertSame('Non Existent File
',
$this->parsedown->text('[Non Existent File](missing-file.zip)'));
}
/**
* @param $string
*
* @return mixed
*/
private function stripLeadingWhitespace($string)
{
return preg_replace('/^\s*(.*)/', '', $string);
}
}