Skip to content

Commit 84112fd

Browse files
committed
tests: compatibility with Latte master
1 parent 421256c commit 84112fd

File tree

7 files changed

+207
-142
lines changed

7 files changed

+207
-142
lines changed

tests/Bridges.Latte/UIMacros.control.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ UIMacros::install($compiler);
1616

1717
// {control ...}
1818
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render() ?>', $compiler->expandMacro('control', 'form', '')->openingCode);
19-
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo $template->filter(%a%) ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode);
19+
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo call_user_func($this->filters->filter, %a%) ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode);
2020
Assert::match('<?php if (is_object($form)) %a% else %a% $_control->getComponent($form); %a%->render() ?>', $compiler->expandMacro('control', '$form', '')->openingCode);
2121
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType() ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode);
2222
Assert::match('<?php %a% $_control->getComponent("form"); %a%->{"render$type"}() ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode);
2323
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType(\'param\') ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode);
2424
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode);
2525
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode);
26-
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo $template->striptags(%a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode);
26+
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo call_user_func($this->filters->striptags, %a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode);

tests/Bridges.Latte/UIMacros.link.2.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ link:['login']
8787
<a href="link:['default!#hash',10,20]"></a>
8888
EOD
8989

90-
, $latte->renderToString(<<<EOD
90+
, strtr($latte->renderToString(<<<EOD
9191
{plink Homepage:}
9292
9393
{plink Homepage: }
@@ -118,4 +118,4 @@ EOD
118118
119119
<a n:href="default!#hash 10, 20"></a>
120120
EOD
121-
, $params));
121+
, $params), ['&#039;' => "'"]));

tests/Bridges.Latte/UIMacros.link.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ UIMacros::install($compiler);
1717

1818
// {link ...}
1919
Assert::same('<?php echo $_control->link("p") ?>', $compiler->expandMacro('link', 'p', '')->openingCode);
20-
Assert::same('<?php echo $template->filter($_control->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode);
20+
Assert::same('<?php echo call_user_func($this->filters->filter, $_control->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode);
2121
Assert::same('<?php echo $_control->link("p:a") ?>', $compiler->expandMacro('link', 'p:a', '')->openingCode);
2222
Assert::same('<?php echo $_control->link($dest) ?>', $compiler->expandMacro('link', '$dest', '')->openingCode);
2323
Assert::same('<?php echo $_control->link($p:$a) ?>', $compiler->expandMacro('link', '$p:$a', '')->openingCode);
Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
<?php
2-
// source: %a%
3-
%A%
4-
// prolog Latte\Macros\BlockMacros
5-
//
6-
// block _outer1
7-
//
8-
if (!function_exists($_b->blocks['_outer1'][] = '_%[a-z0-9]+%__outer1')) { function _%[a-z0-9]+%__outer1($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer1', FALSE)
9-
;%a% foreach (array(1,2,3) as $id) { ?>
10-
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
11-
<?php ob_start() ?> #<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
12-
13-
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
14-
<?php $iterations++; } ?>
15-
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
16-
}}
2+
// source: %A%
173

18-
//
19-
// block _outer2
20-
//
21-
if (!function_exists($_b->blocks['_outer2'][] = '_%[a-z0-9]+%__outer2')) { function _%[a-z0-9]+%__outer2($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer2', FALSE)
22-
;%a% foreach (array(1,2,3) as $id) { ?>
23-
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
24-
<?php ob_start() ?> #<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
4+
class Template%a% extends Latte\Template
5+
{
256

26-
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
27-
<?php $iterations++; } ?>
28-
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
29-
}}
7+
function render()
8+
{
9+
%A%
10+
// prolog Latte\Macros\BlockMacros
11+
$_b->blocks['_outer1'][] = [$this, 'block__outer1_%h%'];
3012

31-
//
32-
// end of blocks
33-
//
13+
$_b->blocks['_outer2'][] = [$this, 'block__outer2_%h%'];
3414

3515
// template extending
3616

@@ -45,13 +25,43 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin
4525
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
4626
}
4727

48-
//
4928
// main template
50-
//
51-
if ($_l->extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
52-
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($_b->blocks['_outer1']), $_b, $template->getParameters()) ?>
29+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
30+
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($_b->blocks['_outer1']), $_b, $this->params) ?>
5331
</div>
5432

55-
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $template->getParameters()) ?>
33+
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $this->params) ?>
5634
</div><?php
57-
%A%
35+
}
36+
37+
38+
function block__outer1_%h%($_b, $_args)
39+
{
40+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
41+
$_control->redrawControl('outer1', FALSE);
42+
43+
%a% foreach (array(1,2,3) as $id) { ?>
44+
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
45+
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
46+
47+
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
48+
<?php $iterations++; } ?>
49+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
50+
}
51+
52+
53+
function block__outer2_%h%($_b, $_args)
54+
{
55+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
56+
$_control->redrawControl('outer2', FALSE);
57+
58+
%a% foreach (array(1,2,3) as $id) { ?>
59+
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
60+
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
61+
62+
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
63+
<?php $iterations++; } ?>
64+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
65+
}
66+
67+
}
Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
<?php
2-
// source: %a%
3-
%A%
4-
// prolog Latte\Macros\BlockMacros
5-
//
6-
// block _outer
7-
//
8-
if (!function_exists($_b->blocks['_outer'][] = '_%[a-z0-9]+%__outer')) { function _%[a-z0-9]+%__outer($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer', FALSE)
9-
;%a% foreach (array(1,2,3) as $id) { ?>
10-
<div id="<?php echo $_l->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
11-
"><?php ob_start() ?>
2+
// source: %A%
123

13-
#<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
4+
class Template%a% extends Latte\Template
5+
{
146

15-
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
16-
</div>
17-
<?php $iterations++; } ?>
18-
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
19-
}}
20-
21-
//
22-
// end of blocks
23-
//
7+
function render()
8+
{
9+
%A%
10+
// prolog Latte\Macros\BlockMacros
11+
$_b->blocks['_outer'][] = [$this, 'block__outer_%h%'];
2412

2513
// template extending
2614

@@ -35,10 +23,28 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin
3523
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
3624
}
3725

38-
//
3926
// main template
40-
//
41-
if ($_l->extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
42-
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $template->getParameters()) ?>
27+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
28+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
4329
</div><?php
44-
%A%
30+
}
31+
32+
33+
function block__outer_%h%($_b, $_args)
34+
{
35+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
36+
$_control->redrawControl('outer', FALSE);
37+
38+
%a% foreach (array(1,2,3) as $id) { ?>
39+
<div id="<?php echo $_l->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
40+
"><?php ob_start() ?>
41+
42+
#<?php echo LFilters::escapeHtmlText($id) ?>
43+
44+
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
45+
</div>
46+
<?php $iterations++; } ?>
47+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
48+
}
49+
50+
}
Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
<?php
2-
// source: %a%
2+
// source: %A%
3+
4+
class Template%a% extends Latte\Template
5+
{
6+
7+
function render()
8+
{
39
%A%
410
// prolog Latte\Macros\BlockMacros
5-
//
6-
// block _outer
7-
//
8-
if (!function_exists($_b->blocks['_outer'][] = '_%[a-z0-9]+%__outer')) { function _%[a-z0-9]+%__outer($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer', FALSE)
9-
?> <p>Outer</p>
10-
<?php
11-
}}
11+
$_b->blocks['_outer'][] = [$this, 'block__outer_%h%'];
1212

13-
//
14-
// block _inner
15-
//
16-
if (!function_exists($_b->blocks['_inner'][] = '_%[a-z0-9]+%__inner')) { function _%[a-z0-9]+%__inner($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('inner', FALSE)
17-
?> <p>Inner</p>
18-
<?php
19-
}}
13+
$_b->blocks['_inner'][] = [$this, 'block__inner_%h%'];
2014

21-
//
22-
// block _gallery
23-
//
24-
if (!function_exists($_b->blocks['_gallery'][] = '_%[a-z0-9]+%__gallery')) { function _%[a-z0-9]+%__gallery($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('gallery', FALSE)
25-
;
26-
}}
27-
28-
//
29-
// end of blocks
30-
//
15+
$_b->blocks['_gallery'][] = [$this, 'block__gallery_%h%'];
3116

3217
// template extending
3318

@@ -42,19 +27,46 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin
4227
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
4328
}
4429

45-
//
4630
// main template
47-
//
4831
?> <div class="test"<?php echo ' id="' . $_control->getSnippetId('outer') . '"' ?>>
49-
<?php if ($_l->extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); }
50-
call_user_func(reset($_b->blocks['_outer']), $_b, $template->getParameters()) ?>
32+
<?php if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
33+
call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
5134
</div>
5235

5336
<div class="test"<?php echo ' id="' . $_control->getSnippetId('inner') . '"' ?>>
54-
<?php call_user_func(reset($_b->blocks['_inner']), $_b, $template->getParameters()) ?> </div>
37+
<?php call_user_func(reset($_b->blocks['_inner']), $_b, $this->params) ?> </div>
5538

56-
<div class="<?php echo Latte\Runtime\Filters::escapeHtml('class', ENT_COMPAT) ?>
57-
"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>><?php call_user_func(reset($_b->blocks['_gallery']), $_b, $template->getParameters()) ?>
39+
<div class="<?php echo LFilters::escapeHtmlAttr('class') ?>"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>
40+
><?php call_user_func(reset($_b->blocks['_gallery']), $_b, $this->params) ?>
5841
</div>
5942
<?php
60-
%A%
43+
}
44+
45+
46+
function block__outer_%h%($_b, $_args)
47+
{
48+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
49+
$_control->redrawControl('outer', FALSE)
50+
?> <p>Outer</p>
51+
<?php
52+
}
53+
54+
55+
function block__inner_%h%($_b, $_args)
56+
{
57+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
58+
$_control->redrawControl('inner', FALSE)
59+
?> <p>Inner</p>
60+
<?php
61+
}
62+
63+
64+
function block__gallery_%h%($_b, $_args)
65+
{
66+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
67+
$_control->redrawControl('gallery', FALSE);
68+
69+
70+
}
71+
72+
}

0 commit comments

Comments
 (0)