Skip to content

Commit 811a30a

Browse files
committed
added & improved tests
1 parent 2677be8 commit 811a30a

23 files changed

+355
-172
lines changed

tests/common/contentType.compatibility.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ $latte->setLoader(new Latte\Loaders\StringLoader([
293293
'context1a' => '<p>{block html|noescape}<hr> " &lt;{/block}</p>',
294294
'context1b' => '<p>{block html|upper}<hr> " &lt;{/block}</p>',
295295
'context1c' => '<p>{block html|stripHtml|upper}<hr> " &lt;{/block}</p>',
296-
'context2' => '<p title="{block html}<hr> &quot;{/block}"</p>',
296+
'context2' => '<p title="{block html}<hr> &quot;{/block}"></p>',
297297
'context2a' => '<p title="{block html|stripHtml|upper}<hr> &quot;{/block}"></p>',
298298
'context6' => '<!--{block html}<hr> &lt;{/block}-->',
299299
'context6a' => '<!--{block html|stripHtml|upper}<hr> &lt;{/block}-->',
@@ -310,7 +310,7 @@ Assert::exception(function () use ($latte) {
310310
}, Latte\RuntimeException::class, 'Filter |upper is called with incompatible content type HTML, try to prepend |stripHtml.');
311311

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

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

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

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

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

tests/tags/contentType.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ Assert::exception(function () use ($latte) {
2626
$latte->createTemplate('<div>{contentType xml}</div>');
2727
}, Latte\CompileException::class, '{contentType} is allowed only in template header.');
2828

29+
Assert::same(
30+
'<script> <p n:if=0 /> </script>',
31+
$latte->renderToString('{contentType html}<script> <p n:if=0 /> </script>')
32+
);
33+
34+
Assert::same(
35+
'<script> </script>',
36+
$latte->renderToString('{contentType xml}<script> <p n:if=0 /> </script>')
37+
);
38+
39+
Assert::same(
40+
'<p n:if=0 />',
41+
$latte->renderToString('{contentType text}<p n:if=0 />')
42+
);
43+
2944
// defined on $latte
3045
$latte = new Latte\Engine;
3146
$latte->setLoader(new Latte\Loaders\StringLoader);

tests/tags/expected/breaking.phtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
%A%
33
$iterations = 0;
4-
foreach ([1, 0] as $cond) /* line %d% */ {
4+
foreach ([1, 0] as $cond) /* line 1 */ {
55
echo ' ';
6-
echo LR\Filters::escapeHtmlText($cond) /* line %d% */;
6+
echo LR\Filters::escapeHtmlText($cond) /* line 2 */;
77
echo "\n";
8-
ob_start(function () {}) /* line %d% */;
8+
ob_start(function () {}) /* line 3 */;
99
try {
1010
echo ' before
1111
';
12-
if ($cond) /* line %d% */ continue;
12+
if ($cond) /* line 5 */ continue;
1313
echo ' after
1414
';
1515
} finally {

tests/tags/expected/define.phtml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ final class Template%a% extends Latte\Runtime\Template
1010
public function main(): array
1111
{
1212
extract($this->params);
13-
$var = 10 /* line %d% */;
13+
$var = 10 /* line 1 */;
1414
echo "\n";
1515
if ($this->getParentName()) {
1616
return get_defined_vars();
1717
}
1818
echo "\n";
19-
$this->renderBlock('test', ['var' => 20] + get_defined_vars(), 'html') /* line %d% */;
19+
$this->renderBlock('test', ['var' => 20] + get_defined_vars(), 'html') /* line 7 */;
2020
echo "\n";
21-
$this->renderBlock('true', get_defined_vars(), 'html') /* line %d% */;
21+
$this->renderBlock('true', get_defined_vars(), 'html') /* line 10 */;
2222
return get_defined_vars();
2323
}
2424

2525

26-
/** {define test} on line %d% */
26+
/** {define test} on line 3 */
2727
public function blockTest(array $ʟ_args): void
2828
{
2929
extract($this->params);
3030
extract($ʟ_args);
3131
unset($ʟ_args);
3232
echo ' This is definition #';
33-
echo LR\Filters::escapeHtmlText($var) /* line %d% */;
33+
echo LR\Filters::escapeHtmlText($var) /* line 4 */;
3434
echo "\n";
3535
}
3636

3737

38-
/** {define true} on line %d% */
38+
/** {define true} on line 9 */
3939
public function blockTrue(array $ʟ_args): void
4040
{
4141
echo 'true';

tests/tags/expected/embed.block.phtml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ final class Template%a% extends Latte\Runtime\Template
1313
{
1414
extract($this->params);
1515
echo "\n";
16-
$this->enterBlockLayer(1, get_defined_vars()) /* line %d% */;
16+
$this->enterBlockLayer(1, get_defined_vars()) /* line 2 */;
1717
if (false) {
18-
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
18+
$this->renderBlock('a', get_defined_vars()) /* line 3 */;
1919
echo "\n";
2020
}
2121
$this->copyBlockLayer();
2222
try {
23-
$this->renderBlock('embed1', [], 'html') /* line %d% */;
23+
$this->renderBlock('embed1', [], 'html') /* line 2 */;
2424
} finally {
2525
$this->leaveBlockLayer();
2626
}
@@ -31,52 +31,52 @@ final class Template%a% extends Latte\Runtime\Template
3131
}
3232

3333

34-
/** {define embed1} on line %d% */
34+
/** {define embed1} on line 10 */
3535
public function blockEmbed1(array $ʟ_args): void
3636
{
3737
extract($this->params);
3838
extract($ʟ_args);
3939
unset($ʟ_args);
4040
echo ' embed1-start
4141
';
42-
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
42+
$this->renderBlock('a', get_defined_vars()) /* line 12 */;
4343
echo '
4444
embed1-end
4545
';
4646
}
4747

4848

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

5555

56-
/** {block a} on line %d% */
56+
/** {block a} on line 3 */
5757
public function blockA1(array $ʟ_args): void
5858
{
5959
extract(end($this->varStack));
6060
extract($ʟ_args);
6161
unset($ʟ_args);
6262

63-
$this->enterBlockLayer(2, get_defined_vars()) /* line %d% */;
63+
$this->enterBlockLayer(2, get_defined_vars()) /* line 4 */;
6464
if (false) {
6565
echo ' ';
66-
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
66+
$this->renderBlock('a', get_defined_vars()) /* line 5 */;
6767
echo "\n";
6868
}
6969
$this->copyBlockLayer();
7070
try {
71-
$this->renderBlock('embed1', [], 'html') /* line %d% */;
71+
$this->renderBlock('embed1', [], 'html') /* line 4 */;
7272
} finally {
7373
$this->leaveBlockLayer();
7474
}
7575
echo "\n";
7676
}
7777

7878

79-
/** {block a} on line %d% */
79+
/** {block a} on line 5 */
8080
public function blockA2(array $ʟ_args): void
8181
{
8282
echo 'nested embeds A';

tests/tags/expected/embed.file.phtml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ final class Template%a% extends Latte\Runtime\Template
1212
{
1313
extract($this->params);
1414
echo "\n";
15-
$this->enterBlockLayer(1, get_defined_vars()) /* line %d% */;
15+
$this->enterBlockLayer(1, get_defined_vars()) /* line 2 */;
1616
if (false) {
17-
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
17+
$this->renderBlock('a', get_defined_vars()) /* line 3 */;
1818
echo "\n";
1919
}
2020
try {
21-
$this->createTemplate("embed1.latte", [], "embed")->renderToContentType('html') /* line %d% */;
21+
$this->createTemplate("embed1.latte", [], "embed")->renderToContentType('html') /* line 2 */;
2222
} finally {
2323
$this->leaveBlockLayer();
2424
}
@@ -28,29 +28,29 @@ final class Template%a% extends Latte\Runtime\Template
2828
}
2929

3030

31-
/** {block a} on line %d% */
31+
/** {block a} on line 3 */
3232
public function blockA(array $ʟ_args): void
3333
{
3434
extract(end($this->varStack));
3535
extract($ʟ_args);
3636
unset($ʟ_args);
3737

38-
$this->enterBlockLayer(2, get_defined_vars()) /* line %d% */;
38+
$this->enterBlockLayer(2, get_defined_vars()) /* line 4 */;
3939
if (false) {
4040
echo ' ';
41-
$this->renderBlock('a', get_defined_vars()) /* line %d% */;
41+
$this->renderBlock('a', get_defined_vars()) /* line 5 */;
4242
echo "\n";
4343
}
4444
try {
45-
$this->createTemplate("embed2.latte", [], "embed")->renderToContentType('html') /* line %d% */;
45+
$this->createTemplate("embed2.latte", [], "embed")->renderToContentType('html') /* line 4 */;
4646
} finally {
4747
$this->leaveBlockLayer();
4848
}
4949
echo "\n";
5050
}
5151

5252

53-
/** {block a} on line %d% */
53+
/** {block a} on line 5 */
5454
public function blockA1(array $ʟ_args): void
5555
{
5656
echo 'nested embeds A';

tests/tags/expected/first-sep-last.phtml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ final class Template%a% extends Latte\Runtime\Template
88
%A%
99
echo "\n";
1010
$iterations = 0;
11-
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
11+
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 2 */ {
1212
echo ' ';
13-
if ($iterator->isFirst()) /* line %d% */ {
13+
if ($iterator->isFirst()) /* line 3 */ {
1414
echo '(';
1515
}
1616
echo ' ';
17-
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
18-
if (!$iterator->isLast()) /* line %d% */ {
17+
echo LR\Filters::escapeHtmlText($person) /* line 3 */;
18+
if (!$iterator->isLast()) /* line 3 */ {
1919
echo ', ';
2020
}
2121
echo ' ';
22-
if ($iterator->isLast()) /* line %d% */ {
22+
if ($iterator->isLast()) /* line 3 */ {
2323
echo ')';
2424
}
2525
echo "\n";
@@ -30,24 +30,24 @@ final class Template%a% extends Latte\Runtime\Template
3030
3131
';
3232
$iterations = 0;
33-
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
33+
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 7 */ {
3434
echo ' ';
35-
if ($iterator->isFirst()) /* line %d% */ {
35+
if ($iterator->isFirst()) /* line 8 */ {
3636
echo '(';
37-
} else /* line %d% */ {
37+
} else /* line 8 */ {
3838
echo '[';
3939
}
4040
echo ' ';
41-
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
42-
if (!$iterator->isLast()) /* line %d% */ {
41+
echo LR\Filters::escapeHtmlText($person) /* line 8 */;
42+
if (!$iterator->isLast()) /* line 8 */ {
4343
echo ', ';
44-
} else /* line %d% */ {
44+
} else /* line 8 */ {
4545
echo ';';
4646
}
4747
echo ' ';
48-
if ($iterator->isLast()) /* line %d% */ {
48+
if ($iterator->isLast()) /* line 8 */ {
4949
echo ')';
50-
} else /* line %d% */ {
50+
} else /* line 8 */ {
5151
echo ']';
5252
}
5353
echo "\n";
@@ -58,18 +58,18 @@ final class Template%a% extends Latte\Runtime\Template
5858
5959
';
6060
$iterations = 0;
61-
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
61+
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 12 */ {
6262
echo ' ';
63-
if ($iterator->isFirst(2)) /* line %d% */ {
63+
if ($iterator->isFirst(2)) /* line 13 */ {
6464
echo '(';
6565
}
6666
echo ' ';
67-
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
68-
if (!$iterator->isLast(2)) /* line %d% */ {
67+
echo LR\Filters::escapeHtmlText($person) /* line 13 */;
68+
if (!$iterator->isLast(2)) /* line 13 */ {
6969
echo ', ';
7070
}
7171
echo ' ';
72-
if ($iterator->isLast(2)) /* line %d% */ {
72+
if ($iterator->isLast(2)) /* line 13 */ {
7373
echo ')';
7474
}
7575
echo "\n";
@@ -80,18 +80,18 @@ final class Template%a% extends Latte\Runtime\Template
8080
8181
';
8282
$iterations = 0;
83-
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
83+
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 17 */ {
8484
echo ' ';
85-
if ($iterator->isFirst(1)) /* line %d% */ {
85+
if ($iterator->isFirst(1)) /* line 18 */ {
8686
echo '(';
8787
}
8888
echo ' ';
89-
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
90-
if (!$iterator->isLast(1)) /* line %d% */ {
89+
echo LR\Filters::escapeHtmlText($person) /* line 18 */;
90+
if (!$iterator->isLast(1)) /* line 18 */ {
9191
echo ', ';
9292
}
9393
echo ' ';
94-
if ($iterator->isLast(1)) /* line %d% */ {
94+
if ($iterator->isLast(1)) /* line 18 */ {
9595
echo ')';
9696
}
9797
echo "\n";
@@ -102,17 +102,17 @@ final class Template%a% extends Latte\Runtime\Template
102102
103103
';
104104
$iterations = 0;
105-
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line %d% */ {
106-
if ($iterator->isFirst(0)) /* line %d% */ {
105+
foreach ($iterator = $ʟ_it = new LR\CachingIterator($people, $ʟ_it ?? null) as $person) /* line 22 */ {
106+
if ($iterator->isFirst(0)) /* line 23 */ {
107107
echo ' <span>(</span>';
108108
}
109109
echo ' ';
110-
echo LR\Filters::escapeHtmlText($person) /* line %d% */;
111-
if (!$iterator->isLast()) /* line %d% */ {
110+
echo LR\Filters::escapeHtmlText($person) /* line 23 */;
111+
if (!$iterator->isLast()) /* line 23 */ {
112112
echo '<span>, </span>';
113113
}
114114
echo ' ';
115-
if ($iterator->isLast()) /* line %d% */ {
115+
if ($iterator->isLast()) /* line 23 */ {
116116
echo '<span>)</span>
117117
';
118118
}

0 commit comments

Comments
 (0)