2013-02-13 20:51:27 +04:00
|
|
|
<?php
|
2013-02-20 19:51:06 +04:00
|
|
|
namespace Aspect;
|
2013-02-15 01:49:26 +04:00
|
|
|
use Aspect, Aspect\Modifier, Aspect\TestCase;
|
2013-02-13 20:51:27 +04:00
|
|
|
|
2013-02-20 19:51:06 +04:00
|
|
|
class ExtendsTemplateTest extends TestCase {
|
2013-02-13 20:51:27 +04:00
|
|
|
public static function providerExtends() {
|
2013-02-20 19:51:06 +04:00
|
|
|
$a = array("one" => 1, "two" => 2, "three" => 3);
|
2013-02-13 20:51:27 +04:00
|
|
|
return array(
|
2013-02-20 19:51:06 +04:00
|
|
|
array("parent.tpl", "Parent. B1: {block b1}{/block}\nB2: {block 'b2'}empty {\$iteration}{/block}", $a,
|
|
|
|
"Parent. B1: \nB2: empty 0"),
|
|
|
|
array("child1.tpl", '{extends "parent.tpl"} {block b1}from child1 {$iteration}{/block} some trash', $a,
|
|
|
|
"Parent. B1: from child1 1\nB2: empty 1"),
|
|
|
|
array("child2.tpl", '{extends "child1.tpl"} {block "b2"}from child2 {$iteration}{/block} some {block b4}what is it?{/block} trash', $a,
|
|
|
|
"Parent. B1: from child1 2\nB2: from child2 2"),
|
|
|
|
array("child3.tpl", '{extends "child2.tpl"} {block \'b1\'}from child3 {$iteration}{/block} {block "b2"}from child3 {$iteration}{/block} some {block b4}what is it?{/block} trash', $a,
|
|
|
|
"Parent. B1: from child3 3\nB2: from child3 3")
|
2013-02-13 20:51:27 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-20 19:51:06 +04:00
|
|
|
public static function providerDynamicExtends() {
|
|
|
|
$data = self::providerExtends();
|
|
|
|
$data[2][1] = str_replace('"b2"', '"b{$two}"', $data[2][1]);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerExtends
|
|
|
|
* @param $name
|
|
|
|
* @param $code
|
|
|
|
* @param $vars
|
|
|
|
* @param $result
|
|
|
|
*/
|
2013-02-27 20:55:08 +04:00
|
|
|
public function testStaticExtends($name, $code, $vars, $result) {
|
2013-02-20 19:51:06 +04:00
|
|
|
static $i = 0;
|
|
|
|
$vars["iteration"] = $i++;
|
|
|
|
$this->execTpl($name, $code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerDynamicExtends
|
|
|
|
* @param $name
|
|
|
|
* @param $code
|
|
|
|
* @param $vars
|
|
|
|
* @param $result
|
|
|
|
*/
|
2013-03-04 12:40:32 +04:00
|
|
|
public function testDynamicExtends($name, $code, $vars, $result) {
|
2013-02-20 19:51:06 +04:00
|
|
|
static $i = 0;
|
|
|
|
$vars["iteration"] = $i++;
|
2013-03-04 12:40:32 +04:00
|
|
|
$this->execTpl($name, $code, $vars, $result, 0);
|
2013-02-20 19:51:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-13 20:51:27 +04:00
|
|
|
/**
|
|
|
|
* @group extends
|
|
|
|
*/
|
2013-02-20 19:51:06 +04:00
|
|
|
public function _testParentLevel() {
|
2013-02-15 01:49:26 +04:00
|
|
|
//echo($this->aspect->getTemplate("parent.tpl")->_body); exit;
|
|
|
|
$this->assertSame($this->aspect->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default");
|
2013-02-13 20:51:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group extends
|
|
|
|
*/
|
2013-02-21 22:51:24 +04:00
|
|
|
public function testChildLevel1() {
|
2013-02-15 01:49:26 +04:00
|
|
|
//echo($this->aspect->fetch("child1.tpl", array("a" => "a char"))); exit;
|
2013-02-13 20:51:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group extends
|
|
|
|
*/
|
2013-02-15 01:49:26 +04:00
|
|
|
public function _testChildLevel3() {
|
|
|
|
echo($this->aspect->getTemplate("child3.tpl")->getBody()); exit;
|
2013-02-13 20:51:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|