2014-02-14 15:55:36 +04:00
|
|
|
<?php
|
|
|
|
namespace Fenom;
|
|
|
|
use Fenom, Fenom\TestCase;
|
|
|
|
|
|
|
|
class ExtendsTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
public $template_path = 'provider';
|
|
|
|
|
|
|
|
public function _testSandbox()
|
|
|
|
{
|
|
|
|
try {
|
2014-02-22 20:34:53 +04:00
|
|
|
var_dump($this->fenom->getTemplate("extends/static/nested/child.1.tpl")->fetch([]));
|
|
|
|
// var_dump($this->fenom->getTemplate("extends/dynamic/child.2.tpl")->getBody());
|
2014-02-14 15:55:36 +04:00
|
|
|
// var_dump($this->fenom->compileCode('{block "main"}a {parent} b{/block}')->getBody());
|
|
|
|
// $child = $this->fenom->getRawTemplate()->load('autoextends/child.1.tpl', false);
|
|
|
|
// $child->extend('autoextends/parent.tpl');
|
|
|
|
// $child->compile();
|
|
|
|
// print_r($child->getBody());
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo "$e";
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2014-02-22 20:34:53 +04:00
|
|
|
public function testAutoExtendsManual()
|
2014-02-14 15:55:36 +04:00
|
|
|
{
|
2014-02-22 20:34:53 +04:00
|
|
|
$child = $this->fenom->getRawTemplate()->load('extends/auto/child.1.tpl', false);
|
|
|
|
$child->extend('extends/auto/parent.tpl');
|
2014-02-14 15:55:36 +04:00
|
|
|
$child->compile();
|
|
|
|
$result = "Before header
|
|
|
|
Content of the header
|
|
|
|
Before body
|
|
|
|
Child 1 Body
|
|
|
|
Before footer
|
|
|
|
Content of the footer";
|
|
|
|
$this->assertSame($result, $child->fetch(array()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group testAutoExtends
|
|
|
|
*/
|
|
|
|
public function testAutoExtends() {
|
|
|
|
$result = "Before header
|
|
|
|
Child 2 header
|
|
|
|
Before body
|
|
|
|
Child 3 content
|
|
|
|
Before footer
|
|
|
|
Footer from use";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch([
|
2014-02-22 20:34:53 +04:00
|
|
|
'extends/auto/child.3.tpl',
|
|
|
|
'extends/auto/child.2.tpl',
|
|
|
|
'extends/auto/child.1.tpl',
|
|
|
|
'extends/auto/parent.tpl',
|
2014-02-14 15:55:36 +04:00
|
|
|
], array()));
|
|
|
|
}
|
|
|
|
|
2014-02-22 20:34:53 +04:00
|
|
|
public function testStaticExtendLevel1() {
|
|
|
|
$result = "Before header
|
|
|
|
Content of the header
|
|
|
|
Before body
|
|
|
|
Child 1 Body
|
|
|
|
Before footer
|
|
|
|
Content of the footer";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/static/child.1.tpl', array()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStaticExtendLevel3() {
|
|
|
|
$result = "Before header
|
|
|
|
Child 2 header
|
|
|
|
Before body
|
|
|
|
Child 3 content
|
|
|
|
Before footer
|
|
|
|
Footer from use";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/static/child.3.tpl', array()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStaticExtendNested() {
|
|
|
|
$result = "Before body
|
|
|
|
|
|
|
|
Before header
|
|
|
|
Child 1: Content of the header
|
|
|
|
Before footer
|
|
|
|
Content of the footer
|
|
|
|
";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/static/nested/child.1.tpl', array()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _testDynamicExtendLevel2() {
|
|
|
|
$result = "Before header
|
|
|
|
Content of the header
|
|
|
|
Before body
|
|
|
|
Child 1 Body
|
|
|
|
Before footer
|
|
|
|
Content of the footer";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/dynamic/child.2.tpl', array()));
|
|
|
|
}
|
|
|
|
|
2014-02-14 15:55:36 +04:00
|
|
|
}
|
|
|
|
|