From b332e497abe0a592d1a2a4971bce444de4ffb762 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 1 Feb 2016 19:44:55 -0700 Subject: [PATCH] reordered --- tests/unit/Grav/Common/MarkdownLinksTest.php | 219 ++++++++++++++----- 1 file changed, 161 insertions(+), 58 deletions(-) diff --git a/tests/unit/Grav/Common/MarkdownLinksTest.php b/tests/unit/Grav/Common/MarkdownLinksTest.php index 1d90fb53f..c8cdfba19 100644 --- a/tests/unit/Grav/Common/MarkdownLinksTest.php +++ b/tests/unit/Grav/Common/MarkdownLinksTest.php @@ -61,68 +61,11 @@ class MarkdownTest extends \Codeception\TestCase\Test { } - public function testAnchorLinksNoPortAbsoluteUrls() - { - $this->config->set('system.absolute_urls', true); - $this->uri->initializeWithURL('http://testing.dev/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 testDirectoryRelativeLinks() - { - $this->config->set('system.absolute_urls', false); - $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 testSlugRelativeLinks() - { - $this->config->set('system.absolute_urls', false); - $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 testExternalLinks() { @@ -132,6 +75,28 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->parsedown->text('[google.com](https://www.google.com)')); } + public function testExternalLinksSubDir() + { + $this->config->set('system.absolute_urls', false); + $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 testAnchorLinksNoPortRelativeUrls() { $this->config->set('system.absolute_urls', false); @@ -147,6 +112,20 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)')); } + public function testAnchorLinksNoPortAbsoluteUrls() + { + $this->config->set('system.absolute_urls', true); + $this->uri->initializeWithURL('http://testing.dev/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 testAnchorLinksWithPortAbsoluteUrls() @@ -194,6 +173,32 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->parsedown->text('[Root Anchor](/#foo)')); } + public function testSlugRelativeLinks() + { + $this->config->set('system.absolute_urls', false); + $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() { @@ -277,7 +282,49 @@ class MarkdownTest extends \Codeception\TestCase\Test } - public function testDirectoryAbsoluteLinks() + public function testDirectoryRelativeLinks() + { + $this->config->set('system.absolute_urls', false); + $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 testAbsoluteRootLinks() + { + $this->config->set('system.absolute_urls', false); + $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 testAbsoluteLinks() { $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); @@ -355,6 +402,36 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->parsedown->text('[sms](sms:123-555-12345)')); } + public function testSpecialProtocolsSubDir() + { + $this->config->set('system.absolute_urls', false); + $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)')); + } + + 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)')); + } + public function testReferenceLinks() { $this->config->set('system.absolute_urls', false); @@ -410,6 +487,32 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->parsedown->text('[Non Existent File](missing-file.zip)')); } + public function testInvalidLinksSubDir() + { + $this->config->set('system.absolute_urls', false); + $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