2014-02-14 15:55:36 +04:00
|
|
|
<?php
|
|
|
|
namespace Fenom;
|
2014-02-27 16:30:44 +04:00
|
|
|
|
2014-02-14 15:55:36 +04:00
|
|
|
use Fenom, Fenom\TestCase;
|
|
|
|
|
|
|
|
class ExtendsTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
public $template_path = 'provider';
|
|
|
|
|
|
|
|
public function _testSandbox()
|
|
|
|
{
|
|
|
|
try {
|
2014-02-26 23:57:29 +04:00
|
|
|
var_dump($this->fenom->getTemplate('extends/dynamic/child.3.tpl')->getBody());
|
2014-02-14 15:55:36 +04:00
|
|
|
} 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
|
|
|
|
*/
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testAutoExtends()
|
|
|
|
{
|
2014-02-14 15:55:36 +04:00
|
|
|
$result = "Before header
|
|
|
|
Child 2 header
|
|
|
|
Before body
|
|
|
|
Child 3 content
|
|
|
|
Before footer
|
|
|
|
Footer from use";
|
2014-02-22 20:53:36 +04:00
|
|
|
$this->assertSame($result, $this->fenom->fetch(array(
|
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-22 20:53:36 +04:00
|
|
|
), array()));
|
2014-02-14 15:55:36 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testStaticExtendLevel1()
|
|
|
|
{
|
2014-02-22 20:34:53 +04:00
|
|
|
$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()));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testStaticExtendLevel3()
|
|
|
|
{
|
2014-02-22 20:34:53 +04:00
|
|
|
$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()));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testAutoAndStaticExtend()
|
|
|
|
{
|
2014-02-26 23:57:29 +04:00
|
|
|
$result = "Before header
|
|
|
|
Child 2 header
|
|
|
|
Before body
|
|
|
|
Child 3 content
|
|
|
|
Before footer
|
|
|
|
Footer from use";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch(array(
|
|
|
|
'extends/auto/child.3.tpl',
|
|
|
|
'extends/auto/child.2.tpl',
|
|
|
|
'extends/auto/static/child.1.tpl'
|
|
|
|
), array()));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testStaticExtendNested()
|
|
|
|
{
|
2014-02-22 20:34:53 +04:00
|
|
|
$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()));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testDynamicExtendLevel2()
|
|
|
|
{
|
2014-02-22 20:34:53 +04:00
|
|
|
$result = "Before header
|
2014-02-26 23:57:29 +04:00
|
|
|
Child 2 header
|
2014-02-22 20:34:53 +04:00
|
|
|
Before body
|
|
|
|
Child 1 Body
|
|
|
|
Before footer
|
2014-02-26 23:57:29 +04:00
|
|
|
Footer from use";
|
2014-02-22 20:34:53 +04:00
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/dynamic/child.2.tpl', array()));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testDynamicExtendLevel3()
|
|
|
|
{
|
2014-02-26 23:57:29 +04:00
|
|
|
$result = "Before header
|
|
|
|
Child 2 header
|
|
|
|
Before body
|
|
|
|
Child 3 content
|
|
|
|
Before footer
|
|
|
|
Footer from use";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/dynamic/child.3.tpl', array()));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function testDynamicExtendLevel4()
|
|
|
|
{
|
2014-02-26 23:57:29 +04:00
|
|
|
$result = "Before header
|
|
|
|
Child 2 header
|
|
|
|
Before body
|
|
|
|
Child 3 content
|
|
|
|
Before footer
|
|
|
|
Footer from use";
|
|
|
|
$this->assertSame($result, $this->fenom->fetch('extends/dynamic/child.4.tpl', array()));
|
|
|
|
}
|
2014-02-14 15:55:36 +04:00
|
|
|
}
|
|
|
|
|