Skip to content

Commit

Permalink
tests: added test for snippet & block
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 27, 2016
1 parent 3a5f333 commit b42b3fe
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/Bridges.Latte/UIMacros.snippet4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$latte = new Latte\Engine;

Assert::matchFile(
__DIR__ . '/expected/UIMacros.snippet4.phtml',
$latte->compile(__DIR__ . '/templates/snippets.block.latte')
);
67 changes: 67 additions & 0 deletions tests/Bridges.Latte/expected/UIMacros.snippet4.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
// source: %A%

class Template%a% extends Latte\Template
{
public $_blocks = [
'_snippet' => 'block__snippet_142fc55',
'block1' => 'block_block1_9dd085e',
'_outer' => 'block__outer_b1d040b',
'block2' => 'block_block2_e0d89d3',
];


function render()
{
%A%
$_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 () {});}

// main template
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
call_user_func(reset($_b->blocks['_snippet']), $_b, $this->params) ?>


<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
</div><?php
}


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


}


function block_block1_%h%($_b, $_args)
{
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
static
</div>
<?php
}


function block__outer_%h%($_b, $_args)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
$_control->redrawControl('outer', FALSE)
?>begin
end
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
}


function block_block2_%h%($_b, $_args)
{
?><div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
dynamic
</div>
<?php
}

}
12 changes: 12 additions & 0 deletions tests/Bridges.Latte/templates/snippets.block.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div n:snippet="snippet" n:block="block1">
static
</div>


{snippet outer}
begin
<div n:snippet="inner-$id" n:block="block2">
dynamic
</div>
end
{/snippet}

0 comments on commit b42b3fe

Please sign in to comment.