Skip to content
Browse files

Merge branch 'hotfix/3385' into develop

Close #3385
  • Loading branch information...
2 parents ccb6638 + 0626cc2 commit 60664eda0d285f63bc287e39593299f14d198c27 @weierophinney weierophinney committed
View
5 library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php
@@ -63,6 +63,7 @@ public function __construct(View $view)
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, array($this, 'render'), -10000);
+ $this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'render'), -10000);
}
/**
@@ -130,6 +131,10 @@ public function render(MvcEvent $e)
try {
$view->render($viewModel);
} catch(\Exception $ex) {
+ if ($e->getName() === MvcEvent::EVENT_RENDER_ERROR) {
+ throw $ex;
+ }
+
$application = $e->getApplication();
$events = $application->getEventManager();
$e->setError(Application::ERROR_EXCEPTION)
View
33 tests/ZendTest/Mvc/View/DefaultRendereringStrategyTest.php
@@ -56,23 +56,27 @@ public function setUp()
public function testAttachesRendererAtExpectedPriority()
{
- $events = new EventManager();
- $events->attachAggregate($this->strategy);
- $listeners = $events->getListeners(MvcEvent::EVENT_RENDER);
-
- $expectedCallback = array($this->strategy, 'render');
- $expectedPriority = -10000;
- $found = false;
- foreach ($listeners as $listener) {
- $callback = $listener->getCallback();
- if ($callback === $expectedCallback) {
- if ($listener->getMetadatum('priority') == $expectedPriority) {
- $found = true;
- break;
+ $evm = new EventManager();
+ $evm->attachAggregate($this->strategy);
+ $events = array(MvcEvent::EVENT_RENDER, MvcEvent::EVENT_RENDER_ERROR);
+
+ foreach ($events as $event) {
+ $listeners = $evm->getListeners($event);
+
+ $expectedCallback = array($this->strategy, 'render');
+ $expectedPriority = -10000;
+ $found = false;
+ foreach ($listeners as $listener) {
+ $callback = $listener->getCallback();
+ if ($callback === $expectedCallback) {
+ if ($listener->getMetadatum('priority') == $expectedPriority) {
+ $found = true;
+ break;
+ }
}
}
+ $this->assertTrue($found, 'Renderer not found');
}
- $this->assertTrue($found, 'Renderer not found');
}
public function testCanDetachListenersFromEventManager()
@@ -132,6 +136,7 @@ public function testTriggersRenderErrorEventInCaseOfRenderingException()
$resolver = new TemplateMapResolver();
$resolver->add('exception', __DIR__ . '/_files/exception.phtml');
$this->renderer->setResolver($resolver);
+
$strategy = new PhpRendererStrategy($this->renderer);
$this->view->getEventManager()->attach($strategy);
View
14 tests/ZendTest/View/PhpRendererTest.php
@@ -330,6 +330,20 @@ public function testRenderedViewModelIsRegisteredAsCurrentViewModel()
$this->assertSame($model, $helper->getCurrent());
}
+ public function testRendererRaisesExceptionInCaseOfExceptionInView()
+ {
+ $resolver = new TemplateMapResolver(array(
+ 'exception' => __DIR__ . '../../Mvc/View/_files/exception.phtml',
+ ));
+ $this->renderer->setResolver($resolver);
+
+ $model = new ViewModel();
+ $model->setTemplate('exception');
+
+ $this->setExpectedException('Exception', 'thrown from view script');
+ $this->renderer->render($model);
+ }
+
public function testRendererRaisesExceptionIfResolverCannotResolveTemplate()
{
$expected = '10 > 9';

0 comments on commit 60664ed

Please sign in to comment.
Something went wrong with that request. Please try again.