Skip to content

Commit

Permalink
[#1] Ensured nested + sequential children render correctly
Browse files Browse the repository at this point in the history
- Scenario was:
  - child "content" with children, followed by:
  - child "sidebar" with no children
  • Loading branch information
weierophinney committed Feb 16, 2012
1 parent f55c9c1 commit 3d9aabe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
9 changes: 5 additions & 4 deletions library/Zend/View/Helper/RenderChildModel.php
Expand Up @@ -79,10 +79,11 @@ public function render($child)
return '';
}

$view = $this->getView();
$return = $view->render($model);
$helper = $this->getViewModelHelper();
$helper->setCurrent($this->current);
$current = $this->current;
$view = $this->getView();
$return = $view->render($model);
$helper = $this->getViewModelHelper();
$helper->setCurrent($current);
return $return;
}

Expand Down
26 changes: 23 additions & 3 deletions tests/Zend/View/Helper/RenderChildModelTest.php
Expand Up @@ -44,9 +44,10 @@ class RenderChildModelTest extends TestCase
public function setUp()
{
$this->resolver = new TemplateMapResolver(array(
'layout' => __DIR__ . '/../_templates/nested-view-model-layout.phtml',
'child1' => __DIR__ . '/../_templates/nested-view-model-content.phtml',
'child2' => __DIR__ . '/../_templates/nested-view-model-child2.phtml',
'layout' => __DIR__ . '/../_templates/nested-view-model-layout.phtml',
'child1' => __DIR__ . '/../_templates/nested-view-model-content.phtml',
'child2' => __DIR__ . '/../_templates/nested-view-model-child2.phtml',
'complex' => __DIR__ . '/../_templates/nested-view-model-complexlayout.phtml',
));
$this->renderer = $renderer = new PhpRenderer();
$renderer->setCanRenderTrees(true);
Expand Down Expand Up @@ -118,6 +119,25 @@ public function testRendersNestedChildren()
$this->assertContains('Layout end', $result, $result);
}

public function testRendersSequentialChildrenWithNestedChildren()
{
$this->parent->setTemplate('complex');
$child1 = $this->setupFirstChild();
$child1->setTemplate('layout');
$child1->setCaptureTo('content');

$child2 = $this->setupSecondChild();
$child2->setCaptureTo('sidebar');

$nested = new ViewModel();
$nested->setTemplate('child1');
$nested->setCaptureTo('content');
$child1->addChild($nested);

$result = $this->renderer->render($this->parent);
$this->assertRegExp('/Content:\s+Layout start\s+Content for layout\s+Layout end\s+Sidebar:\s+Second child/s', $result, $result);
}

/**
* @outputBuffering enabled
*/
Expand Down
@@ -0,0 +1,5 @@
Content:
<?php echo $this->renderChildModel('content') ?>

Sidebar:
<?php echo $this->renderChildModel('sidebar') ?>

0 comments on commit 3d9aabe

Please sign in to comment.