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": { 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..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; } @@ -304,6 +303,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']; } /** diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 836de7ea2..dd85c2c47 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -40,8 +40,11 @@ $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'; 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 @@ grav = Fixtures::get('grav'); $this->pages = $this->grav['pages']; - /** @var UniformResourceLocator $locator */ - $locator = $this->grav['locator']; - $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false); - $this->pages->init(); + $this->config = $this->grav['config']; + + $this->uri = $this->grav['uri']; + + 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, @@ -42,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() @@ -58,108 +80,192 @@ class MarkdownTest extends \Codeception\TestCase\Test return preg_replace('/^\s*(.*)/', '', $string); } - public function testAnchorLinks() + public function testAnchorLinksNoPortRelativeUrls() { - $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->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-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 testAnchorLinksNoPortAbsoluteUrls() + { + $this->config->set('system.absolute_urls', true); + $this->uri->initializeWithURL('http://localhost/item2/item-2-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() + { + $this->config->set('system.absolute_urls', true); + $this->uri->initializeWithURL('http://localhost:8080/item2/item-2-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->config->set('system.absolute_urls', false); + $this->uri->initializeWithUrlAndRootPath('http://localhost/subdir/item2/item-2-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://localhost/subdir/item2/item-2-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->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->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-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 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->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->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $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() { - $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->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-2')->init(); + + $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->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->config->set('system.absolute_urls', false); + $this->uri->initializeWithURL('http://localhost/item2/item-2-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)')); } 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

'); + $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() { - $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)')); } + } diff --git a/tests/unit/Grav/Common/Page/PagesTest.php b/tests/unit/Grav/Common/Page/PagesTest.php index aed050ee7..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() @@ -43,7 +49,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'); } }