Skip to content

Commit

Permalink
test: added new
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 8, 2021
1 parent 108d4a7 commit c28492c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Latte/BlockMacros.block.vars.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* Test: variable scope
*/

declare(strict_types=1);

use Tester\Assert;


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


$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);

$template = <<<'XX'
{var $var = a}
{define a}
{$var}
{var $var = define}
{/define}
{$var}
{block b}
{$var}
{var $var = blocknamed}
{/block}
{$var}
{block|trim}
{$var}
{var $var = blockmod}
{/block}
{$var}
{block}
{$var}
{var $var = block}
{/block}
{$var}
XX;

Assert::matchFile(
__DIR__ . '/expected/BlockMacros.vars.phtml',
$latte->compile($template)
);
Assert::matchFile(
__DIR__ . '/expected/BlockMacros.vars.html',
$latte->renderToString($template)
);
4 changes: 4 additions & 0 deletions tests/Latte/Filters.substring().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ require __DIR__ . '/../bootstrap.php';
$s = "\u{158}ekn\u{11B}te, jak se (dnes) m\u{E1}te?"; // Řekněte, jak se (dnes) máte?

Assert::same('', Filters::substring('', 0));
Assert::same('', Filters::substring('', -1));
Assert::same('', Filters::substring('', 1));
Assert::same('?', Filters::substring($s, -1));
Assert::same('Řekněte, jak se (dnes) máte?', Filters::substring($s, 0));
Assert::same('Řekněte, jak se (dnes) máte?', Filters::substring($s, 0, 99));
Assert::same('ekněte, jak se (dnes) máte?', Filters::substring($s, 1));
Assert::same('ě', Filters::substring($s, 4, 1));
Assert::same('ěte, jak se (d', Filters::substring($s, 4, -10));


class CountableTraversableStringClass implements Countable, IteratorAggregate
Expand Down
20 changes: 20 additions & 0 deletions tests/Latte/expected/BlockMacros.vars.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


a


a


a


a

blockmod


blockmod


block
73 changes: 73 additions & 0 deletions tests/Latte/expected/BlockMacros.vars.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
%A%
$var = 'a' /* line %d% */;
echo "\n";
if ($this->getParentName()) {
return get_defined_vars();
}
echo "\n";
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo '
';
$this->renderBlock('b', get_defined_vars()) /* line %d% */;
echo '
';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo '
';
ob_start(function () {}) /* line %d% */;
echo ' ';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo "\n";
$var = 'blockmod' /* line %d% */;
$ʟ_fi = new LR\FilterInfo('html');
echo LR\Filters::convertTo($ʟ_fi, 'html', $this->filters->filterContent('trim', $ʟ_fi, ob_get_clean()));
echo '
';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo '
';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo "\n";
$var = 'block' /* line %d% */;
echo '
';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
return get_defined_vars();
}


/** {define a} on line %d% */
public function blockA(array $ʟ_args): void
{
extract($this->params);
extract($ʟ_args);
echo ' ';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo "\n";
$var = 'define' /* line %d% */;

}


/** {block b} on line %d% */
public function blockB(array $ʟ_args): void
{
extract($this->params);
extract($ʟ_args);
echo ' ';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo "\n";
$var = 'blocknamed' /* line %d% */;

}
%A%

0 comments on commit c28492c

Please sign in to comment.