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

Commit

Permalink
Merge branch 'feature/3559' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jan 25, 2013
2 parents 303eee7 + 675397a commit 8b1a5d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
8 changes: 7 additions & 1 deletion library/Zend/View/Helper/FlashMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Helper\AbstractHelper;
use Zend\View\Helper\EscapeHtml;
use Zend\I18n\View\Helper\AbstractTranslatorHelper;

/**
* Helper to proxy the plugin flash messenger
*/
class FlashMessenger extends AbstractHelper implements ServiceLocatorAwareInterface
class FlashMessenger extends AbstractTranslatorHelper implements ServiceLocatorAwareInterface
{
/**
* @var ServiceLocatorInterface
Expand Down Expand Up @@ -102,6 +103,11 @@ public function render($namespace = null, array $classes = array())
$escapeHtml = $this->getEscapeHtmlHelper();
$messagesToPrint = array();
array_walk_recursive($messages, function($item) use (&$messagesToPrint, $escapeHtml) {
if (($translator = $this->getTranslator()) !== null) {
$item = $translator->translate(
$item, $this->getTranslatorTextDomain()
);
}
$messagesToPrint[] = $escapeHtml($item);
});

Expand Down
17 changes: 17 additions & 0 deletions tests/ZendTest/View/Helper/FlashMessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,21 @@ public function testCanDisplayListOfMessagesCustomisedByConfig()
$displayInfo = $helper->render(PluginFlashMessenger::NAMESPACE_INFO);
$this->assertEquals($displayInfoAssertion, $displayInfo);
}

public function testCanTranslateMessages()
{
$mockTranslator = $this->getMock('Zend\I18n\Translator\Translator');
$mockTranslator->expects($this->exactly(1))
->method('translate')
->will($this->returnValue('translated message'));

$this->helper->setTranslator($mockTranslator);
$this->assertTrue($this->helper->hasTranslator());

$this->seedMessages();

$displayAssertion = '<ul class="info"><li>translated message</li></ul>';
$display = $this->helper->render(PluginFlashMessenger::NAMESPACE_INFO);
$this->assertEquals($displayAssertion, $display);
}
}
8 changes: 6 additions & 2 deletions tests/ZendTest/View/PhpRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,12 @@ public function testRendererRaisesExceptionInCaseOfExceptionInView()
$model = new ViewModel();
$model->setTemplate('exception');

$this->setExpectedException('Exception', 'thrown from view script');
$this->renderer->render($model);
try {
$this->renderer->render($model);
$this->fail('Exception from renderer should propagate');
} catch (\Exception $e) {
$this->assertInstanceOf('Exception', $e);
}
}

public function testRendererRaisesExceptionIfResolverCannotResolveTemplate()
Expand Down

0 comments on commit 8b1a5d5

Please sign in to comment.