From 84112fde0c3af444dcd0f667924a5c12b1accf70 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 24 Apr 2016 16:03:44 +0200 Subject: [PATCH] tests: compatibility with Latte master --- tests/Bridges.Latte/UIMacros.control.phpt | 4 +- tests/Bridges.Latte/UIMacros.link.2.phpt | 4 +- tests/Bridges.Latte/UIMacros.link.phpt | 2 +- .../UIMacros.dynamicsnippets.alt.phtml | 80 ++++++----- .../expected/UIMacros.dynamicsnippets.phtml | 56 ++++---- .../expected/UIMacros.snippet.alt.phtml | 78 ++++++----- .../expected/UIMacros.snippet.phtml | 125 ++++++++++++------ 7 files changed, 207 insertions(+), 142 deletions(-) diff --git a/tests/Bridges.Latte/UIMacros.control.phpt b/tests/Bridges.Latte/UIMacros.control.phpt index b6837f867..f4b3ce8fd 100644 --- a/tests/Bridges.Latte/UIMacros.control.phpt +++ b/tests/Bridges.Latte/UIMacros.control.phpt @@ -16,11 +16,11 @@ UIMacros::install($compiler); // {control ...} Assert::match('getComponent("form"); %a%->render() ?>', $compiler->expandMacro('control', 'form', '')->openingCode); -Assert::match('getComponent("form"); %a%->render(); echo $template->filter(%a%) ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode); +Assert::match('getComponent("form"); %a%->render(); echo call_user_func($this->filters->filter, %a%) ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode); Assert::match('getComponent($form); %a%->render() ?>', $compiler->expandMacro('control', '$form', '')->openingCode); Assert::match('getComponent("form"); %a%->renderType() ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode); Assert::match('getComponent("form"); %a%->{"render$type"}() ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode); Assert::match('getComponent("form"); %a%->renderType(\'param\') ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode); Assert::match('getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode); Assert::match('getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode); -Assert::match('getComponent("form"); %a%->render(); echo $template->striptags(%a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode); +Assert::match('getComponent("form"); %a%->render(); echo call_user_func($this->filters->striptags, %a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode); diff --git a/tests/Bridges.Latte/UIMacros.link.2.phpt b/tests/Bridges.Latte/UIMacros.link.2.phpt index 22ec92479..c4f72e356 100644 --- a/tests/Bridges.Latte/UIMacros.link.2.phpt +++ b/tests/Bridges.Latte/UIMacros.link.2.phpt @@ -87,7 +87,7 @@ link:['login'] EOD -, $latte->renderToString(<<renderToString(<< EOD -, $params)); +, $params), [''' => "'"])); diff --git a/tests/Bridges.Latte/UIMacros.link.phpt b/tests/Bridges.Latte/UIMacros.link.phpt index 8a5488246..59ab95d8c 100644 --- a/tests/Bridges.Latte/UIMacros.link.phpt +++ b/tests/Bridges.Latte/UIMacros.link.phpt @@ -17,7 +17,7 @@ UIMacros::install($compiler); // {link ...} Assert::same('link("p") ?>', $compiler->expandMacro('link', 'p', '')->openingCode); -Assert::same('filter($_control->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode); +Assert::same('filters->filter, $_control->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode); Assert::same('link("p:a") ?>', $compiler->expandMacro('link', 'p:a', '')->openingCode); Assert::same('link($dest) ?>', $compiler->expandMacro('link', '$dest', '')->openingCode); Assert::same('link($p:$a) ?>', $compiler->expandMacro('link', '$p:$a', '')->openingCode); diff --git a/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml b/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml index 474742cb2..727943974 100644 --- a/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml +++ b/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml @@ -1,36 +1,16 @@ blocks['_outer1'][] = '_%[a-z0-9]+%__outer1')) { function _%[a-z0-9]+%__outer1($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer1', FALSE) -;%a% foreach (array(1,2,3) as $id) { ?> - > - # - -dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> - - dynSnippets)) return $_l->dynSnippets; -}} +// source: %A% -// -// block _outer2 -// -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) -;%a% foreach (array(1,2,3) as $id) { ?> - > - # +class Template%a% extends Latte\Template +{ -dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> - - dynSnippets)) return $_l->dynSnippets; -}} + function render() + { +%A% +// prolog Latte\Macros\BlockMacros +$_b->blocks['_outer1'][] = [$this, 'block__outer1_%h%']; -// -// end of blocks -// +$_b->blocks['_outer2'][] = [$this, 'block__outer2_%h%']; // template extending @@ -45,13 +25,43 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars()); } -// // main template -// -if ($_l->extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); } ?> -
blocks['_outer1']), $_b, $template->getParameters()) ?> +if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?> +
blocks['_outer1']), $_b, $this->params) ?>
-
blocks['_outer2']), $_b, $template->getParameters()) ?> +
blocks['_outer2']), $_b, $this->params) ?>
$__v) $$__k = $__v; +$_control->redrawControl('outer1', FALSE); + +%a% foreach (array(1,2,3) as $id) { ?> + > + # + +dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
+ + dynSnippets)) return $_l->dynSnippets; + } + + + function block__outer2_%h%($_b, $_args) + { + unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v; +$_control->redrawControl('outer2', FALSE); + +%a% foreach (array(1,2,3) as $id) { ?> + > + # + +dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
+ + dynSnippets)) return $_l->dynSnippets; + } + +} diff --git a/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml b/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml index 867146d78..b62b2b2b7 100644 --- a/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml +++ b/tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml @@ -1,26 +1,14 @@ blocks['_outer'][] = '_%[a-z0-9]+%__outer')) { function _%[a-z0-9]+%__outer($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer', FALSE) -;%a% foreach (array(1,2,3) as $id) { ?> -
-"> +// source: %A% - # +class Template%a% extends Latte\Template +{ -dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> -
- - dynSnippets)) return $_l->dynSnippets; -}} - -// -// end of blocks -// + function render() + { +%A% +// prolog Latte\Macros\BlockMacros +$_b->blocks['_outer'][] = [$this, 'block__outer_%h%']; // template extending @@ -35,10 +23,28 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars()); } -// // main template -// -if ($_l->extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); } ?> -
blocks['_outer']), $_b, $template->getParameters()) ?> +if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?> +
blocks['_outer']), $_b, $this->params) ?>
$__v) $$__k = $__v; +$_control->redrawControl('outer', FALSE); + +%a% foreach (array(1,2,3) as $id) { ?> +
+"> + + # + +dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> +
+ + dynSnippets)) return $_l->dynSnippets; + } + +} diff --git a/tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml b/tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml index 1b2eb07c2..f21e60faf 100644 --- a/tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml +++ b/tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml @@ -1,33 +1,18 @@ blocks['_outer'][] = '_%[a-z0-9]+%__outer')) { function _%[a-z0-9]+%__outer($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('outer', FALSE) -?>

Outer

-blocks['_outer'][] = [$this, 'block__outer_%h%']; -// -// block _inner -// -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) -?>

Inner

-blocks['_inner'][] = [$this, 'block__inner_%h%']; -// -// block _gallery -// -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) -; -}} - -// -// end of blocks -// +$_b->blocks['_gallery'][] = [$this, 'block__gallery_%h%']; // template extending @@ -42,19 +27,46 @@ if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includin return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars()); } -// // main template -// ?>
> -extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); } -call_user_func(reset($_b->blocks['_outer']), $_b, $template->getParameters()) ?> +extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } +call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
> -blocks['_inner']), $_b, $template->getParameters()) ?>
+blocks['_inner']), $_b, $this->params) ?>
-
>blocks['_gallery']), $_b, $template->getParameters()) ?> +
+>blocks['_gallery']), $_b, $this->params) ?>
$__v) $$__k = $__v; +$_control->redrawControl('outer', FALSE) +?>

Outer

+ $__v) $$__k = $__v; +$_control->redrawControl('inner', FALSE) +?>

Inner

+ $__v) $$__k = $__v; +$_control->redrawControl('gallery', FALSE); + + + } + +} diff --git a/tests/Bridges.Latte/expected/UIMacros.snippet.phtml b/tests/Bridges.Latte/expected/UIMacros.snippet.phtml index ecdc2f95f..926fb18af 100644 --- a/tests/Bridges.Latte/expected/UIMacros.snippet.phtml +++ b/tests/Bridges.Latte/expected/UIMacros.snippet.phtml @@ -1,62 +1,99 @@ -%A% -// block _ -// -if (!function_exists($_b->blocks['_'][] = '_%[a-z0-9]+%__')) { function _%[a-z0-9]+%__($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl(%[false']+%, FALSE) -; -}} - -// -// block _outer -// -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) -?> Outer -
blocks['_inner']), $_b, $template->getParameters()) ?> -
- /Outer blocks['_inner'][] = '_%[a-z0-9]+%__inner')) { function _%[a-z0-9]+%__inner($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('inner', FALSE) -?>Innerblocks['_title'][] = '_%[a-z0-9]+%__title')) { function _%[a-z0-9]+%__title($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('title', FALSE) -?>Title 1blocks['_'][] = [$this, 'block___%h%']; -// -// block _title2 -// -if (!function_exists($_b->blocks['_title2'][] = '_%[a-z0-9]+%__title2')) { function _%[a-z0-9]+%__title2($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v; $_control->redrawControl('title2', FALSE) -?>Title 2blocks['_outer'][] = [$this, 'block__outer_%h%']; -// -// end of blocks -%A% +$_b->blocks['_inner'][] = [$this, 'block__inner_%h%']; + +$_b->blocks['_title'][] = [$this, 'block__title_%h%']; + +$_b->blocks['_title2'][] = [$this, 'block__title2_%h%']; + +// template extending + +$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE; + +if ($_l->extends) { ob_start(function () {});} + +// prolog Nette\Bridges\ApplicationLatte\UIMacros + +// snippets support +if (empty($_l->extends) && !empty($_control->snippetMode) && empty($_g->includingBlock)) { return Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($_control, $_b, get_defined_vars()); -%A% -
blocks['_']), $_b, $template->getParameters()) ?> +} + +// main template +?> + +extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?> +
blocks['_']), $_b, $this->params) ?>
-
blocks['_outer']), $_b, $template->getParameters()) ?> +
blocks['_outer']), $_b, $this->params) ?>
@ Hello World @ -

blocks['_title']), $_b, $template->getParameters()) ?> +

blocks['_title']), $_b, $this->params) ?>

+

blocks['_title2']), $_b, $this->params) ?> +

getSnippetId('title2') ?>">blocks['_title2']), $_b, $template->getParameters()) ?> - + + function block___%h%($_b, $_args) + { + unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v; +$_control->redrawControl('', FALSE); + + + } + + + function block__outer_%h%($_b, $_args) + { + unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v; +$_control->redrawControl('outer', FALSE) +?> Outer +
blocks['_inner']), $_b, $this->params) ?> +
/Outer $__v) $$__k = $__v; +$_control->redrawControl('inner', FALSE) +?>Inner $__v) $$__k = $__v; +$_control->redrawControl('title', FALSE) +?>Title 1 $__v) $$__k = $__v; +$_control->redrawControl('title2', FALSE) +?>Title 2