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

Commit bdcf3a7

Browse files
committed
Merge pull request #43 from koza4ok/ZendViewRenderer_mergeViewModel_fix
mergeViewModel pass array instead of object to mergeParams function
2 parents b46ff34 + cf1221a commit bdcf3a7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/ZendViewRenderer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ private function getNamespacedResolver(AggregateResolver $aggregate)
295295
*/
296296
private function mergeViewModel($name, ModelInterface $model)
297297
{
298-
$params = $this->mergeParams($name, $model->getVariables());
298+
$variables = $model->getVariables();
299+
$params = $this->mergeParams($name, $this->normalizeParams($variables));
299300
$model->setVariables($params);
300301
$model->setTemplate($name);
301302
return $model;

test/ZendViewRendererTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,27 @@ public function testWillRenderAViewModel()
468468
$content = str_replace('<?php echo $name ?>', 'Zend', $content);
469469
$this->assertEquals($content, $result);
470470
}
471+
472+
public function testCanRenderWithChildViewModel()
473+
{
474+
$path = __DIR__ . '/TestAsset';
475+
$renderer = new ZendViewRenderer();
476+
$renderer->addPath($path);
477+
$viewModelParent = new ViewModel();
478+
$viewModelChild = new ViewModel();
479+
$viewModelChild->setTemplate('zendview-null');
480+
$viewModelParent->setVariables([
481+
'layout' => 'zendview-layout',
482+
]);
483+
$viewModelParent->addChild($viewModelChild, 'name');
484+
$result = $renderer->render('zendview', $viewModelParent);
485+
486+
$content = file_get_contents("$path/zendview-null.phtml");
487+
$contentParent = file_get_contents("$path/zendview.phtml");
488+
$contentParentLayout = file_get_contents("$path/zendview-layout.phtml");
489+
//trim is used here, because rendering engine is trimming content too
490+
$content = trim(str_replace('<?php echo $name ?>', $content, $contentParent));
491+
$content = str_replace('<?= $this->content ?>', $content, $contentParentLayout);
492+
$this->assertEquals($content, $result);
493+
}
471494
}

0 commit comments

Comments
 (0)