Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Fix: Pass repository instead of array into view helper #373

Merged
merged 1 commit into from
Feb 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions module/ZfModule/src/ZfModule/View/Helper/ModuleDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
class ModuleDescription extends AbstractHelper
{
/**
* @param array $module
* @param $repository
* @return string
*/
public function __invoke(array $module)
public function __invoke($repository)
{
return $this->getView()->render('zf-module/helper/module-description.phtml', [
'module' => $module,
'owner' => $repository->owner->login,
'name' => $repository->name,
'createdAt' => $repository->created_at,
'url' => $repository->html_url,
'photoUrl' => $repository->owner->avatar_url,
'description' => $repository->description,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
namespace ZfModuleTest\View\Helper;

use PHPUnit_Framework_TestCase;
use stdClass;
use Zend\View;
use ZfModule\View\Helper;

class ModuleDescriptionTest extends PHPUnit_Framework_TestCase
{
public function testInvokeRendersViewScript()
{
$module = [
'foo' => 'bar',
];
$module = new stdClass();
$module->owner = new stdClass();
$module->owner->login = 'foo';
$module->owner->avatar_url = 'http://www.example.org/john.gif';
$module->name = 'bar';
$module->created_at = '1970-01-01 00:00:00';
$module->html_url = 'http://www.example.org';
$module->description = 'blah blah blah';

$view = $this->getMockForAbstractClass(View\Renderer\RendererInterface::class);

Expand All @@ -22,7 +28,12 @@ public function testInvokeRendersViewScript()
->with(
$this->equalTo('zf-module/helper/module-description.phtml'),
$this->equalTo([
'module' => $module,
'owner' => $module->owner->login,
'name' => $module->name,
'createdAt' => $module->created_at,
'url' => $module->html_url,
'photoUrl' => $module->owner->avatar_url,
'description' => $module->description,
])
)
;
Expand Down
12 changes: 6 additions & 6 deletions module/ZfModule/view/zf-module/helper/module-description.phtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="row">
<div class="hidden-xs col-sm-2">
<img src="<?php echo $this->escapeHtmlAttr($module['photo_url']) ?>" alt="<?php echo $this->escapeHtmlAttr($module['owner']) ?>" class="thumbnail img-responsive">
<img src="<?php echo $this->escapeHtmlAttr($this->photoUrl); ?>" alt="<?php echo $this->escapeHtmlAttr($this->owner); ?>" class="thumbnail img-responsive">
</div>
<div class="col-xs-7 col-sm-6">
<p><strong><?php echo $this->escapeHtml($module['name']) ?></strong></p>
<p><span class="zf-green">Submitter:</span> <?php echo $this->escapeHtml($module['owner']) ?></p>
<p><span class="zf-green">Created:</span> <?php echo $this->dateFormat(new DateTime($module['created_at']), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); ?></p>
<p><strong><?php echo $this->escapeHtml($this->name); ?></strong></p>
<p><span class="zf-green">Submitter:</span> <?php echo $this->escapeHtml($this->owner); ?></p>
<p><span class="zf-green">Created:</span> <?php echo $this->dateFormat(new DateTime($this->createdAt), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); ?></p>
</div>
<div class="col-xs-4">
<a href="<?php echo $this->escapeHtmlAttr($module['url']) ?>">Show module on GitHub</a>
<a href="<?php echo $this->escapeHtmlAttr($this->url); ?>">Show module on GitHub</a>
</div>
</div>
</div>
9 changes: 1 addition & 8 deletions module/ZfModule/view/zf-module/index/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@
</div>
<div class="col-md-4">
<div class="sidebar">
<?php echo $this->moduleDescription([
'owner' => $repository->owner->login,
'name' => $repository->name,
'created_at' => $repository->created_at,
'url' => $repository->html_url,
'photo_url' => $repository->owner->avatar_url,
'description' => $repository->description
]) ?>
<?php echo $this->moduleDescription($repository); ?>
</div>
</div>
</div>