Skip to content

Commit

Permalink
added & improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 18, 2022
1 parent 2677be8 commit 811a30a
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 172 deletions.
12 changes: 6 additions & 6 deletions tests/common/contentType.compatibility.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ $latte->setLoader(new Latte\Loaders\StringLoader([
'context1a' => '<p>{block html|noescape}<hr> " &lt;{/block}</p>',
'context1b' => '<p>{block html|upper}<hr> " &lt;{/block}</p>',
'context1c' => '<p>{block html|stripHtml|upper}<hr> " &lt;{/block}</p>',
'context2' => '<p title="{block html}<hr> &quot;{/block}"</p>',
'context2' => '<p title="{block html}<hr> &quot;{/block}"></p>',
'context2a' => '<p title="{block html|stripHtml|upper}<hr> &quot;{/block}"></p>',
'context6' => '<!--{block html}<hr> &lt;{/block}-->',
'context6a' => '<!--{block html|stripHtml|upper}<hr> &lt;{/block}-->',
Expand All @@ -310,7 +310,7 @@ Assert::exception(function () use ($latte) {
}, Latte\RuntimeException::class, 'Filter |upper is called with incompatible content type HTML, try to prepend |stripHtml.');

Assert::same('<p> " &lt;</p>', $latte->renderToString('context1c'));
Assert::same('<p title="&lt;hr&gt; &quot;"</p>', $latte->renderToString('context2'));
Assert::same('<p title="&lt;hr&gt; &quot;"></p>', $latte->renderToString('context2'));
Assert::same('<p title=" &quot;"></p>', $latte->renderToString('context2a'));
Assert::same('<!--<hr> &lt;-->', $latte->renderToString('context6'));

Expand All @@ -326,7 +326,7 @@ $latte->setLoader(new Latte\Loaders\StringLoader([
'context1a' => '<p>{var $n=html}{block $n|noescape}<hr> " &lt;{/block}</p>',
'context1b' => '<p>{var $n=html}{block $n|upper}<hr> " &lt;{/block}</p>',
'context1c' => '<p>{var $n=html}{block $n|stripHtml|upper}<hr> " &lt;{/block}</p>',
'context2' => '<p title="{var $n=html}{block $n}<hr> &quot;{/block}"</p>',
'context2' => '<p title="{var $n=html}{block $n}<hr> &quot;{/block}"></p>',
'context2a' => '<p title="{var $n=html}{block $n|stripHtml|upper}<hr> &quot;{/block}"></p>',
'context6' => '<!--{var $n=html}{block $n}<hr> &lt;{/block}-->',
'context6a' => '<!--{var $n=html}{block $n|stripHtml|upper}<hr> &lt;{/block}-->',
Expand All @@ -343,7 +343,7 @@ Assert::exception(function () use ($latte) {
}, Latte\RuntimeException::class, 'Filter |upper is called with incompatible content type HTML, try to prepend |stripHtml.');

Assert::same('<p> " &lt;</p>', $latte->renderToString('context1c'));
Assert::same('<p title="&lt;hr&gt; &quot;"</p>', $latte->renderToString('context2'));
Assert::same('<p title="&lt;hr&gt; &quot;"></p>', $latte->renderToString('context2'));
Assert::same('<p title=" &quot;"></p>', $latte->renderToString('context2a'));
Assert::same('<!--<hr> &lt;-->', $latte->renderToString('context6'));

Expand All @@ -359,7 +359,7 @@ $latte->setLoader(new Latte\Loaders\StringLoader([
'context1a' => '<p>{block|noescape}<hr> " &lt;{/block}</p>',
'context1b' => '<p>{block|upper}<hr> " &lt;{/block}</p>',
'context1c' => '<p>{block|stripHtml|upper}<hr> " &lt;{/block}</p>',
'context2' => '<p title="{block}<hr> &quot;{/block}"</p>',
'context2' => '<p title="{block}<hr> &quot;{/block}"></p>',
'context2a' => '<p title="{block|stripHtml|upper}<hr> &quot;{/block}"></p>',
'context6' => '<!--{block}<hr> &lt;{/block}-->',
'context6a' => '<!--{block|stripHtml|upper}<hr> &lt;{/block}-->',
Expand All @@ -376,7 +376,7 @@ Assert::exception(function () use ($latte) {
}, Latte\RuntimeException::class, 'Filter |upper is called with incompatible content type HTML, try to prepend |stripHtml.');

Assert::same('<p> " &lt;</p>', $latte->renderToString('context1c'));
Assert::same('<p title="<hr> &quot;"</p>', $latte->renderToString('context2'));
Assert::same('<p title="<hr> &quot;"></p>', $latte->renderToString('context2'));
Assert::same('<p title=" &quot;"></p>', $latte->renderToString('context2a'));
Assert::same('<!--<hr> &lt;-->', $latte->renderToString('context6'));

Expand Down
15 changes: 15 additions & 0 deletions tests/tags/contentType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ Assert::exception(function () use ($latte) {
$latte->createTemplate('<div>{contentType xml}</div>');
}, Latte\CompileException::class, '{contentType} is allowed only in template header.');

Assert::same(
'<script> <p n:if=0 /> </script>',
$latte->renderToString('{contentType html}<script> <p n:if=0 /> </script>')
);

Assert::same(
'<script> </script>',
$latte->renderToString('{contentType xml}<script> <p n:if=0 /> </script>')
);

Assert::same(
'<p n:if=0 />',
$latte->renderToString('{contentType text}<p n:if=0 />')
);

// defined on $latte
$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
Expand Down
8 changes: 4 additions & 4 deletions tests/tags/expected/breaking.phtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
%A%
$iterations = 0;
foreach ([1, 0] as $cond) /* line %d% */ {
foreach ([1, 0] as $cond) /* line 1 */ {
echo ' ';
echo LR\Filters::escapeHtmlText($cond) /* line %d% */;
echo LR\Filters::escapeHtmlText($cond) /* line 2 */;
echo "\n";
ob_start(function () {}) /* line %d% */;
ob_start(function () {}) /* line 3 */;
try {
echo ' before
';
if ($cond) /* line %d% */ continue;
if ($cond) /* line 5 */ continue;
echo ' after
';
} finally {
Expand Down
12 changes: 6 additions & 6 deletions tests/tags/expected/define.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ final class Template%a% extends Latte\Runtime\Template
public function main(): array
{
extract($this->params);
$var = 10 /* line %d% */;
$var = 10 /* line 1 */;
echo "\n";
if ($this->getParentName()) {
return get_defined_vars();
}
echo "\n";
$this->renderBlock('test', ['var' => 20] + get_defined_vars(), 'html') /* line %d% */;
$this->renderBlock('test', ['var' => 20] + get_defined_vars(), 'html') /* line 7 */;
echo "\n";
$this->renderBlock('true', get_defined_vars(), 'html') /* line %d% */;
$this->renderBlock('true', get_defined_vars(), 'html') /* line 10 */;
return get_defined_vars();
}


/** {define test} on line %d% */
/** {define test} on line 3 */
public function blockTest(array $ʟ_args): void
{
extract($this->params);
extract($ʟ_args);
unset($ʟ_args);
echo ' This is definition #';
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
echo LR\Filters::escapeHtmlText($var) /* line 4 */;
echo "\n";
}


/** {define true} on line %d% */
/** {define true} on line 9 */
public function blockTrue(array $ʟ_args): void
{
echo 'true';
Expand Down
22 changes: 11 additions & 11 deletions tests/tags/expected/embed.block.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ final class Template%a% extends Latte\Runtime\Template
{
extract($this->params);
echo "\n";
$this->enterBlockLayer(1, get_defined_vars()) /* line %d% */;
$this->enterBlockLayer(1, get_defined_vars()) /* line 2 */;
if (false) {
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
$this->renderBlock('a', get_defined_vars()) /* line 3 */;
echo "\n";
}
$this->copyBlockLayer();
try {
$this->renderBlock('embed1', [], 'html') /* line %d% */;
$this->renderBlock('embed1', [], 'html') /* line 2 */;
} finally {
$this->leaveBlockLayer();
}
Expand All @@ -31,52 +31,52 @@ final class Template%a% extends Latte\Runtime\Template
}


/** {define embed1} on line %d% */
/** {define embed1} on line 10 */
public function blockEmbed1(array $ʟ_args): void
{
extract($this->params);
extract($ʟ_args);
unset($ʟ_args);
echo ' embed1-start
';
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
$this->renderBlock('a', get_defined_vars()) /* line 12 */;
echo '
embed1-end
';
}


/** {block a} on line %d% */
/** {block a} on line 12 */
public function blockA(array $ʟ_args): void
{
echo 'embed1-A';
}


/** {block a} on line %d% */
/** {block a} on line 3 */
public function blockA1(array $ʟ_args): void
{
extract(end($this->varStack));
extract($ʟ_args);
unset($ʟ_args);

$this->enterBlockLayer(2, get_defined_vars()) /* line %d% */;
$this->enterBlockLayer(2, get_defined_vars()) /* line 4 */;
if (false) {
echo ' ';
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
$this->renderBlock('a', get_defined_vars()) /* line 5 */;
echo "\n";
}
$this->copyBlockLayer();
try {
$this->renderBlock('embed1', [], 'html') /* line %d% */;
$this->renderBlock('embed1', [], 'html') /* line 4 */;
} finally {
$this->leaveBlockLayer();
}
echo "\n";
}


/** {block a} on line %d% */
/** {block a} on line 5 */
public function blockA2(array $ʟ_args): void
{
echo 'nested embeds A';
Expand Down
16 changes: 8 additions & 8 deletions tests/tags/expected/embed.file.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ final class Template%a% extends Latte\Runtime\Template
{
extract($this->params);
echo "\n";
$this->enterBlockLayer(1, get_defined_vars()) /* line %d% */;
$this->enterBlockLayer(1, get_defined_vars()) /* line 2 */;
if (false) {
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
$this->renderBlock('a', get_defined_vars()) /* line 3 */;
echo "\n";
}
try {
$this->createTemplate("embed1.latte", [], "embed")->renderToContentType('html') /* line %d% */;
$this->createTemplate("embed1.latte", [], "embed")->renderToContentType('html') /* line 2 */;
} finally {
$this->leaveBlockLayer();
}
Expand All @@ -28,29 +28,29 @@ final class Template%a% extends Latte\Runtime\Template
}


/** {block a} on line %d% */
/** {block a} on line 3 */
public function blockA(array $ʟ_args): void
{
extract(end($this->varStack));
extract($ʟ_args);
unset($ʟ_args);

$this->enterBlockLayer(2, get_defined_vars()) /* line %d% */;
$this->enterBlockLayer(2, get_defined_vars()) /* line 4 */;
if (false) {
echo ' ';
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
$this->renderBlock('a', get_defined_vars()) /* line 5 */;
echo "\n";
}
try {
$this->createTemplate("embed2.latte", [], "embed")->renderToContentType('html') /* line %d% */;
$this->createTemplate("embed2.latte", [], "embed")->renderToContentType('html') /* line 4 */;
} finally {
$this->leaveBlockLayer();
}
echo "\n";
}


/** {block a} on line %d% */
/** {block a} on line 5 */
public function blockA1(array $ʟ_args): void
{
echo 'nested embeds A';
Expand Down
56 changes: 28 additions & 28 deletions tests/tags/expected/first-sep-last.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ final class Template%a% extends Latte\Runtime\Template
%A%
echo "\n";
$iterations = 0;
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 2 */ {
echo ' ';
if ($iterator->isFirst()) /* line %d% */ {
if ($iterator->isFirst()) /* line 3 */ {
echo '(';
}
echo ' ';
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
if (!$iterator->isLast()) /* line %d% */ {
echo LR\Filters::escapeHtmlText($person) /* line 3 */;
if (!$iterator->isLast()) /* line 3 */ {
echo ', ';
}
echo ' ';
if ($iterator->isLast()) /* line %d% */ {
if ($iterator->isLast()) /* line 3 */ {
echo ')';
}
echo "\n";
Expand All @@ -30,24 +30,24 @@ final class Template%a% extends Latte\Runtime\Template
';
$iterations = 0;
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 7 */ {
echo ' ';
if ($iterator->isFirst()) /* line %d% */ {
if ($iterator->isFirst()) /* line 8 */ {
echo '(';
} else /* line %d% */ {
} else /* line 8 */ {
echo '[';
}
echo ' ';
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
if (!$iterator->isLast()) /* line %d% */ {
echo LR\Filters::escapeHtmlText($person) /* line 8 */;
if (!$iterator->isLast()) /* line 8 */ {
echo ', ';
} else /* line %d% */ {
} else /* line 8 */ {
echo ';';
}
echo ' ';
if ($iterator->isLast()) /* line %d% */ {
if ($iterator->isLast()) /* line 8 */ {
echo ')';
} else /* line %d% */ {
} else /* line 8 */ {
echo ']';
}
echo "\n";
Expand All @@ -58,18 +58,18 @@ final class Template%a% extends Latte\Runtime\Template
';
$iterations = 0;
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 12 */ {
echo ' ';
if ($iterator->isFirst(2)) /* line %d% */ {
if ($iterator->isFirst(2)) /* line 13 */ {
echo '(';
}
echo ' ';
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
if (!$iterator->isLast(2)) /* line %d% */ {
echo LR\Filters::escapeHtmlText($person) /* line 13 */;
if (!$iterator->isLast(2)) /* line 13 */ {
echo ', ';
}
echo ' ';
if ($iterator->isLast(2)) /* line %d% */ {
if ($iterator->isLast(2)) /* line 13 */ {
echo ')';
}
echo "\n";
Expand All @@ -80,18 +80,18 @@ final class Template%a% extends Latte\Runtime\Template
';
$iterations = 0;
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 17 */ {
echo ' ';
if ($iterator->isFirst(1)) /* line %d% */ {
if ($iterator->isFirst(1)) /* line 18 */ {
echo '(';
}
echo ' ';
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
if (!$iterator->isLast(1)) /* line %d% */ {
echo LR\Filters::escapeHtmlText($person) /* line 18 */;
if (!$iterator->isLast(1)) /* line 18 */ {
echo ', ';
}
echo ' ';
if ($iterator->isLast(1)) /* line %d% */ {
if ($iterator->isLast(1)) /* line 18 */ {
echo ')';
}
echo "\n";
Expand All @@ -102,17 +102,17 @@ final class Template%a% extends Latte\Runtime\Template
';
$iterations = 0;
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
if ($iterator->isFirst(0)) /* line %d% */ {
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 22 */ {
if ($iterator->isFirst(0)) /* line 23 */ {
echo ' <span>(</span>';
}
echo ' ';
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
if (!$iterator->isLast()) /* line %d% */ {
echo LR\Filters::escapeHtmlText($person) /* line 23 */;
if (!$iterator->isLast()) /* line 23 */ {
echo '<span>, </span>';
}
echo ' ';
if ($iterator->isLast()) /* line %d% */ {
if ($iterator->isLast()) /* line 23 */ {
echo '<span>)</span>
';
}
Expand Down
Loading

0 comments on commit 811a30a

Please sign in to comment.