mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding view files for tests.
Adding test case for elements + extending Making elements extend each other.
This commit is contained in:
parent
b6919a0268
commit
e06895ef91
9 changed files with 57 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
<?php $this->extend('parent_element'); ?>
|
||||
Element content.
|
2
lib/Cake/Test/test_app/View/Elements/parent_element.ctp
Normal file
2
lib/Cake/Test/test_app/View/Elements/parent_element.ctp
Normal file
|
@ -0,0 +1,2 @@
|
|||
Parent Element.
|
||||
<?php echo $this->fetch('content'); ?>
|
3
lib/Cake/Test/test_app/View/Posts/extend_element.ctp
Normal file
3
lib/Cake/Test/test_app/View/Posts/extend_element.ctp
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php $this->extend('parent_view'); ?>
|
||||
View content.
|
||||
<?php echo $this->element('extended_element'); ?>
|
5
lib/Cake/Test/test_app/View/Posts/nested_extends.ctp
Normal file
5
lib/Cake/Test/test_app/View/Posts/nested_extends.ctp
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
$this->extend('parent_1');
|
||||
$this->assign('sidebar', 'Sidebar Content.');
|
||||
?>
|
||||
This is the first template.
|
5
lib/Cake/Test/test_app/View/Posts/parent_1.ctp
Normal file
5
lib/Cake/Test/test_app/View/Posts/parent_1.ctp
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
$this->extend('parent_2');
|
||||
?>
|
||||
This is the first parent.
|
||||
<?php echo $this->fetch('content'); ?>
|
3
lib/Cake/Test/test_app/View/Posts/parent_2.ctp
Normal file
3
lib/Cake/Test/test_app/View/Posts/parent_2.ctp
Normal file
|
@ -0,0 +1,3 @@
|
|||
This is the second parent.
|
||||
<?php echo $this->fetch('content'); ?>
|
||||
<?php echo $this->fetch('sidebar'); ?>
|
2
lib/Cake/Test/test_app/View/Posts/parent_view.ctp
Normal file
2
lib/Cake/Test/test_app/View/Posts/parent_view.ctp
Normal file
|
@ -0,0 +1,2 @@
|
|||
Parent View.
|
||||
<?php echo $this->fetch('content') ?>
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue