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 26, 2016
1 parent 84112fd commit 2c1ae3b
Show file tree
Hide file tree
Showing 3 changed files with 99 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')
);
73 changes: 73 additions & 0 deletions tests/Bridges.Latte/expected/UIMacros.snippet4.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
// source: %A%

class Template%a% extends Latte\Template
{

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

$_b->blocks['block1'][] = [$this, 'block_block1_%h%'];

$_b->blocks['_outer'][] = [$this, 'block__outer_%h%'];

$_b->blocks['block2'][] = [$this, 'block_block2_%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 () {});}

// 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)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v
?><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)
{
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v
?><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 2c1ae3b

Please sign in to comment.