Adding view files for tests.

Adding test case for elements + extending
Making elements extend each other.
This commit is contained in:
mark_story 2011-09-25 21:52:11 -04:00
parent b6919a0268
commit e06895ef91
9 changed files with 57 additions and 1 deletions

View file

@ -1039,6 +1039,23 @@ This is the second parent.
This is the first parent.
This is the first template.
Sidebar Content.
TEXT;
$this->assertEquals($expected, $content);
}
/**
* Test extend() in an element and a view.
*
* @return void
*/
public function testExtendElement() {
$this->View->layout = false;
$content = $this->View->render('extend_element');
$expected = <<<TEXT
Parent View.
View content.
Parent Element.
Element content.
TEXT;
$this->assertEquals($expected, $content);

View file

@ -0,0 +1,2 @@
<?php $this->extend('parent_element'); ?>
Element content.

View file

@ -0,0 +1,2 @@
Parent Element.
<?php echo $this->fetch('content'); ?>

View file

@ -0,0 +1,3 @@
<?php $this->extend('parent_view'); ?>
View content.
<?php echo $this->element('extended_element'); ?>

View file

@ -0,0 +1,5 @@
<?php
$this->extend('parent_1');
$this->assign('sidebar', 'Sidebar Content.');
?>
This is the first template.

View file

@ -0,0 +1,5 @@
<?php
$this->extend('parent_2');
?>
This is the first parent.
<?php echo $this->fetch('content'); ?>

View file

@ -0,0 +1,3 @@
This is the second parent.
<?php echo $this->fetch('content'); ?>
<?php echo $this->fetch('sidebar'); ?>

View file

@ -0,0 +1,2 @@
Parent View.
<?php echo $this->fetch('content') ?>

View file

@ -260,6 +260,14 @@ class View extends Object {
*/
protected $_current = null;
/**
* Currently rendering an element. Used for finding parent fragments
* for elements.
*
* @var boolean
*/
protected $_inElement = false;
/**
* Content stack, used for nested templates that all use View::extend();
*
@ -349,7 +357,11 @@ class View extends Object {
if ($callbacks) {
$this->Helpers->trigger('beforeRender', array($file));
}
$this->_inElement = true;
$element = $this->_render($file, array_merge($this->viewVars, $data));
$this->_inElement = false;
if ($callbacks) {
$this->Helpers->trigger('afterRender', array($file, $element));
}
@ -640,7 +652,12 @@ class View extends Object {
* @param string $name The view or element to 'extend' the current one with.
*/
public function extend($name) {
$this->_parents[$this->_current] = $this->_getViewFileName($name);
if ($this->_inElement) {
$parent = $this->_getElementFileName($name);
} else {
$parent = $this->_getViewFileName($name);
}
$this->_parents[$this->_current] = $parent;
}
/**