|
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 spec\Sylius\Bundle\UiBundle\Renderer; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Bundle\UiBundle\Registry\TemplateBlock; |
|
18
|
|
|
use Sylius\Bundle\UiBundle\Renderer\TemplateBlockRendererInterface; |
|
19
|
|
|
use Twig\Environment; |
|
20
|
|
|
|
|
21
|
|
|
final class TemplateBlockRendererSpec extends ObjectBehavior |
|
22
|
|
|
{ |
|
23
|
|
|
function let(Environment $twig): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->beConstructedWith($twig, false); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
function it_is_a_template_block_renderer(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->shouldImplement(TemplateBlockRendererInterface::class); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_renders_a_template_block(Environment $twig): void |
|
34
|
|
|
{ |
|
35
|
|
|
$twig->render('block.txt.twig', ['foo' => 'bar'])->willReturn('Block content'); |
|
36
|
|
|
|
|
37
|
|
|
$this->render( |
|
38
|
|
|
'event_name', |
|
39
|
|
|
new TemplateBlock('block_name', 'block.txt.twig', [], 0, true), |
|
40
|
|
|
['foo' => 'bar'] |
|
41
|
|
|
)->shouldReturn('Block content'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_merges_template_block_context_with_passed_context(Environment $twig): void |
|
45
|
|
|
{ |
|
46
|
|
|
$twig->render('block.txt.twig', ['sample' => 'Hello', 'switch' => true])->willReturn('Block content'); |
|
47
|
|
|
|
|
48
|
|
|
$this->render( |
|
49
|
|
|
'event_name', |
|
50
|
|
|
new TemplateBlock('block_name', 'block.txt.twig', ['sample' => 'Hi', 'switch' => true], 0, true), |
|
51
|
|
|
['sample' => 'Hello'] |
|
52
|
|
|
)->shouldReturn('Block content'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function it_renders_html_debug_comment_prepending_the_comment_if_in_debug_mode_rendering_html_template(Environment $twig): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->beConstructedWith($twig, true); |
|
58
|
|
|
|
|
59
|
|
|
$twig->render('block.html.twig', ['foo' => 'bar'])->willReturn('Block content'); |
|
60
|
|
|
|
|
61
|
|
|
$this->render( |
|
62
|
|
|
'event_name', |
|
63
|
|
|
new TemplateBlock('block_name', 'block.html.twig', [], 0, true), |
|
64
|
|
|
['foo' => 'bar'] |
|
65
|
|
|
)->shouldReturn( |
|
66
|
|
|
'<!-- event name: "event_name", block name: "block_name", template: "block.html.twig", priority: 0 -->' . "\n" . |
|
67
|
|
|
'Block content' |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function it_renders_html_debug_comment_prepending_the_comment_if_not_in_debug_mode_rendering_html_template(Environment $twig): void |
|
72
|
|
|
{ |
|
73
|
|
|
$this->beConstructedWith($twig, false); |
|
74
|
|
|
|
|
75
|
|
|
$twig->render('block.html.twig', ['foo' => 'bar'])->willReturn('Block content'); |
|
76
|
|
|
|
|
77
|
|
|
$this->render( |
|
78
|
|
|
'event_name', |
|
79
|
|
|
new TemplateBlock('block_name', 'block.html.twig', [], 0, true), |
|
80
|
|
|
['foo' => 'bar'] |
|
81
|
|
|
)->shouldReturn('Block content'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|