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

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

',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
}
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('')
);
self::assertSame(
'

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

',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
}
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('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertSame(
'

',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
}
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('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertSame(
'

',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
}
public function testImagesAttributes(): void
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
}
public function testImagesDefaults(): void
{
/**
* Testing default 'loading'
*/
$this->setImagesDefaults(['loading' => 'auto']);
// loading should NOT be added to image by default
self::assertSame(
'
',
$this->parsedown->text('')
);
// loading="lazy" should be added when default is overridden by ?loading=lazy
self::assertSame(
'
',
$this->parsedown->text('')
);
$this->setImagesDefaults(['loading' => 'lazy']);
// loading="lazy" should be added by default
self::assertSame(
'
',
$this->parsedown->text('')
);
// loading should not be added when default is overridden by ?loading=auto
self::assertSame(
'
',
$this->parsedown->text('')
);
// loading="eager" should be added when default is overridden by ?loading=eager
self::assertSame(
'
',
$this->parsedown->text('')
);
}
public function testCLSAutoSizes(): void
{
$this->config->set('system.images.cls.auto_sizes', false);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
$this->config->set('system.images.cls.auto_sizes', true);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
self::assertRegExp(
'/width="400" height="200"/',
$this->parsedown->text('')
);
$this->config->set('system.images.cls.retina_scale', 2);
self::assertRegExp(
'/width="400" height="200"/',
$this->parsedown->text('')
);
$this->config->set('system.images.cls.retina_scale', 4);
self::assertRegExp(
'/width="200" height="100"/',
$this->parsedown->text('')
);
self::assertRegExp(
'/width="266" height="133"/',
$this->parsedown->text('')
);
$this->config->set('system.images.cls.aspect_ratio', true);
self::assertRegExp(
'/style="--aspect-ratio: 800\/400;"/',
$this->parsedown->text('')
);
$this->config->set('system.images.cls.aspect_ratio', false);
self::assertRegExp(
'/style="--aspect-ratio: 800\/400;"/',
$this->parsedown->text('')
);
}
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('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::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();
self::assertSame(
'
',
$this->parsedown->text('')
);
}
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('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertRegexp(
'|
<\/p>|',
$this->parsedown->text('')
);
self::assertSame(
'

',
$this->parsedown->text('')
);
self::assertSame(
'
',
$this->parsedown->text('')
);
}
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(
'Down a Level
',
$this->parsedown->text('[Down a Level](item1-3)')
);
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](../item2)')
);
self::assertSame(
'With Query
',
$this->parsedown->text('[With Query](?foo=bar)')
);
self::assertSame(
'With Param
',
$this->parsedown->text('[With Param](/foo:bar)')
);
self::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();
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](../item2)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](item1-3)')
);
self::assertSame(
'With Query
',
$this->parsedown->text('[With Query](?foo=bar)')
);
self::assertSame(
'With Param
',
$this->parsedown->text('[With Param](/foo:bar)')
);
self::assertSame(
'With Anchor
',
$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(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)')
);
self::assertSame(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$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(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)')
);
self::assertSame(
'Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)')
);
}
public function testExternalLinks(): void
{
self::assertSame(
'cnn.com
',
$this->parsedown->text('[cnn.com](http://www.cnn.com)')
);
self::assertSame(
'google.com
',
$this->parsedown->text('[google.com](https://www.google.com)')
);
self::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(): void
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
self::assertSame(
'cnn.com
',
$this->parsedown->text('[cnn.com](http://www.cnn.com)')
);
self::assertSame(
'google.com
',
$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(
'cnn.com
',
$this->parsedown->text('[cnn.com](http://www.cnn.com)')
);
self::assertSame(
'google.com
',
$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(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)')
);
self::assertSame(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$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(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)')
);
self::assertSame(
'Root Anchor
',
$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(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)')
);
self::assertSame(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)')
);
}
public function testAnchorLinksSubDirRelativeUrls(): void
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
self::assertSame(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)')
);
self::assertSame(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Root Anchor
',
$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(
'Peer Anchor
',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)')
);
self::assertSame(
'Peer Anchor 2
',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)')
);
self::assertSame(
'Current Anchor
',
$this->parsedown->text('[Current Anchor](#foo)')
);
self::assertSame(
'Root Anchor
',
$this->parsedown->text('[Root Anchor](/#foo)')
);
}
public function testSlugRelativeLinks(): void
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
self::assertSame(
'Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)')
);
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](..)')
);
self::assertSame(
'Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)')
);
self::assertSame(
'Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)')
);
self::assertSame(
'Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)')
);
self::assertSame(
'Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)')
);
self::assertSame(
'Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)')
);
self::assertSame(
'Up and Down with Anchor
',
$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(
'Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](..)')
);
self::assertSame(
'Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)')
);
self::assertSame(
'Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)')
);
self::assertSame(
'Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)')
);
self::assertSame(
'Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)')
);
self::assertSame(
'Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)')
);
self::assertSame(
'Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)')
);
self::assertSame(
'Up and Down with Anchor
',
$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(
'Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](..)')
);
self::assertSame(
'Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)')
);
self::assertSame(
'Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)')
);
self::assertSame(
'Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)')
);
self::assertSame(
'Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)')
);
self::assertSame(
'Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)')
);
self::assertSame(
'Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)')
);
self::assertSame(
'Up and Down with Anchor
',
$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(
'Peer Page
',
$this->parsedown->text('[Peer Page](../item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](..)')
);
self::assertSame(
'Up to Root Level
',
$this->parsedown->text('[Up to Root Level](../..)')
);
self::assertSame(
'Up and Down
',
$this->parsedown->text('[Up and Down](../../item3/item3-3)')
);
self::assertSame(
'Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)')
);
self::assertSame(
'Up a Level with Query
',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)')
);
self::assertSame(
'Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)')
);
self::assertSame(
'Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)')
);
self::assertSame(
'Up and Down with Anchor
',
$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(
'Up and Down with Param
',
$this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)')
);
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](../01.item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](01.item2-2-1)')
);
self::assertSame(
'Up and Down
',
$this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)')
);
self::assertSame(
'Down a Level with Query
',
$this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)')
);
self::assertSame(
'Up and Down with Query
',
$this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)')
);
self::assertSame(
'Up and Down with Anchor
',
$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(
'Root
',
$this->parsedown->text('[Root](/)')
);
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](/item2/item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](/item2)')
);
self::assertSame(
'With Query
',
$this->parsedown->text('[With Query](/item2?foo=bar)')
);
self::assertSame(
'With Param
',
$this->parsedown->text('[With Param](/item2/foo:bar)')
);
self::assertSame(
'With Anchor
',
$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(
'Root
',
$this->parsedown->text('[Root](/)')
);
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](/item2/item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](/item2)')
);
self::assertSame(
'With Query
',
$this->parsedown->text('[With Query](/item2?foo=bar)')
);
self::assertSame(
'With Param
',
$this->parsedown->text('[With Param](/item2/foo:bar)')
);
self::assertSame(
'With Anchor
',
$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(
'Root
',
$this->parsedown->text('[Root](/)')
);
self::assertSame(
'Peer Page
',
$this->parsedown->text('[Peer Page](/item2/item2-1)')
);
self::assertSame(
'Down a Level
',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)')
);
self::assertSame(
'Up a Level
',
$this->parsedown->text('[Up a Level](/item2)')
);
self::assertSame(
'With Query
',
$this->parsedown->text('[With Query](/item2?foo=bar)')
);
self::assertSame(
'With Param
',
$this->parsedown->text('[With Param](/item2/foo:bar)')
);
self::assertSame(
'With Anchor
',
$this->parsedown->text('[With Anchor](/item2#foo)')
);
}
public function testSpecialProtocols(): void
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
self::assertSame(
'mailto
',
$this->parsedown->text('[mailto](mailto:user@domain.com)')
);
self::assertSame(
'xmpp
',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)')
);
self::assertSame(
'tel
',
$this->parsedown->text('[tel](tel:123-555-12345)')
);
self::assertSame(
'sms
',
$this->parsedown->text('[sms](sms:123-555-12345)')
);
self::assertSame(
'ts.example.com
',
$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(
'mailto
',
$this->parsedown->text('[mailto](mailto:user@domain.com)')
);
self::assertSame(
'xmpp
',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)')
);
self::assertSame(
'tel
',
$this->parsedown->text('[tel](tel:123-555-12345)')
);
self::assertSame(
'sms
',
$this->parsedown->text('[sms](sms:123-555-12345)')
);
self::assertSame(
'ts.example.com
',
$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(
'mailto
',
$this->parsedown->text('[mailto](mailto:user@domain.com)')
);
self::assertSame(
'xmpp
',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)')
);
self::assertSame(
'tel
',
$this->parsedown->text('[tel](tel:123-555-12345)')
);
self::assertSame(
'sms
',
$this->parsedown->text('[sms](sms:123-555-12345)')
);
self::assertSame(
'ts.example.com
',
$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(
'relative link
',
$this->parsedown->text($sample)
);
$sample = '[absolute link][r_absolute]
[r_absolute]: /item3#blah';
self::assertSame(
'absolute link
',
$this->parsedown->text($sample)
);
$sample = '[external link][r_external]
[r_external]: http://www.cnn.com';
self::assertSame(
'external link
',
$this->parsedown->text($sample)
);
}
public function testAttributeLinks(): void
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
self::assertSame(
'Anchor Class
',
$this->parsedown->text('[Anchor Class](?classes=button#something)')
);
self::assertSame(
'Relative Class
',
$this->parsedown->text('[Relative Class](../item2-3?classes=button)')
);
self::assertSame(
'Relative ID
',
$this->parsedown->text('[Relative ID](../item2-3?id=unique)')
);
self::assertSame(
'External
',
$this->parsedown->text('[External](https://github.com/getgrav/grav?classes=button,big)')
);
self::assertSame(
'Relative Noprocess
',
$this->parsedown->text('[Relative Noprocess](../item2-3?id=unique&noprocess)')
);
self::assertSame(
'Relative Target
',
$this->parsedown->text('[Relative Target](../item2-3?target=_blank)')
);
self::assertSame(
'Relative Rel
',
$this->parsedown->text('[Relative Rel](../item2-3?rel=nofollow)')
);
self::assertSame(
'Relative Mixed
',
$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(
'Non Existent Page
',
$this->parsedown->text('[Non Existent Page](no-page)')
);
self::assertSame(
'Existent File
',
$this->parsedown->text('[Existent File](existing-file.zip)')
);
self::assertSame(
'Non Existent File
',
$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(
'Non Existent Page
',
$this->parsedown->text('[Non Existent Page](no-page)')
);
self::assertSame(
'Existent File
',
$this->parsedown->text('[Existent File](existing-file.zip)')
);
self::assertSame(
'Non Existent File
',
$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(
'Non Existent Page
',
$this->parsedown->text('[Non Existent Page](no-page)')
);
self::assertSame(
'Existent File
',
$this->parsedown->text('[Existent File](existing-file.zip)')
);
self::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);
}
private function setImagesDefaults($defaults) {
$defaults = [
'images' => [
'defaults' => $defaults
],
];
$page = $this->pages->find('/item2/item2-2');
$excerpts = new Excerpts($page, $defaults);
$this->parsedown = new Parsedown($excerpts);
}
}