From 5abb4060f39cd0b221a5cf86873f9d8b8cc7d570 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 19:04:58 -0700 Subject: [PATCH 01/12] moved grav-based base_uri values into Uri->init() --- system/src/Grav/Common/Grav.php | 15 --------------- system/src/Grav/Common/Uri.php | 5 +++++ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 05cc8944e..669d91cee 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -190,21 +190,6 @@ class Grav extends Container return new Browser(); }; - $container['base_url_absolute'] = function ($c) { - /** @var Grav $c */ - return $c['config']->get('system.base_url_absolute') ?: $c['uri']->rootUrl(true); - }; - - $container['base_url_relative'] = function ($c) { - /** @var Grav $c */ - return $c['config']->get('system.base_url_relative') ?: $c['uri']->rootUrl(false); - }; - - $container['base_url'] = function ($c) { - /** @var Grav $c */ - return $c['config']->get('system.absolute_urls') ? $c['base_url_absolute'] : $c['base_url_relative']; - }; - $container->register(new StreamsServiceProvider); $container->register(new ConfigServiceProvider); diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 0857238cb..0d30d3b07 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -304,6 +304,11 @@ class Uri if ($this->content_path != '') { $this->paths = explode('/', $this->content_path); } + + // Set some Grav stuff + $grav['base_url_absolute'] = $this->rootUrl(true); + $grav['base_url_relative'] = $this->rootUrl(false); + $grav['base_url'] = $grav['config']->get('system.absolute_urls') ? $grav['base_url_absolute'] : $grav['base_url_relative']; } /** From 0ddfd4c5461487cbfebc03faeb87c8fb056af78d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 19:05:15 -0700 Subject: [PATCH 02/12] value is getting overridden so not needed here --- system/src/Grav/Common/Uri.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 0d30d3b07..874902003 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -221,7 +221,6 @@ class Uri { $this->initializeWithUrl($url); $this->root_path = $root_path; - $this->root = $this->base . $this->root_path; return $this; } From 62dbf9b02b47b8551eaee42034d92c9d01d080ee Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 19:05:37 -0700 Subject: [PATCH 03/12] Initiate the Uri->init() in bootstrap stage --- tests/_bootstrap.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 836de7ea2..f2ceea5e3 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -40,9 +40,12 @@ $grav = Grav::instance( ) ); + +$grav['uri']->init(); $grav['debugger']->init(); $grav['assets']->init(); + // Set default $_SERVER value used for nonces empty( $_SERVER['HTTP_CLIENT_IP'] ) && $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1'; From 9c0deea6c846060691ee0106568611e91bd6503c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 19:06:00 -0700 Subject: [PATCH 04/12] added some tests that test various URL and subduer scenarios --- tests/unit/Grav/Common/MarkdownTest.php | 107 +++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/tests/unit/Grav/Common/MarkdownTest.php b/tests/unit/Grav/Common/MarkdownTest.php index 1e1760910..fa8ccc2ca 100644 --- a/tests/unit/Grav/Common/MarkdownTest.php +++ b/tests/unit/Grav/Common/MarkdownTest.php @@ -2,6 +2,8 @@ use Codeception\Util\Fixtures; use Grav\Common\Grav; +use Grav\Common\Uri; +use Grav\Common\Config\Config; use Grav\Common\Page\Pages; use Grav\Common\Page\Page; use Grav\Common\Markdown\Parsedown; @@ -21,12 +23,22 @@ class MarkdownTest extends \Codeception\TestCase\Test /** @var Pages $pages */ protected $pages; + /** @var Config $config */ + protected $config; + + /** @var Uri $uri */ + protected $uri; + protected function _before() { $this->grav = Fixtures::get('grav'); $this->pages = $this->grav['pages']; + $this->config = $this->grav['config']; + + $this->uri = $this->grav['uri']; + /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false); @@ -58,8 +70,12 @@ class MarkdownTest extends \Codeception\TestCase\Test return preg_replace('/^\s*(.*)/', '', $string); } - public function testAnchorLinks() + public function testAnchorLinksNoPortRelativeUrls() { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), '

Peer Anchor

'); $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), @@ -71,8 +87,80 @@ class MarkdownTest extends \Codeception\TestCase\Test } + public function testAnchorLinksNoPortAbsoluteUrls() + { + $this->config->set('system.absolute_urls', true); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + + $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), + '

Peer Anchor

'); + $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), + '

Peer Anchor 2

'); +// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), +// '

Current Anchor

'); + $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), + '

Root Anchor

'); + + } + + public function testAnchorLinksWithPortAbsoluteUrls() + { + $this->config->set('system.absolute_urls', true); + $this->uri->initializeWithURL('http://localhost:8080/item2/item-2-2')->init(); + + + $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), + '

Peer Anchor

'); + $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), + '

Peer Anchor 2

'); +// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), +// '

Current Anchor

'); + $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), + '

Root Anchor

'); + + } + + public function testAnchorLinksSubDirRelativeUrls() + { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithUrlAndRootPath('http://localhost/subdir/item2/item-2-2', '/subdir')->init(); + + + $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), + '

Peer Anchor

'); + $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), + '

Peer Anchor 2

'); +// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), +// '

Current Anchor

'); + $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), + '

Root Anchor

'); + + } + + public function testAnchorLinksSubDirAbsoluteUrls() + { + $this->config->set('system.absolute_urls', true); + $this->uri->initializeWithUrlAndRootPath('http://localhost/subdir/item2/item-2-2', '/subdir')->init(); + + + $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), + '

Peer Anchor

'); + $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), + '

Peer Anchor 2

'); +// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), +// '

Current Anchor

'); + $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), + '

Root Anchor

'); + + } + public function testSlugRelativeLinks() { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $this->assertSame($this->parsedown->text('[Peer Page](../item2-1)'), '

Peer Page

'); $this->assertSame($this->parsedown->text('[Down a Level](item2-2-1)'), @@ -95,6 +183,10 @@ class MarkdownTest extends \Codeception\TestCase\Test public function testDirectoryRelativeLinks() { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $this->assertSame($this->parsedown->text('[Peer Page](../01.item2-1)'), '

Peer Page

'); $this->assertSame($this->parsedown->text('[Down a Level](01.item2-2-1)'), @@ -113,6 +205,10 @@ class MarkdownTest extends \Codeception\TestCase\Test public function testDirectoryAbsoluteLinks() { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $this->assertSame($this->parsedown->text('[Peer Page](/item2/item2-1)'), '

Peer Page

'); $this->assertSame($this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'), @@ -129,6 +225,10 @@ class MarkdownTest extends \Codeception\TestCase\Test public function testSpecialProtocols() { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $this->assertSame($this->parsedown->text('[mailto](mailto:user@domain.com)'), '

mailto

'); $this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'), @@ -141,6 +241,10 @@ class MarkdownTest extends \Codeception\TestCase\Test public function testReferenceLinks() { + $this->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $sample = '[relative link][r_relative] [r_relative]: ../item2-3#blah'; $this->assertSame($this->parsedown->text($sample), '

relative link

'); @@ -162,4 +266,5 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'), '

google.com

'); } + } From 7de21b1f52074012023eccf223402a28df7d6e17 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 21:54:08 -0700 Subject: [PATCH 05/12] went back to dev-master of Parsedown until release --- composer.json | 7 +------ composer.lock | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 2bc153a40..2cc831fef 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "require": { "php": ">=5.5.9", "twig/twig": "~1.24", + "erusev/parsedown": "dev-master as 1.6.0", "erusev/parsedown-extra": "~0.7", "symfony/yaml": "~2.8", "symfony/console": "~2.8", @@ -31,12 +32,6 @@ "codeception/codeception": "^2.1", "fzaninotto/faker": "^1.5" }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/getgrav/parsedown" - } - ], "autoload": { "psr-4": { "Grav\\": "system/src/Grav" diff --git a/composer.lock b/composer.lock index 584fd0675..92d015aa2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a779e113a6d1bc09fff7a0a27ec8251e", - "content-hash": "335b1c5c62ea10a4df7d085816a50f91", + "hash": "a641806eb4174e72533c76a56d4fac5e", + "content-hash": "812ba1911705385948bc6b15c197f9b4", "packages": [ { "name": "doctrine/cache", @@ -130,24 +130,28 @@ }, { "name": "erusev/parsedown", - "version": "1.6.0", + "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/getgrav/parsedown.git", - "reference": "3ebbd730b5c2cf5ce78bc1bf64071407fc6674b7" + "url": "https://github.com/erusev/parsedown.git", + "reference": "94688f21cc5d8bc85f1783b4c8b98b3288d712cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getgrav/parsedown/zipball/3ebbd730b5c2cf5ce78bc1bf64071407fc6674b7", - "reference": "3ebbd730b5c2cf5ce78bc1bf64071407fc6674b7", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/94688f21cc5d8bc85f1783b4c8b98b3288d712cb", + "reference": "94688f21cc5d8bc85f1783b4c8b98b3288d712cb", "shasum": "" }, + "require": { + "php": ">=5.3.0" + }, "type": "library", "autoload": { "psr-0": { "Parsedown": "" } }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -164,10 +168,7 @@ "markdown", "parser" ], - "support": { - "source": "https://github.com/getgrav/parsedown/tree/1.6.0" - }, - "time": "2015-10-04 16:44:32" + "time": "2016-01-07 17:36:51" }, { "name": "erusev/parsedown-extra", @@ -2647,9 +2648,18 @@ "time": "2015-12-05 11:13:14" } ], - "aliases": [], + "aliases": [ + { + "alias": "1.6.0", + "alias_normalized": "1.6.0.0", + "version": "9999999-dev", + "package": "erusev/parsedown" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "erusev/parsedown": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From 5f6b09b0325e0cd7ac5c1ae20277bab03fbea4d5 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 21:54:57 -0700 Subject: [PATCH 06/12] fixed a markdown test --- tests/unit/Grav/Common/MarkdownTest.php | 43 ++++++++++++------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/tests/unit/Grav/Common/MarkdownTest.php b/tests/unit/Grav/Common/MarkdownTest.php index fa8ccc2ca..1a2b905ad 100644 --- a/tests/unit/Grav/Common/MarkdownTest.php +++ b/tests/unit/Grav/Common/MarkdownTest.php @@ -75,15 +75,14 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), - '

Peer Anchor

'); - $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), - '

Peer Anchor 2

'); -// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), -// '

Current Anchor

'); - $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), - '

Root Anchor

'); + $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)')); } @@ -92,16 +91,14 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', true); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), - '

Peer Anchor

'); - $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), - '

Peer Anchor 2

'); -// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), -// '

Current Anchor

'); - $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), - '

Root Anchor

'); - + $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() @@ -261,10 +258,10 @@ class MarkdownTest extends \Codeception\TestCase\Test public function testExternalLinks() { - $this->assertSame($this->parsedown->text('[cnn.com](http://www.cnn.com)'), - '

cnn.com

'); - $this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'), - '

google.com

'); + $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)')); } } From 56f267ec79e6d2ef31cf07fa4f564ddc3bb57c00 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2016 22:09:27 -0700 Subject: [PATCH 07/12] reordered tests --- tests/unit/Grav/Common/MarkdownTest.php | 178 ++++++++++++------------ 1 file changed, 86 insertions(+), 92 deletions(-) diff --git a/tests/unit/Grav/Common/MarkdownTest.php b/tests/unit/Grav/Common/MarkdownTest.php index 1a2b905ad..24eed1424 100644 --- a/tests/unit/Grav/Common/MarkdownTest.php +++ b/tests/unit/Grav/Common/MarkdownTest.php @@ -79,8 +79,8 @@ class MarkdownTest extends \Codeception\TestCase\Test $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('

Current Anchor

', +// $this->parsedown->text('[Current Anchor](#foo)')); $this->assertSame('

Root Anchor

', $this->parsedown->text('[Root Anchor](/#foo)')); @@ -95,8 +95,8 @@ class MarkdownTest extends \Codeception\TestCase\Test $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('

Current Anchor

', +// $this->parsedown->text('[Current Anchor](#foo)')); $this->assertSame('

Root Anchor

', $this->parsedown->text('[Root Anchor](/#foo)')); } @@ -106,15 +106,14 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', true); $this->uri->initializeWithURL('http://localhost:8080/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), - '

Peer Anchor

'); - $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), - '

Peer Anchor 2

'); -// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), -// '

Current Anchor

'); - $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), - '

Root Anchor

'); + $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)')); } @@ -123,15 +122,14 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithUrlAndRootPath('http://localhost/subdir/item2/item-2-2', '/subdir')->init(); - - $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), - '

Peer Anchor

'); - $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), - '

Peer Anchor 2

'); -// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), -// '

Current Anchor

'); - $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), - '

Root Anchor

'); + $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)')); } @@ -140,15 +138,14 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://localhost/subdir/item2/item-2-2', '/subdir')->init(); - - $this->assertSame($this->parsedown->text('[Peer Anchor](../item2-1#foo)'), - '

Peer Anchor

'); - $this->assertSame($this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'), - '

Peer Anchor 2

'); -// $this->assertSame($this->parsedown->text('[Current Anchor](#foo)'), -// '

Current Anchor

'); - $this->assertSame($this->parsedown->text('[Root Anchor](/#foo)'), - '

Root Anchor

'); + $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)')); } @@ -157,25 +154,24 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[Peer Page](../item2-1)'), - '

Peer Page

'); - $this->assertSame($this->parsedown->text('[Down a Level](item2-2-1)'), - '

Down a Level

'); - $this->assertSame($this->parsedown->text('[Up a Level](..)'), - '

Up a Level

'); - $this->assertSame($this->parsedown->text('[Up and Down](../../item3/item3-3)'), - '

Up and Down

'); - $this->assertSame($this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'), - '

Down a Level with Query

'); -// $this->assertSame($this->parsedown->text('[Up a Level with Query](../?foo=bar)'), -// '

Up a Level with Query

'); - $this->assertSame($this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'), - '

Up and Down with Query

'); - $this->assertSame($this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'), - '

Up and Down with Param

'); - $this->assertSame($this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'), - '

Up and Down with Anchor

'); + $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 testDirectoryRelativeLinks() @@ -183,21 +179,20 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[Peer Page](../01.item2-1)'), - '

Peer Page

'); - $this->assertSame($this->parsedown->text('[Down a Level](01.item2-2-1)'), - '

Down a Level

'); - $this->assertSame($this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)'), - '

Up and Down

'); - $this->assertSame($this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)'), - '

Down a Level with Query

'); - $this->assertSame($this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)'), - '

Up and Down with Query

'); -// $this->assertSame($this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)'), -// '

Up and Down with Param

'); - $this->assertSame($this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)'), - '

Up and Down with Anchor

'); + $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 Param

', +// $this->parsedown->text('[Up and Down with Param](../../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 testDirectoryAbsoluteLinks() @@ -205,19 +200,18 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[Peer Page](/item2/item2-1)'), - '

Peer Page

'); - $this->assertSame($this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'), - '

Down a Level

'); - $this->assertSame($this->parsedown->text('[Up a Level](/item2)'), - '

Up a Level

'); - $this->assertSame($this->parsedown->text('[With Query](/item2?foo=bar)'), - '

With Query

'); - $this->assertSame($this->parsedown->text('[With Param](/item2/foo:bar)'), - '

With Param

'); - $this->assertSame($this->parsedown->text('[With Anchor](/item2#foo)'), - '

With Anchor

'); + $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() @@ -225,15 +219,14 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - - $this->assertSame($this->parsedown->text('[mailto](mailto:user@domain.com)'), - '

mailto

'); - $this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'), - '

xmpp

'); - $this->assertSame($this->parsedown->text('[tel](tel:123-555-12345)'), - '

tel

'); - $this->assertSame($this->parsedown->text('[sms](sms:123-555-12345)'), - '

sms

'); + $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() @@ -241,19 +234,20 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->config->set('system.absolute_urls', false); $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); - $sample = '[relative link][r_relative] [r_relative]: ../item2-3#blah'; - $this->assertSame($this->parsedown->text($sample), '

relative link

'); + $this->assertSame('

relative link

', + $this->parsedown->text($sample)); $sample = '[absolute link][r_absolute] [r_absolute]: /item3#blah'; - $this->assertSame($this->parsedown->text($sample), - '

absolute link

'); + $this->assertSame('

absolute link

', + $this->parsedown->text($sample)); $sample = '[external link][r_external] [r_external]: http://www.cnn.com'; - $this->assertSame($this->parsedown->text($sample), '

external link

'); + $this->assertSame('

external link

', + $this->parsedown->text($sample)); } public function testExternalLinks() From 31940c03b141407b7d625c341c62bb3340c71802 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 1 Feb 2016 14:33:31 +0100 Subject: [PATCH 08/12] Disable system cache --- tests/_bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index f2ceea5e3..dd85c2c47 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -44,7 +44,7 @@ $grav = Grav::instance( $grav['uri']->init(); $grav['debugger']->init(); $grav['assets']->init(); - +$grav['config']->set('system.cache.enabled', false); // Set default $_SERVER value used for nonces empty( $_SERVER['HTTP_CLIENT_IP'] ) && $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1'; From 57cd5c9e6fb74e3c6804f97b00dcf3a46fe2e3bc Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 1 Feb 2016 14:37:19 +0100 Subject: [PATCH 09/12] Add second set of pages to test --- tests/unit/Grav/Common/Page/PagesTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/Grav/Common/Page/PagesTest.php b/tests/unit/Grav/Common/Page/PagesTest.php index aed050ee7..5225f35b7 100644 --- a/tests/unit/Grav/Common/Page/PagesTest.php +++ b/tests/unit/Grav/Common/Page/PagesTest.php @@ -27,9 +27,9 @@ class PagesTest extends \Codeception\TestCase\Test $this->pages = $this->grav['pages']; /** @var UniformResourceLocator $locator */ -// $locator = $this->grav['locator']; -// $locator->addPath('page', '', 'tests/fake/simple-site/user/pages', false); -// $this->pages->init(); + $locator = $this->grav['locator']; + $locator->addPath('page', '', 'tests/fake/simple-site/user/pages', false); + $this->pages->init(); } public function testAll() @@ -43,7 +43,7 @@ class PagesTest extends \Codeception\TestCase\Test { $list = $this->pages->getList(); $this->assertTrue(is_array($list)); -// $this->assertSame($list['/home'], 'Home'); -// $this->assertSame($list['/blog'], 'Blog'); + $this->assertSame($list['/'], 'Home'); + $this->assertSame($list['/blog'], 'Blog'); } } From 2934157fb49a80174bd271e206e6ae9a62c0b6f2 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 1 Feb 2016 15:18:33 +0100 Subject: [PATCH 10/12] :white_check_mark: Add pages content --- tests/fake/simple-site/user/pages/01.home/default.md | 11 ++++++++++- tests/fake/simple-site/user/pages/02.blog/blog.md | 10 ++++++++++ .../simple-site/user/pages/02.blog/post-one/item.md | 11 ++++++++++- .../simple-site/user/pages/02.blog/post-two/item.md | 11 ++++++++++- tests/fake/simple-site/user/pages/03.about/default.md | 9 +++++++-- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tests/fake/simple-site/user/pages/02.blog/blog.md diff --git a/tests/fake/simple-site/user/pages/01.home/default.md b/tests/fake/simple-site/user/pages/01.home/default.md index 8318c86b3..93d474701 100644 --- a/tests/fake/simple-site/user/pages/01.home/default.md +++ b/tests/fake/simple-site/user/pages/01.home/default.md @@ -1 +1,10 @@ -Test \ No newline at end of file +--- +title: Home +--- + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file diff --git a/tests/fake/simple-site/user/pages/02.blog/blog.md b/tests/fake/simple-site/user/pages/02.blog/blog.md new file mode 100644 index 000000000..1675616ad --- /dev/null +++ b/tests/fake/simple-site/user/pages/02.blog/blog.md @@ -0,0 +1,10 @@ +--- +title: Blog +--- + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file diff --git a/tests/fake/simple-site/user/pages/02.blog/post-one/item.md b/tests/fake/simple-site/user/pages/02.blog/post-one/item.md index 8318c86b3..26bef8963 100644 --- a/tests/fake/simple-site/user/pages/02.blog/post-one/item.md +++ b/tests/fake/simple-site/user/pages/02.blog/post-one/item.md @@ -1 +1,10 @@ -Test \ No newline at end of file +--- +title: Post 1 +--- + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file diff --git a/tests/fake/simple-site/user/pages/02.blog/post-two/item.md b/tests/fake/simple-site/user/pages/02.blog/post-two/item.md index 8318c86b3..5aebce815 100644 --- a/tests/fake/simple-site/user/pages/02.blog/post-two/item.md +++ b/tests/fake/simple-site/user/pages/02.blog/post-two/item.md @@ -1 +1,10 @@ -Test \ No newline at end of file +--- +title: Post 2 +--- + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file diff --git a/tests/fake/simple-site/user/pages/03.about/default.md b/tests/fake/simple-site/user/pages/03.about/default.md index 43bfdf031..0e280c07f 100644 --- a/tests/fake/simple-site/user/pages/03.about/default.md +++ b/tests/fake/simple-site/user/pages/03.about/default.md @@ -1,5 +1,10 @@ --- -title: test +title: About --- -# Test \ No newline at end of file +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file From 1279cb4ef3bd8d7569623054ff54088cf9bcd2e2 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 1 Feb 2016 17:19:34 +0100 Subject: [PATCH 11/12] Add Unit module available methods for future usage --- tests/_support/Helper/Unit.php | 75 ++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/tests/_support/Helper/Unit.php b/tests/_support/Helper/Unit.php index 41fc4d1c5..199872966 100644 --- a/tests/_support/Helper/Unit.php +++ b/tests/_support/Helper/Unit.php @@ -1,13 +1,80 @@ Date: Mon, 1 Feb 2016 17:19:52 +0100 Subject: [PATCH 12/12] Only initialize new pages location once in tests --- tests/unit/Grav/Common/MarkdownTest.php | 18 ++++++++++++++---- tests/unit/Grav/Common/Page/PagesTest.php | 14 ++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/unit/Grav/Common/MarkdownTest.php b/tests/unit/Grav/Common/MarkdownTest.php index 24eed1424..3c5e7c664 100644 --- a/tests/unit/Grav/Common/MarkdownTest.php +++ b/tests/unit/Grav/Common/MarkdownTest.php @@ -29,6 +29,8 @@ class MarkdownTest extends \Codeception\TestCase\Test /** @var Uri $uri */ protected $uri; + static $run = false; + protected function _before() { $this->grav = Fixtures::get('grav'); @@ -39,10 +41,15 @@ class MarkdownTest extends \Codeception\TestCase\Test $this->uri = $this->grav['uri']; - /** @var UniformResourceLocator $locator */ - $locator = $this->grav['locator']; - $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false); - $this->pages->init(); + if (!self::$run) { + + /** @var UniformResourceLocator $locator */ + $locator = $this->grav['locator']; + $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false); + $this->pages->init(); + + self::$run = true; + } $defaults = [ 'extra' => false, @@ -54,6 +61,9 @@ class MarkdownTest extends \Codeception\TestCase\Test $page = $this->pages->dispatch('/item2/item2-2'); $this->parsedown = new Parsedown($page, $defaults); + + + } protected function _after() diff --git a/tests/unit/Grav/Common/Page/PagesTest.php b/tests/unit/Grav/Common/Page/PagesTest.php index 5225f35b7..98e2bcc03 100644 --- a/tests/unit/Grav/Common/Page/PagesTest.php +++ b/tests/unit/Grav/Common/Page/PagesTest.php @@ -21,15 +21,21 @@ class PagesTest extends \Codeception\TestCase\Test /** @var Page $root_page */ protected $root_page; + static $run = false; + protected function _before() { $this->grav = Fixtures::get('grav'); $this->pages = $this->grav['pages']; - /** @var UniformResourceLocator $locator */ - $locator = $this->grav['locator']; - $locator->addPath('page', '', 'tests/fake/simple-site/user/pages', false); - $this->pages->init(); + if (!self::$run) { + /** @var UniformResourceLocator $locator */ + $locator = $this->grav['locator']; + $locator->addPath('page', '', 'tests/fake/simple-site/user/pages', false); + $this->pages->init(); + self::$run = true; + } + } public function testAll()