From 11d9cbf5a827ffac4145e2fa540f847ce4126bf6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 1 Feb 2022 02:40:16 +0100 Subject: [PATCH] added tests --- tests/tags/contentType.phpt | 15 +++++++ tests/tags/expected/n-class.phtml | 35 ++++++++++++++++ tests/tags/n-attr.phpt | 65 +++++++++++++++++++++++++++++ tests/tags/n-class.phpt | 68 +++++++++++++++++++++++++++++++ tests/tags/n-tag.phpt | 2 +- 5 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 tests/tags/expected/n-class.phtml create mode 100644 tests/tags/n-attr.phpt create mode 100644 tests/tags/n-class.phpt diff --git a/tests/tags/contentType.phpt b/tests/tags/contentType.phpt index ea1ee1e97..9d47f07cf 100644 --- a/tests/tags/contentType.phpt +++ b/tests/tags/contentType.phpt @@ -26,6 +26,21 @@ Assert::exception(function () use ($latte) { $latte->createTemplate('
{contentType xml}
'); }, Latte\CompileException::class, '{contentType} is allowed only in template header.'); +Assert::same( + '', + $latte->renderToString('{contentType html}') +); + +Assert::same( + '', + $latte->renderToString('{contentType xml}') +); + +Assert::same( + '

', + $latte->renderToString('{contentType text}

') +); + // defined on $latte $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/tags/expected/n-class.phtml b/tests/tags/expected/n-class.phtml new file mode 100644 index 000000000..35a3d746f --- /dev/null +++ b/tests/tags/expected/n-class.phtml @@ -0,0 +1,35 @@ +%A% + foreach ($iterator = $ʟ_it = new LR\CachingIterator([1,2,3], $ʟ_it ?? null) as $foo) /* line %d% */ { + echo ' even ? 'even' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; + echo '>item +'; + $iterations++; + } + $iterator = $ʟ_it = $ʟ_it->getParent(); + echo "\n"; + $iterations = 0; + foreach ($iterator = $ʟ_it = new LR\CachingIterator([1, 2, 3], $ʟ_it ?? null) as $foo) /* line %d% */ { + echo 'even ? 'even' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; + echo '>'; + echo LR\Filters::escapeHtmlText($foo) /* line %d% */; + echo '

+'; + $iterations++; + } + $iterator = $ʟ_it = $ʟ_it->getParent(); + echo ' +n:class

+ +n:class empty

+ +n:class with BEM

+'; +%A% diff --git a/tests/tags/n-attr.phpt b/tests/tags/n-attr.phpt new file mode 100644 index 000000000..acd8d803d --- /dev/null +++ b/tests/tags/n-attr.phpt @@ -0,0 +1,65 @@ +setLoader(new Latte\Loaders\StringLoader); + +$template = <<<'EOD' + +

+ +

+ +EOD; + +Assert::match( + <<<'XX' +%A% + echo ' + 'hello', 'lang' => isset($lang) ? $lang : null]; + echo LR\Filters::htmlAttributes(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp) /* line 2 */; + echo '>

+ + 'hello']]; + echo LR\Filters::htmlAttributes(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp) /* line 4 */; + echo '>

+'; +%A% +XX +, + $latte->compile($template) +); + +Assert::match( + <<<'XX' + +

+ +

+XX +, + $latte->renderToString($template) +); + + +Assert::exception(function () use ($latte) { + $latte->compile('
'); +}, Latte\CompileException::class, 'Missing arguments in n:attr'); + + +Assert::exception(function () use ($latte) { + $latte->compile('
'); +}, Latte\CompileException::class, 'Unknown attribute n:inner-attr'); diff --git a/tests/tags/n-class.phpt b/tests/tags/n-class.phpt new file mode 100644 index 000000000..e9fe7a031 --- /dev/null +++ b/tests/tags/n-class.phpt @@ -0,0 +1,68 @@ +setLoader(new Latte\Loaders\StringLoader); + +$template = <<<'EOD' + +{foreach [1,2,3] as $foo} + item +{/foreach} + +

{$foo}

+ +

n:class

+ +

n:class empty

+ +

n:class with BEM

+ +EOD; + +Assert::matchFile( + __DIR__ . '/expected/n-class.phtml', + $latte->compile($template) +); + +Assert::match( + <<<'XX' + + item + item + item + +

1

+

2

+

3

+ +

n:class

+ +

n:class empty

+ +

n:class with BEM

+XX +, + $latte->renderToString($template) +); + + +Assert::exception(function () use ($latte) { + $latte->compile('
'); +}, Latte\CompileException::class, 'Missing arguments in n:class'); + + +Assert::exception(function () use ($latte) { + $latte->compile('
'); +}, Latte\CompileException::class, 'Unknown attribute n:inner-class'); diff --git a/tests/tags/n-tag.phpt b/tests/tags/n-tag.phpt index a675ff26a..37f095645 100644 --- a/tests/tags/n-tag.phpt +++ b/tests/tags/n-tag.phpt @@ -1,7 +1,7 @@