Skip to content

Commit c025df0

Browse files
committed
test: improved Latte tests
1 parent a86bb1f commit c025df0

File tree

4 files changed

+129
-36
lines changed

4 files changed

+129
-36
lines changed

tests/Bridges.Latte/UIMacros.control.phpt

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,78 @@ declare(strict_types=1);
99
use Nette\Bridges\ApplicationLatte\UIMacros;
1010
use Tester\Assert;
1111

12-
1312
require __DIR__ . '/../bootstrap.php';
1413

1514

16-
$compiler = new Latte\Compiler;
17-
UIMacros::install($compiler);
15+
$latte = new Latte\Engine;
16+
$latte->setLoader(new Latte\Loaders\StringLoader);
17+
UIMacros::install($latte->getCompiler());
1818

1919
// {control ...}
20-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); ?>', $compiler->expandMacro('control', 'form', '')->openingCode);
21-
@Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); $ʟ_fi = new LR\FilterInfo(\'html\'); echo $this->filters->filterContent(\'filter\', $ʟ_fi, ob_get_clean()); ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode); // @deprecated
22-
Assert::match('<?php %a% if (is_object($form)) %a% else %a% $this->global->uiControl->getComponent($form); %a%->render(); ?>', $compiler->expandMacro('control', '$form', '')->openingCode);
23-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType(); ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode);
24-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->{"render$type"}(); ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode);
25-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType(\'param\'); ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode);
26-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(array_merge([], $params, [])); ?>', $compiler->expandMacro('control', 'form (expand) $params', '')->openingCode);
27-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType([\'param\' => 123]); ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode);
28-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType([\'param\' => 123]); ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode);
29-
@Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); $ʟ_fi = new LR\FilterInfo(\'html\'); echo $this->filters->filterContent(\'striptags\', $ʟ_fi, ob_get_clean()); ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode); // @ deprecated
30-
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType(param: 123); ?>', $compiler->expandMacro('control', 'form:type, param: 123', '')->openingCode);
20+
Assert::match(
21+
'%A% $this->global->uiControl->getComponent("form");%A%->render();%A%',
22+
$latte->compile('{control form}')
23+
);
24+
25+
@Assert::match(
26+
<<<'XX'
27+
%A%
28+
/* line 1 */ $_tmp = $this->global->uiControl->getComponent("form");
29+
if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false);
30+
ob_start(function () {});
31+
$_tmp->render();
32+
$ʟ_fi = new LR\FilterInfo('html');
33+
echo $this->filters->filterContent('filter', $ʟ_fi, ob_get_clean());
34+
%A%
35+
XX
36+
,
37+
$latte->compile('{control form|filter}')
38+
); // @deprecated
39+
40+
Assert::match(
41+
<<<'XX'
42+
%A%
43+
/* line 1 */ if (is_object($form)) $_tmp = $form;
44+
else $_tmp = $this->global->uiControl->getComponent($form);
45+
if ($_tmp instanceof Nette\Application\UI\Renderable) $_tmp->redrawControl(null, false);
46+
$_tmp->render();
47+
%A%
48+
XX
49+
,
50+
$latte->compile('{control $form}')
51+
);
52+
53+
Assert::match(
54+
'%A% $this->global->uiControl->getComponent("form");%A%->renderType();%A%',
55+
$latte->compile('{control form:type}')
56+
);
57+
58+
Assert::match(
59+
'%A% $this->global->uiControl->getComponent("form");%A%->{"render$type"}();%A%',
60+
$latte->compile('{control form:$type}')
61+
);
62+
63+
Assert::match(
64+
'%A% $this->global->uiControl->getComponent("form");%A%->renderType(\'param\');%A%',
65+
$latte->compile('{control form:type param}')
66+
);
67+
68+
Assert::match(
69+
'%A% $this->global->uiControl->getComponent("form");%A%->render(array_merge([], $params, []));%A%',
70+
$latte->compile('{control form (expand) $params}')
71+
);
72+
73+
Assert::match(
74+
'%A% $this->global->uiControl->getComponent("form");%A%->renderType([\'param\' => 123]);%A%',
75+
$latte->compile('{control form:type param => 123}')
76+
);
77+
78+
Assert::match(
79+
'%A% $this->global->uiControl->getComponent("form");%A%->renderType([\'param\' => 123]);%A%',
80+
$latte->compile('{control form:type, param => 123}')
81+
);
82+
83+
Assert::match(
84+
'%A% $this->global->uiControl->getComponent("form");%A%->renderType(param: 123);%A%',
85+
$latte->compile('{control form:type, param: 123}')
86+
);

tests/Bridges.Latte/UIMacros.isLinkCurrent.phpt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ $factory->createTemplate($presenter);
2929

3030
$latte->setLoader(new Latte\Loaders\StringLoader);
3131

32-
Assert::matchFile(__DIR__ . '/expected/UIMacros.isLinkCurrent.phtml', $latte->compile(
33-
'<a n:href="default" n:class="$presenter->isLinkCurrent() ? current">n:href before n:class</a>
32+
Assert::matchFile(
33+
__DIR__ . '/expected/UIMacros.isLinkCurrent.phtml',
34+
$latte->compile(
35+
<<<'XX'
36+
<a n:href="default" n:class="$presenter->isLinkCurrent() ? current">n:href before n:class</a>
3437
3538
<a n:class="$presenter->isLinkCurrent() ? current" n:href="default">n:href after n:class</a>
3639
@@ -43,5 +46,7 @@ Assert::matchFile(__DIR__ . '/expected/UIMacros.isLinkCurrent.phtml', $latte->co
4346
{ifCurrent default}default{/ifCurrent}
4447
4548
<a n:class="isLinkCurrent(default) ? current" n:href="default">custom function</a>
46-
'
47-
));
49+
50+
XX
51+
)
52+
);

tests/Bridges.Latte/UIMacros.link.phpt

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,56 @@ declare(strict_types=1);
99
use Nette\Bridges\ApplicationLatte\UIMacros;
1010
use Tester\Assert;
1111

12-
1312
require __DIR__ . '/../bootstrap.php';
1413

1514

16-
$compiler = new Latte\Compiler;
17-
$compiler->setContentType($compiler::CONTENT_TEXT);
18-
UIMacros::install($compiler);
15+
$latte = new Latte\Engine;
16+
$latte->setLoader(new Latte\Loaders\StringLoader);
17+
UIMacros::install($latte->getCompiler());
1918

2019
// {link ...}
21-
Assert::same('<?php echo $this->global->uiControl->link("p"); ?>', $compiler->expandMacro('link', 'p', '')->openingCode);
22-
Assert::same('<?php echo ($this->filters->filter)($this->global->uiControl->link("p")); ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode);
23-
Assert::same('<?php echo $this->global->uiControl->link("p:a"); ?>', $compiler->expandMacro('link', 'p:a', '')->openingCode);
24-
Assert::same('<?php echo $this->global->uiControl->link($dest); ?>', $compiler->expandMacro('link', '$dest', '')->openingCode);
25-
Assert::same('<?php echo $this->global->uiControl->link($p:$a); ?>', $compiler->expandMacro('link', '$p:$a', '')->openingCode);
26-
Assert::same('<?php echo $this->global->uiControl->link("$p:$a"); ?>', $compiler->expandMacro('link', '"$p:$a"', '')->openingCode);
27-
Assert::same('<?php echo $this->global->uiControl->link("p:a"); ?>', $compiler->expandMacro('link', '"p:a"', '')->openingCode);
28-
Assert::same('<?php echo $this->global->uiControl->link(\'p:a\'); ?>', $compiler->expandMacro('link', "'p:a'", '')->openingCode);
29-
30-
Assert::same('<?php echo $this->global->uiControl->link("p", [\'param\']); ?>', $compiler->expandMacro('link', 'p param', '')->openingCode);
31-
Assert::same('<?php echo $this->global->uiControl->link("p", [\'param\' => 123]); ?>', $compiler->expandMacro('link', 'p param => 123', '')->openingCode);
32-
Assert::same('<?php echo $this->global->uiControl->link("p", [\'param\' => 123]); ?>', $compiler->expandMacro('link', 'p, param => 123', '')->openingCode);
20+
Assert::contains(
21+
'$this->global->uiControl->link("p")',
22+
$latte->compile('{link p}')
23+
);
24+
Assert::contains(
25+
'($this->filters->filter)($this->global->uiControl->link("p"))',
26+
$latte->compile('{link p|filter}')
27+
);
28+
Assert::contains(
29+
'$this->global->uiControl->link("p:a")',
30+
$latte->compile('{link p:a}')
31+
);
32+
Assert::contains(
33+
'$this->global->uiControl->link($dest)',
34+
$latte->compile('{link $dest}')
35+
);
36+
Assert::contains(
37+
'$this->global->uiControl->link($p:$a)',
38+
$latte->compile('{link $p:$a}')
39+
);
40+
Assert::contains(
41+
'$this->global->uiControl->link("$p:$a")',
42+
$latte->compile('{link "$p:$a"}')
43+
);
44+
Assert::contains(
45+
'$this->global->uiControl->link("p:a")',
46+
$latte->compile('{link "p:a"}')
47+
);
48+
Assert::contains(
49+
'$this->global->uiControl->link(\'p:a\')',
50+
$latte->compile('{link \'p:a\'}')
51+
);
52+
53+
Assert::contains(
54+
'$this->global->uiControl->link("p", [\'param\'])',
55+
$latte->compile('{link p param}')
56+
);
57+
Assert::contains(
58+
'$this->global->uiControl->link("p", [\'param\' => 123])',
59+
$latte->compile('{link p param => 123}')
60+
);
61+
Assert::contains(
62+
'$this->global->uiControl->link("p", [\'param\' => 123])',
63+
$latte->compile('{link p, param => 123}')
64+
);

tests/Bridges.Latte/templates/snippet-include.latte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
{snippet array}
88
{foreach [1, 2, 3] as $id}
9-
{snippet array-$id}Value {$id}{/snippet}
9+
{snippet "array-$id"}Value {$id}{/snippet}
1010
{/foreach}
1111
{/snippet}
1212

1313
{snippetArea array2}
1414
{foreach [1, 2, 3] as $id}
15-
{snippet array2-$id}Value {$id}{/snippet}
15+
{snippet "array2-$id"}Value {$id}{/snippet}
1616
{/foreach}
1717
{/snippetArea}
1818

0 commit comments

Comments
 (0)