8000 added tests · nette/latte@11d9cbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 11d9cbf

Browse files
committed
added tests
1 parent 2677be8 commit 11d9cbf

File tree

5 files changed

+184
-1
lines changed

5 files changed

+184
-1
lines changed

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/n-class.phtml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
%A%
2+
foreach ($iterator = $ʟ_it = new LR\CachingIterator([1,2,3], $ʟ_it ?? null) as $foo) /* line %d% */ {
3+
echo ' <b';
4+
echo ($ʟ_tmp = array_filter([$iterator->even ? 'even' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */;
5+
echo '>item</b>
6+
';
7+
$iterations++;
8+
}
9+
$iterator = $ʟ_it = $ʟ_it->getParent();
10+
echo "\n";
11+
$iterations = 0;
12+
foreach ($iterator = $ʟ_it = new LR\CachingIterator([1, 2, 3], $ʟ_it ?? null) as $foo) /* line %d% */ {
13+
echo '<p';
14+
echo ($ʟ_tmp = array_filter([$iterator->even ? 'even' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */;
15+
echo '>';
16+
echo LR\Filters::escapeHtmlText($foo) /* line %d% */;
17+
echo '</p>
18+
';
19+
$iterations++;
20+
}
21+
$iterator = $ʟ_it = $ʟ_it->getParent();
22+
echo '
23+
<p';
24+
echo ($ʟ_tmp = array_filter(['foo', (false ? 'first' : null), 'odd', (true ? 'foo' : 'bar')])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */;
25+
echo '>n:class</p>
26+
27+
<p';
28+
echo ($ʟ_tmp = array_filter([false ? 'first' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */;
29+
echo '>n:class empty</p>
30+
31+
<p';
32+
echo ($ʟ_tmp = array_filter([true ? 'bem--modifier' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */;
33+
echo '>n:class with BEM</p>
34+
';
35+
%A%

tests/tags/n-attr.phpt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/**
4+
* n:attr
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Tester\Assert;
10+
11+
12+
require __DIR__ . '/../bootstrap.php';
13+
14+
15+
$latte = new Latte\Engine;
16+
$latte->setLoader(new Latte\Loaders\StringLoader);
17+
18+
$template = <<<'EOD'
19+
20+
<p n:attr="title => hello, lang => isset($lang) ? $lang"> </p>
21+
22+
<p n:attr="[title => hello]"> </p>
23+
24+
EOD;
25+
26+
Assert::match(
27+
<<<'XX'
28+
%A%
29+
echo '
30+
<p';
31+
$ʟ_tmp = ['title' => 'hello', 'lang' => isset($lang) ? $lang : null];
32+
echo LR\Filters::htmlAttributes(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp) /* line 2 */;
33+
echo '> </p>
34+
35+
<p';
36+
$ʟ_tmp = [['title' => 'hello']];
37+
echo LR\Filters::htmlAttributes(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp) /* line 4 */;
38+
echo '> </p>
39+
';
40+
%A%
41+
XX
42+
,
43+
$latte->compile($template)
44+
);
45+
46+
Assert::match(
47+
<<<'XX'
48+
49+
<p title="hello"> </p>
50+
51+
<p title="hello"> </p>
52+
XX
53+
,
54+
$latte->renderToString($template)
55+
);
56+
57+
58+
Assert::exception(function () use ($latte) {
59+
$latte->compile('<div n:attr/>');
60+
}, Latte\CompileException::class, 'Missing arguments in n:attr');
61+
62+
63+
Assert::exception(function () use ($latte) {
64+
$latte->compile('<div n:inner-attr/>');
65+
}, Latte\CompileException::class, 'Unknown attribute n:inner-attr');

tests/tags/n-class.phpt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/**
4+
* n:class
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Tester\Assert;
10+
11+
12+
require __DIR__ . '/../bootstrap.php';
13+
14+
15+
$latte = new Latte\Engine;
16+
$latte->setLoader(new Latte\Loaders\StringLoader);
17+
18+
$template = <<<'EOD'
19+
20+
{foreach [1,2,3] as $foo}
21+
<b n:class="$iterator->even ? even">item</b>
22+
{/foreach}
23+
24+
<p n:foreach="[1, 2, 3] as $foo" n:class="$iterator->even ? even">{$foo}</p>
25+
26+
<p n:class="foo, (false ? first), odd, (true ? foo : bar)">n:class</p>
27+
28+
<p n:class="false ? first">n:class empty</p>
29+
30+
<p n:class="true ? bem--modifier">n:class with BEM</p>
31+
32+
EOD;
33+
34+
Assert::matchFile(
35+
__DIR__ . '/expected/n-class.phtml',
36+
$latte->compile($template)
37+
);
38+
39+
Assert::match(
40+
<<<'XX'
41+
42+
<b>item</b>
43+
<b class="even">item</b>
44+
<b>item</b>
45+
46+
<p>1</p>
47+
<p class="even">2</p>
48+
<p>3</p>
49+
50+
<p class="foo odd">n:class</p>
51+
52+
<p>n:class empty</p>
53+
54+
<p class="bem--modifier">n:class with BEM</p>
55+
XX
56+
,
57+
$latte->renderToString($template)
58+
);
59+
60+
61+
Assert::exception(function () use ($latte) {
62+
$latte->compile('<div n:class/>');
63+
}, Latte\CompileException::class, 'Missing arguments in n:class');
64+
65+
66+
Assert::exception(function () use ($latte) {
67+
$latte->compile('<div n:inner-class/>');
68+
}, Latte\CompileException::class, 'Unknown attribute n:inner-class');

tests/tags/n-tag.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Test: Latte\Engine and n:tag.
4+
* n:tag
55
*/
66

77
declare(strict_types=1);

0 commit comments

Comments
 (0)
0