Skip to content

Commit

Permalink
Use MvcTranslator, when available, to inject helpers
Browse files Browse the repository at this point in the history
- Use the MvcTranslator service, when available, to inject view helpers.
  • Loading branch information
weierophinney committed Jul 22, 2013
1 parent 080c7b9 commit 36b20ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/Zend/View/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 tests/ZendTest/View/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 36b20ff

Please sign in to comment.