Skip to content

Commit

Permalink
add PermaLink view helper for tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mamuz committed Aug 30, 2014
1 parent 6a9fe3e commit 9e7e4e6
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 20 deletions.
5 changes: 3 additions & 2 deletions config/module.config.php
Expand Up @@ -23,7 +23,7 @@
'options' => array(
'route' => '/blog/post[/:id][/:title]',
'constraints' => array(
'id' => '[a-zA-Z0-9]+',
'id' => '[a-zA-Z0-9]+',
'title' => '[a-zA-Z0-9_+%-]+',
),
'defaults' => array(
Expand Down Expand Up @@ -77,7 +77,8 @@
'panel' => 'MamuzBlog\View\Helper\Panel',
'tag' => 'MamuzBlog\View\Helper\Tag',
'tagAnchor' => 'MamuzBlog\View\Helper\TagAnchor',
'permaLink' => 'MamuzBlog\View\Helper\PermaLink',
'permaLinkPost' => 'MamuzBlog\View\Helper\PermaLinkPost',
'permaLinkTag' => 'MamuzBlog\View\Helper\PermaLinkTag',
'postMeta' => 'MamuzBlog\View\Helper\PostMeta',
'postPanel' => 'MamuzBlog\View\Helper\PostPanel',
'postPanelShort' => 'MamuzBlog\View\Helper\PostPanelShort',
Expand Down
Expand Up @@ -4,7 +4,7 @@

use MamuzBlog\Entity\Post as PostEntity;

class PermaLink extends AbstractHelper
class PermaLinkPost extends AbstractHelper
{
/**
* {@link render()}
Expand Down
30 changes: 30 additions & 0 deletions src/MamuzBlog/View/Helper/PermaLinkTag.php
@@ -0,0 +1,30 @@
<?php

namespace MamuzBlog\View\Helper;

class PermaLinkTag extends AbstractHelper
{
/**
* {@link render()}
*/
public function __invoke($tagName)
{
return $this->render($tagName);
}

/**
* @param string $tagName
* @return string
*/
public function render($tagName)
{
$serverUrl = $this->getRenderer()->serverUrl();

$url = $this->getRenderer()->url(
'blogPublishedPosts',
array('tag' => $tagName)
);

return $serverUrl . $url;
}
}
2 changes: 1 addition & 1 deletion src/MamuzBlog/View/Helper/PostPanelShort.php
Expand Up @@ -17,7 +17,7 @@ private function getUrl()

private function createUrl()
{
$this->url = $this->getRenderer()->permaLink($this->entity);
$this->url = $this->getRenderer()->permaLinkPost($this->entity);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/MamuzBlog/View/Helper/TagAnchor.php
Expand Up @@ -19,13 +19,8 @@ public function __invoke($tagName, $content)
*/
public function render($tagName, $content)
{
$serverUrl = $this->getRenderer()->serverUrl();
$url = $this->getRenderer()->permaLinkTag($tagName);

$url = $this->getRenderer()->url(
'blogPublishedPosts',
array('tag' => $tagName)
);

return $this->getRenderer()->anchorBookmark($serverUrl . $url, 'Go to specific list', $content);
return $this->getRenderer()->anchorBookmark($url, 'Go to specific list', $content);
}
}
3 changes: 2 additions & 1 deletion src/MamuzBlog/View/Renderer/PhpRenderer.php
Expand Up @@ -12,7 +12,8 @@
* @method string slugify($value)
* @method string panel($header, $content, $footer)
* @method string postMeta(\MamuzBlog\Entity\Post $entity)
* @method string permaLink(\MamuzBlog\Entity\Post $entity)
* @method string permaLinkPost(\MamuzBlog\Entity\Post $entity)
* @method string permaLinkTag($tagName)
* @method string tag(\MamuzBlog\Entity\Tag $entity)
* @method string tagList()
* @method string tagAnchor($tagName, $content)
Expand Down
Expand Up @@ -2,11 +2,11 @@

namespace MamuzBlogTest\View\Helper;

use MamuzBlog\View\Helper\PermaLink;
use MamuzBlog\View\Helper\PermaLinkPost;

class PermaLinkTest extends \PHPUnit_Framework_TestCase
class PermaLinkPostTest extends \PHPUnit_Framework_TestCase
{
/** @var PermaLink */
/** @var PermaLinkPost */
protected $fixture;

/** @var \MamuzBlog\Entity\Post | \Mockery\MockInterface */
Expand All @@ -30,7 +30,7 @@ protected function setUp()
array('title' => '_title_', 'id' => '_hashId_')
)->andReturn('url');

$this->fixture = new PermaLink;
$this->fixture = new PermaLinkPost;
$this->fixture->setView($this->renderer);
}

Expand Down
43 changes: 43 additions & 0 deletions tests/MamuzBlogTest/View/Helper/PermaLinkTagTest.php
@@ -0,0 +1,43 @@
<?php

namespace MamuzBlogTest\View\Helper;

use MamuzBlog\View\Helper\PermaLinkTag;

class PermaLinkTagTest extends \PHPUnit_Framework_TestCase
{
/** @var PermaLinkTag */
protected $fixture;

/** @var \Zend\View\Renderer\RendererInterface | \Mockery\MockInterface */
protected $renderer;

protected function setUp()
{
$this->renderer = \Mockery::mock('Zend\View\Renderer\RendererInterface');
$this->renderer->shouldReceive('serverUrl')->andReturn('server_');
$this->renderer->shouldReceive('url')->with(
'blogPublishedPosts',
array('tag' => 'tagname')
)->andReturn('url');

$this->fixture = new PermaLinkTag;
$this->fixture->setView($this->renderer);
}

public function testExtendingAbstractHelper()
{
$this->assertInstanceOf('MamuzBlog\View\Helper\AbstractHelper', $this->fixture);
}

public function testRender()
{
$permaLink = $this->fixture->render('tagname');

$this->assertSame('server_url', $permaLink);

$invoke = $this->fixture;
$permaLink = $invoke('tagname');
$this->assertSame('server_url', $permaLink);
}
}
2 changes: 1 addition & 1 deletion tests/MamuzBlogTest/View/Helper/PostPanelShortTest.php
Expand Up @@ -26,7 +26,7 @@ protected function setUp()
$this->renderer->shouldReceive('markdown')->with('desc')->andReturn('_content_');
$this->renderer->shouldReceive('hashId')->with(12)->andReturn('_hashId_');
$this->renderer->shouldReceive('slugify')->with('title')->andReturn('_title_');
$this->renderer->shouldReceive('permaLink')->with($this->post)->andReturn('url');
$this->renderer->shouldReceive('permaLinkPost')->with($this->post)->andReturn('url');
$this->renderer->shouldReceive('anchorBookmark')->with('url', 'Go to post', 'title')->andReturn('anchor1');
$this->renderer->shouldReceive('anchorBookmark')->with('url', 'Go to post', 'Read more')->andReturn('anchor2');
$this->renderer->shouldReceive('postMeta')->with($this->post)->andReturn('_meta_');
Expand Down
5 changes: 2 additions & 3 deletions tests/MamuzBlogTest/View/Helper/TagAnchorTest.php
Expand Up @@ -15,11 +15,10 @@ class TagAnchorTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->renderer = \Mockery::mock('Zend\View\Renderer\RendererInterface');
$this->renderer->shouldReceive('serverUrl')->andReturn('server_');
$this->renderer->shouldReceive('url')->with('blogPublishedPosts', array('tag' => 'tagname'))->andReturn('url');
$this->renderer->shouldReceive('permaLinkTag')->with('tagname')->andReturn('url');
$this->renderer
->shouldReceive('anchorBookmark')
->with('server_url', 'Go to specific list', 'content')->andReturn('anchor');
->with('url', 'Go to specific list', 'content')->andReturn('anchor');

$this->fixture = new TagAnchor;
$this->fixture->setView($this->renderer);
Expand Down

0 comments on commit 9e7e4e6

Please sign in to comment.