Skip to content

Commit 3adcd65

Browse files
committed
tests: added test for snippet & block
1 parent 140f7a1 commit 3adcd65

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use Tester\Assert;
4+
5+
6+
require __DIR__ . '/../bootstrap.php';
7+
8+
9+
$latte = new Latte\Engine;
10+
11+
Assert::matchFile(
12+
__DIR__ . '/expected/UIMacros.snippet4.phtml',
13+
$latte->compile(__DIR__ . '/templates/snippets.block.latte')
14+
);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
// source: %A%
3+
4+
class Template%a% extends Latte\Template
5+
{
6+
public $blocks = [
7+
'_snippet' => ['blockSnippet', 'html'],
8+
'block1' => ['blockBlock1', 'html'],
9+
'_outer' => ['blockOuter', 'html'],
10+
'block2' => ['blockBlock2', 'html'],
11+
];
12+
13+
14+
function render()
15+
{
16+
%A%
17+
// main template
18+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
19+
call_user_func(reset($_b->blocks['_snippet']), $_b, $this->params) ?>
20+
21+
22+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
23+
</div><?php
24+
}
25+
26+
27+
function blockSnippet($_b, $_args)
28+
{
29+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
30+
$_control->redrawControl('snippet', FALSE);
31+
32+
33+
}
34+
35+
36+
function blockBlock1($_b, $_args)
37+
{ ?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
38+
static
39+
</div>
40+
<?php
41+
}
42+
43+
44+
function blockOuter($_b, $_args)
45+
{
46+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
47+
$_control->redrawControl('outer', FALSE)
48+
?>begin
49+
end
50+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
51+
}
52+
53+
54+
function blockBlock2($_b, $_args)
55+
{ ?><div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
56+
dynamic
57+
</div>
58+
<?php
59+
}
60+
61+
62+
function getExtends()
63+
{
64+
}
65+
66+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div n:snippet="snippet" n:block="block1">
2+
static
3+
</div>
4+
5+
6+
{snippet outer}
7+
begin
8+
<div n:snippet="inner-$id" n:block="block2">
9+
dynamic
10+
</div>
11+
end
12+
{/snippet}

0 commit comments

Comments
 (0)