Skip to content

Commit b3a4ffa

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

File tree

7 files changed

+217
-160
lines changed

7 files changed

+217
-160
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);

tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,66 @@
11
<?php
2-
// source: %a%
2+
// source: %A%
3+
4+
class Template%a% extends Latte\Template
5+
{
6+
public $blocks = [
7+
'_outer1' => ['blockOuter1', 'html'],
8+
'_outer2' => ['blockOuter2', 'html'],
9+
];
10+
11+
12+
function render()
13+
{
314
%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) { ?>
15+
// prolog Nette\Bridges\ApplicationLatte\UIMacros
16+
17+
// snippets support
18+
if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includingBlock)) {
19+
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
20+
}
21+
22+
// main template
23+
if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return ?>
24+
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($_b->blocks['_outer1']), $_b, $this->params) ?>
25+
</div>
26+
27+
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $this->params) ?>
28+
</div><?php
29+
}
30+
31+
32+
function blockOuter1($_b, $_args)
33+
{
34+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
35+
$_control->redrawControl('outer1', FALSE);
36+
37+
%a% foreach (array(1,2,3) as $id) { ?>
1038
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
11-
<?php ob_start() ?> #<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
39+
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
1240

1341
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
1442
<?php $iterations++; } ?>
1543
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
16-
}}
44+
}
45+
1746

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) { ?>
47+
function blockOuter2($_b, $_args)
48+
{
49+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
50+
$_control->redrawControl('outer2', FALSE);
51+
52+
%a% foreach (array(1,2,3) as $id) { ?>
2353
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
24-
<?php ob_start() ?> #<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
54+
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
2555

2656
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
2757
<?php $iterations++; } ?>
2858
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
29-
}}
30-
31-
//
32-
// end of blocks
33-
//
59+
}
3460

35-
// template extending
3661

37-
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
62+
function getExtends()
63+
{
64+
}
3865

39-
if ($_l->extends) { ob_start(function () {});}
40-
41-
// prolog Nette\Bridges\ApplicationLatte\UIMacros
42-
43-
// snippets support
44-
if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includingBlock)) {
45-
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
4666
}
47-
48-
//
49-
// 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()) ?>
53-
</div>
54-
55-
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $template->getParameters()) ?>
56-
</div><?php
57-
%A%

tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
<?php
2-
// source: %a%
2+
// source: %A%
3+
4+
class Template%a% extends Latte\Template
5+
{
6+
public $blocks = [
7+
'_outer' => ['blockOuter', 'html'],
8+
];
9+
10+
11+
function render()
12+
{
313
%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) { ?>
14+
// prolog Nette\Bridges\ApplicationLatte\UIMacros
15+
16+
// snippets support
17+
if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includingBlock)) {
18+
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
19+
}
20+
21+
// main template
22+
if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return ?>
23+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
24+
</div><?php
25+
}
26+
27+
28+
function blockOuter($_b, $_args)
29+
{
30+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
31+
$_control->redrawControl('outer', FALSE);
32+
33+
%a% foreach (array(1,2,3) as $id) { ?>
1034
<div id="<?php echo $_l->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
1135
"><?php ob_start() ?>
1236

13-
#<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
37+
#<?php echo LFilters::escapeHtmlText($id) ?>
1438

1539
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
1640
</div>
1741
<?php $iterations++; } ?>
1842
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
19-
}}
20-
21-
//
22-
// end of blocks
23-
//
24-
25-
// template extending
43+
}
2644

27-
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
2845

29-
if ($_l->extends) { ob_start(function () {});}
46+
function getExtends()
47+
{
48+
}
3049

31-
// prolog Nette\Bridges\ApplicationLatte\UIMacros
32-
33-
// snippets support
34-
if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includingBlock)) {
35-
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
3650
}
37-
38-
//
39-
// 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()) ?>
43-
</div><?php
44-
%A%
Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,69 @@
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-
?> <p>Outer</p>
10-
<?php
11-
}}
12-
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-
}}
20-
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-
}}
2+
// source: %A%
273

28-
//
29-
// end of blocks
30-
//
4+
class Template%a% extends Latte\Template
5+
{
6+
public $blocks = [
7+
'_outer' => ['blockOuter', 'html'],
8+
'_inner' => ['blockInner', 'html'],
9+
'_gallery' => ['blockGallery', 'html'],
10+
];
3111

32-
// template extending
33-
34-
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
35-
36-
if ($_l->extends) { ob_start(function () {});}
3712

13+
function render()
14+
{
15+
%A%
3816
// prolog Nette\Bridges\ApplicationLatte\UIMacros
3917

4018
// snippets support
4119
if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includingBlock)) {
4220
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
4321
}
4422

45-
//
4623
// main template
47-
//
4824
?> <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()) ?>
25+
<?php if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return;call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
5126
</div>
5227

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

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()) ?>
31+
<div class="<?php echo LFilters::escapeHtmlAttr('class') ?>"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>
32+
><?php call_user_func(reset($_b->blocks['_gallery']), $_b, $this->params) ?>
5833
</div>
5934
<?php
60-
%A%
35+
}
36+
37+
38+
function blockOuter($_b, $_args)
39+
{
40+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
41+
$_control->redrawControl('outer', FALSE)
42+
?> <p>Outer</p>
43+
<?php
44+
}
45+
46+
47+
function blockInner($_b, $_args)
48+
{
49+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
50+
$_control->redrawControl('inner', FALSE)
51+
?> <p>Inner</p>
52+
<?php
53+
}
54+
55+
56+
function blockGallery($_b, $_args)
57+
{
58+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
59+
$_control->redrawControl('gallery', FALSE);
60+
61+
62+
}
63+
64+
65+
function getExtends()
66+
{
67+
}
68+
69+
}

0 commit comments

Comments
 (0)