Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/view-helper-translator' of https://github.com/we…
Browse files Browse the repository at this point in the history
…ierophinney/zf2 into weierophinney-hotfix/view-helper-translator
  • Loading branch information
ezimuel committed Jul 22, 2013
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HelperPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public function injectTranslator($helper)
{
if ($helper instanceof TranslatorAwareInterface) {
$locator = $this->getServiceLocator();
if ($locator && $locator->has('translator')) {
if ($locator && $locator->has('MvcTranslator')) {
$helper->setTranslator($locator->get('MvcTranslator'));
} elseif ($locator && $locator->has('translator')) {
$helper->setTranslator($locator->get('translator'));
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/HelperPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace ZendTest\View;

use Zend\I18n\Translator\Translator;
use Zend\Mvc\I18n\Translator as MvcTranslator;
use Zend\ServiceManager\ServiceManager;
use Zend\View\HelperPluginManager;
use Zend\View\Renderer\PhpRenderer;
Expand Down Expand Up @@ -80,4 +82,26 @@ public function testIdentityFactoryCanInjectAuthenticationServiceIfInParentServi
$expected = $services->get('Zend\Authentication\AuthenticationService');
$this->assertSame($expected, $identity->getAuthenticationService());
}

public function testIfHelperIsTranslatorAwareAndMvcTranslatorIsAvailableItWillInjectTheMvcTranslator()
{
$translator = new MvcTranslator();
$services = new ServiceManager();
$services->setService('MvcTranslator', $translator);
$this->helpers->setServiceLocator($services);

$helper = $this->helpers->get('HeadTitle');
$this->assertSame($translator, $helper->getTranslator());
}

public function testIfHelperIsTranslatorAwareAndMvcTranslatorIsUnavailableAndTranslatorIsAvailableItWillInjectTheTranslator()
{
$translator = new Translator();
$services = new ServiceManager();
$services->setService('Translator', $translator);
$this->helpers->setServiceLocator($services);

$helper = $this->helpers->get('HeadTitle');
$this->assertSame($translator, $helper->getTranslator());
}
}

0 comments on commit b7a9769

Please sign in to comment.