Skip to content

Commit 65c6607

Browse files
committed
tests: added test for snippet & block
1 parent b3a4ffa commit 65c6607

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return;call_user_func(reset($_b->blocks['_snippet']), $_b, $this->params) ?>
19+
20+
21+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
22+
</div><?php
23+
}
24+
25+
26+
function blockSnippet($_b, $_args)
27+
{
28+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
29+
$_control->redrawControl('snippet', FALSE);
30+
31+
32+
}
33+
34+
35+
function blockBlock1($_b, $_args)
36+
{ ?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
37+
static
38+
</div>
39+
<?php
40+
}
41+
42+
43+
function blockOuter($_b, $_args)
44+
{
45+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
46+
$_control->redrawControl('outer', FALSE)
47+
?>begin
48+
end
49+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
50+
}
51+
52+
53+
function blockBlock2($_b, $_args)
54+
{ ?><div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
55+
dynamic
56+
</div>
57+
<?php
58+
}
59+
60+
61+
function getExtends()
62+
{
63+
}
64+
65+
}
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)