Skip to content

Commit

Permalink
tests: compatibility with Latte master
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 26, 2016
1 parent 421256c commit 84112fd
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 142 deletions.
4 changes: 2 additions & 2 deletions tests/Bridges.Latte/UIMacros.control.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ UIMacros::install($compiler);

// {control ...}
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render() ?>', $compiler->expandMacro('control', 'form', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo $template->filter(%a%) ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo call_user_func($this->filters->filter, %a%) ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode);
Assert::match('<?php if (is_object($form)) %a% else %a% $_control->getComponent($form); %a%->render() ?>', $compiler->expandMacro('control', '$form', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType() ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->{"render$type"}() ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType(\'param\') ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo $template->striptags(%a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode);
Assert::match('<?php %a% $_control->getComponent("form"); %a%->render(); echo call_user_func($this->filters->striptags, %a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode);
4 changes: 2 additions & 2 deletions tests/Bridges.Latte/UIMacros.link.2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ link:['login']
<a href="link:['default!#hash',10,20]"></a>
EOD

, $latte->renderToString(<<<EOD
, strtr($latte->renderToString(<<<EOD
{plink Homepage:}
{plink Homepage: }
Expand Down Expand Up @@ -118,4 +118,4 @@ EOD
<a n:href="default!#hash 10, 20"></a>
EOD
, $params));
, $params), ['&#039;' => "'"]));
2 changes: 1 addition & 1 deletion tests/Bridges.Latte/UIMacros.link.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ UIMacros::install($compiler);

// {link ...}
Assert::same('<?php echo $_control->link("p") ?>', $compiler->expandMacro('link', 'p', '')->openingCode);
Assert::same('<?php echo $template->filter($_control->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode);
Assert::same('<?php echo call_user_func($this->filters->filter, $_control->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode);
Assert::same('<?php echo $_control->link("p:a") ?>', $compiler->expandMacro('link', 'p:a', '')->openingCode);
Assert::same('<?php echo $_control->link($dest) ?>', $compiler->expandMacro('link', '$dest', '')->openingCode);
Assert::same('<?php echo $_control->link($p:$a) ?>', $compiler->expandMacro('link', '$p:$a', '')->openingCode);
Expand Down
80 changes: 45 additions & 35 deletions tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
<?php
// source: %a%
%A%
// prolog Latte\Macros\BlockMacros
//
// block _outer1
//
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)
;%a% foreach (array(1,2,3) as $id) { ?>
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
<?php ob_start() ?> #<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>

<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
<?php $iterations++; } ?>
<?php if (isset($_l->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) { ?>
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
<?php ob_start() ?> #<?php echo Latte\Runtime\Filters::escapeHtml($id, ENT_NOQUOTES) ?>
class Template%a% extends Latte\Template
{

<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
<?php $iterations++; } ?>
<?php if (isset($_l->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

Expand All @@ -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()); } ?>
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($_b->blocks['_outer1']), $_b, $template->getParameters()) ?>
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($_b->blocks['_outer1']), $_b, $this->params) ?>
</div>

<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $template->getParameters()) ?>
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($_b->blocks['_outer2']), $_b, $this->params) ?>
</div><?php
%A%
}


function block__outer1_%h%($_b, $_args)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
$_control->redrawControl('outer1', FALSE);

%a% foreach (array(1,2,3) as $id) { ?>
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>

<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
<?php $iterations++; } ?>
<?php if (isset($_l->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) { ?>
<div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>

<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?> </div>
<?php $iterations++; } ?>
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
}

}
56 changes: 31 additions & 25 deletions tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
<?php
// source: %a%
%A%
// prolog Latte\Macros\BlockMacros
//
// 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)
;%a% foreach (array(1,2,3) as $id) { ?>
<div id="<?php echo $_l->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
"><?php ob_start() ?>
// source: %A%

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

<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
</div>
<?php $iterations++; } ?>
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
}}

//
// end of blocks
//
function render()
{
%A%
// prolog Latte\Macros\BlockMacros
$_b->blocks['_outer'][] = [$this, 'block__outer_%h%'];

// template extending

Expand All @@ -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()); } ?>
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $template->getParameters()) ?>
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); } ?>
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
</div><?php
%A%
}


function block__outer_%h%($_b, $_args)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
$_control->redrawControl('outer', FALSE);

%a% foreach (array(1,2,3) as $id) { ?>
<div id="<?php echo $_l->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
"><?php ob_start() ?>

#<?php echo LFilters::escapeHtmlText($id) ?>

<?php $_l->dynSnippets[$_l->dynSnippetId] = ob_get_flush() ?>
</div>
<?php $iterations++; } ?>
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
}

}
78 changes: 45 additions & 33 deletions tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
<?php
// source: %a%
// source: %A%

class Template%a% extends Latte\Template
{

function render()
{
%A%
// prolog Latte\Macros\BlockMacros
//
// 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)
?> <p>Outer</p>
<?php
}}
$_b->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)
?> <p>Inner</p>
<?php
}}
$_b->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

Expand All @@ -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
//
?> <div class="test"<?php echo ' id="' . $_control->getSnippetId('outer') . '"' ?>>
<?php if ($_l->extends) { ob_end_clean(); return $template->renderChildTemplate($_l->extends, get_defined_vars()); }
call_user_func(reset($_b->blocks['_outer']), $_b, $template->getParameters()) ?>
<?php if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
</div>

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

<div class="<?php echo Latte\Runtime\Filters::escapeHtml('class', ENT_COMPAT) ?>
"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>><?php call_user_func(reset($_b->blocks['_gallery']), $_b, $template->getParameters()) ?>
<div class="<?php echo LFilters::escapeHtmlAttr('class') ?>"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>
><?php call_user_func(reset($_b->blocks['_gallery']), $_b, $this->params) ?>
</div>
<?php
%A%
}


function block__outer_%h%($_b, $_args)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
$_control->redrawControl('outer', FALSE)
?> <p>Outer</p>
<?php
}


function block__inner_%h%($_b, $_args)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
$_control->redrawControl('inner', FALSE)
?> <p>Inner</p>
<?php
}


function block__gallery_%h%($_b, $_args)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
$_control->redrawControl('gallery', FALSE);


}

}
Loading

0 comments on commit 84112fd

Please sign in to comment.