1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\UiBundle\Tests\Functional; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\Assert; |
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
18
|
|
|
use Twig\Environment; |
19
|
|
|
|
20
|
|
|
final class TemplateEventTest extends KernelTestCase |
21
|
|
|
{ |
22
|
|
|
/** @var Environment */ |
23
|
|
|
private $twig; |
24
|
|
|
|
25
|
|
|
protected function setUp(): void |
26
|
|
|
{ |
27
|
|
|
self::bootKernel(); |
28
|
|
|
|
29
|
|
|
$this->twig = self::$container->get('twig'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** @test */ |
33
|
|
|
public function it_renders_template_events_blocks(): void |
34
|
|
|
{ |
35
|
|
|
// See Kernel.php for the configuration resulting in those lines |
36
|
|
|
$expectedLines = [ |
37
|
|
|
'First block', |
38
|
|
|
'Second block', |
39
|
|
|
'Third block', |
40
|
|
|
'The king is dead, long live the king!', |
41
|
|
|
]; |
42
|
|
|
$renderedLines = array_values(array_filter(explode("\n", $this->twig->render('templateEvents.txt.twig')))); |
43
|
|
|
|
44
|
|
|
Assert::assertSame($expectedLines, $renderedLines); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** @test */ |
48
|
|
|
public function it_renders_debug_info_in_html_comments_while_rendering_in_test_environment(): void |
49
|
|
|
{ |
50
|
|
|
// See Kernel.php for the configuration resulting in those lines |
51
|
|
|
$expectedLines = [ |
52
|
|
|
'<!-- BEGIN EVENT | event name: "event" -->', |
53
|
|
|
'<!-- BEGIN BLOCK | event name: "event", block name: "first", template: "blocks/html/first.html.twig", priority: 5 -->', |
54
|
|
|
'<p id="first">First block</p>', |
55
|
|
|
'<!-- END BLOCK | event name: "event", block name: "first" -->', |
56
|
|
|
'<!-- BEGIN BLOCK | event name: "event", block name: "context", template: "blocks/html/context.html.twig", priority: -5 -->', |
57
|
|
|
'<p class="context">The king is dead, long live the king!</p>', |
58
|
|
|
'<!-- END BLOCK | event name: "event", block name: "context" -->', |
59
|
|
|
'<!-- END EVENT | event name: "event" -->', |
60
|
|
|
]; |
61
|
|
|
$renderedLines = array_values(array_filter(explode("\n", $this->twig->render('templateEvents.html.twig')))); |
62
|
|
|
|
63
|
|
|
Assert::assertSame($expectedLines, $renderedLines); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @test */ |
67
|
|
|
public function it_passes_context_defined_in_template_block_configuration_during_rendering(): void |
68
|
|
|
{ |
69
|
|
|
// See Kernel.php for the configuration resulting in those lines |
70
|
|
|
$expectedLines = [ |
71
|
|
|
'Block: option1=foo, option2=baz', |
72
|
|
|
]; |
73
|
|
|
$renderedLines = array_values(array_filter(explode("\n", $this->twig->render('contextTemplateBlock.txt.twig')))); |
74
|
|
|
|
75
|
|
|
Assert::assertSame($expectedLines, $renderedLines); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** @test */ |
79
|
|
|
public function it_renders_multiple_events_at_once(): void |
80
|
|
|
{ |
81
|
|
|
// See Kernel.php for the configuration resulting in those lines |
82
|
|
|
$expectedLines = [ |
83
|
|
|
'Generic block #2 (value=42)', |
84
|
|
|
'Specific block', |
85
|
|
|
'Generic block #1', |
86
|
|
|
]; |
87
|
|
|
|
88
|
|
|
$renderedLines = array_values(array_filter(explode("\n", $this->twig->render('multipleEvents.txt.twig')))); |
89
|
|
|
|
90
|
|
|
Assert::assertSame($expectedLines, $renderedLines); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|