Skip to content

Commit

Permalink
Pages & Linker
Browse files Browse the repository at this point in the history
  • Loading branch information
kapxapot committed Jun 27, 2020
1 parent b01865c commit b2fff80
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/Traits/NewsPageDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait NewsPageDescription

protected function makeNewsPageDescription(
NewsSourceInterface $news,
?string $limitVar = null
string $limitVar = null
) : string
{
return $this->makePageDescription($news->fullText(), $limitVar);
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Traits/PageDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait PageDescription
{
protected int $pageDescriptionLimit = 1000;

protected function makePageDescription(string $text, ?string $limitVar = null) : string
protected function makePageDescription(string $text, string $limitVar = null) : string
{
$limit = $limitVar
? $this->getSettings(
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Interfaces/LinkerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function rel(string $url = null) : string;

function getImageExtension(?string $type) : string;

function page(PageInterface $page) : string;
function page(PageInterface $page = null) : string;
function news(int $id = null) : string;
function tag(string $tag = null, string $tab = null) : string;

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Linker.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public function getImageExtension(?string $type) : string
return Image::getExtension($type) ?? 'jpg';
}

public function page(PageInterface $page) : string
public function page(PageInterface $page = null) : string
{
return $this->router->pathFor(
'main.page',
['slug' => $page->getSlug()]
['slug' => $page ? $page->getSlug() : null]
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Testing/Mocks/LinkerMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function getImageExtension(?string $type) : string
return Image::getExtension($type) ?? 'jpg';
}

public function page(PageInterface $page) : string
public function page(PageInterface $page = null) : string
{
return $this->abs('/') . $page->getSlug();
return $this->abs('/') . ($page ? $page->getSlug() : null);
}

public function news(int $id = null) : string
Expand Down
9 changes: 6 additions & 3 deletions tests/Parsing/CompositeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Plasticode\Parsing\Parsers\CompositeParser;
use Plasticode\Parsing\Parsers\DoubleBracketsParser;
use Plasticode\Parsing\ParsingContext;
use Plasticode\Testing\Dummies\PageDummy;
use Plasticode\Testing\Factories\LinkMapperSourceFactory;
use Plasticode\Testing\Mocks\LinkerMock;
use Plasticode\Tests\BaseRenderTestCase;
Expand All @@ -31,12 +32,14 @@ public function testRenderLinks() : void

$parsedContext = $parser->renderLinks($context);

$page = new PageDummy(['slug' => 'about-us']);

$this->assertEquals(
Text::fromLines(
[
'<a href="' . $linker->page() . 'about-us" class="entity-url">about us</a>',
'<a href="' . $linker->tag() . 'warcraft" class="entity-url">warcraft</a>',
'<a href="' . $linker->news() . '5" class="entity-url">Some great news!</a>',
'<a href="' . $linker->page($page) . '" class="entity-url">about us</a>',
'<a href="' . $linker->tag('warcraft') . '" class="entity-url">warcraft</a>',
'<a href="' . $linker->news(5) . '" class="entity-url">Some great news!</a>',
]
),
$parsedContext->text
Expand Down
9 changes: 6 additions & 3 deletions tests/Parsing/DoubleBracketsParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Plasticode\Parsing\Parsers\DoubleBracketsParser;
use Plasticode\Parsing\ParsingContext;
use Plasticode\Testing\Dummies\PageDummy;
use Plasticode\Testing\Factories\LinkMapperSourceFactory;
use Plasticode\Testing\Mocks\LinkerMock;
use Plasticode\Tests\BaseRenderTestCase;
Expand Down Expand Up @@ -124,12 +125,14 @@ public function testRenderLinks() : void

$parsedContext = $this->parser->renderLinks($context);

$page = new PageDummy(['slug' => 'about-us']);

$this->assertEquals(
Text::fromLines(
[
'<a href="' . $this->linker->page() . 'about-us" class="entity-url">about us</a>',
'<a href="' . $this->linker->tag() . 'warcraft" class="entity-url">warcraft</a>',
'<a href="' . $this->linker->news() . '5" class="entity-url">Some great news!</a>',
'<a href="' . $this->linker->page($page) . '" class="entity-url">about us</a>',
'<a href="' . $this->linker->tag('warcraft') . '" class="entity-url">warcraft</a>',
'<a href="' . $this->linker->news(5) . '" class="entity-url">Some great news!</a>',
]
),
$parsedContext->text
Expand Down
7 changes: 5 additions & 2 deletions tests/Parsing/LinkMappers/PageLinkMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Plasticode\Parsing\LinkMappers\PageLinkMapper;
use Plasticode\Parsing\LinkMappers\TagLinkMapper;
use Plasticode\Parsing\ParsingContext;
use Plasticode\Testing\Dummies\PageDummy;
use Plasticode\Testing\Factories\PageLinkMapperFactory;
use Plasticode\Testing\Mocks\LinkerMock;
use Plasticode\Tests\BaseRenderTestCase;
Expand Down Expand Up @@ -90,14 +91,16 @@ public function renderLinksProvider() : array
{
$linker = new LinkerMock();

$page = new PageDummy(['slug' => 'about-us']);

return [
[
'<a href="%page%/about-us" class="entity-url">about us</a>',
'<a href="' . $linker->page() . 'about-us" class="entity-url">about us</a>'
'<a href="' . $linker->page($page) . '" class="entity-url">about us</a>'
],
[
'<a href="%tag%/warcraft" class="entity-url">warcraft</a>',
'<a href="' . $linker->tag() . 'warcraft" class="entity-url">warcraft</a>'
'<a href="' . $linker->tag('warcraft') . '" class="entity-url">warcraft</a>'
]
];
}
Expand Down

0 comments on commit b2fff80

Please sign in to comment.