Skip to content

Commit 3a5f333

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

File tree

7 files changed

+205
-151
lines changed

7 files changed

+205
-151
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: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
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-
}}
17-
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) ?>
2+
// source: %A%
253

26-
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
27-
<?php $iterations++; } ?>
28-
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
29-
}}
30-
31-
//
32-
// end of blocks
33-
//
4+
class Template%a% extends Latte\Template
5+
{
6+
public $_blocks = [
7+
'_outer1' => 'block__outer1_76b7a10',
8+
'_outer2' => 'block__outer2_6ee343a',
9+
];
3410

35-
// template extending
3611

12+
function render()
13+
{
14+
%A%
3715
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
3816

3917
if ($_l->extends) { ob_start(function () {});}
@@ -45,13 +23,43 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin
4523
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
4624
}
4725

48-
//
4926
// 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()) ?>
27+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
28+
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($_b->blocks['_outer1']), $_b, $this->params) ?>
5329
</div>
5430

55-
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $template->getParameters()) ?>
31+
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $this->params) ?>
5632
</div><?php
57-
%A%
33+
}
34+
35+
36+
function block__outer1_%h%($_b, $_args)
37+
{
38+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
39+
$_control->redrawControl('outer1', FALSE);
40+
41+
%a% foreach (array(1,2,3) as $id) { ?>
42+
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
43+
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
44+
45+
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
46+
<?php $iterations++; } ?>
47+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
48+
}
49+
50+
51+
function block__outer2_%h%($_b, $_args)
52+
{
53+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
54+
$_control->redrawControl('outer2', FALSE);
55+
56+
%a% foreach (array(1,2,3) as $id) { ?>
57+
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
58+
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
59+
60+
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
61+
<?php $iterations++; } ?>
62+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
63+
}
64+
65+
}
Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
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() ?>
12-
13-
#<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
14-
15-
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
16-
</div>
17-
<?php $iterations++; } ?>
18-
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
19-
}}
2+
// source: %A%
203

21-
//
22-
// end of blocks
23-
//
4+
class Template%a% extends Latte\Template
5+
{
6+
public $_blocks = [
7+
'_outer' => 'block__outer_b1d040b',
8+
];
249

25-
// template extending
2610

11+
function render()
12+
{
13+
%A%
2714
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
2815

2916
if ($_l->extends) { ob_start(function () {});}
@@ -35,10 +22,28 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin
3522
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
3623
}
3724

38-
//
3925
// 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()) ?>
26+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
27+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
4328
</div><?php
44-
%A%
29+
}
30+
31+
32+
function block__outer_%h%($_b, $_args)
33+
{
34+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
35+
$_control->redrawControl('outer', FALSE);
36+
37+
%a% foreach (array(1,2,3) as $id) { ?>
38+
<div id="<?php echo $_l->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
39+
"><?php ob_start() ?>
40+
41+
#<?php echo LFilters::escapeHtmlText($id) ?>
42+
43+
<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
44+
</div>
45+
<?php $iterations++; } ?>
46+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
47+
}
48+
49+
}
Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
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-
}}
2+
// source: %A%
203

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-
}}
4+
class Template%a% extends Latte\Template
5+
{
6+
public $_blocks = [
7+
'_outer' => 'block__outer_b1d040b',
8+
'_inner' => 'block__inner_621f214',
9+
'_gallery' => 'block__gallery_4ab8376',
10+
];
2711

28-
//
29-
// end of blocks
30-
//
31-
32-
// template extending
3312

13+
function render()
14+
{
15+
%A%
3416
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
3517

3618
if ($_l->extends) { ob_start(function () {});}
@@ -42,19 +24,46 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin
4224
return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars());
4325
}
4426

45-
//
4627
// main template
47-
//
4828
?> <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()) ?>
29+
<?php if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
30+
call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
5131
</div>
5232

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

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

0 commit comments

Comments
 (0)