Completed
Push — template-events-reloaded ( 9aa4c3 )
by Kamil
28:28 queued 10s
created

it_is_a_template_event_renderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Prophecy\Argument;
18
use Sylius\Bundle\UiBundle\Registry\TemplateBlock;
19
use Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface;
20
use Sylius\Bundle\UiBundle\Renderer\TemplateEventRendererInterface;
21
22
final class HtmlDebugTemplateEventRendererSpec extends ObjectBehavior
23
{
24
    function let(TemplateEventRendererInterface $templateEventRenderer, TemplateBlockRegistryInterface $templateBlockRegistry): void
25
    {
26
        $this->beConstructedWith($templateEventRenderer, $templateBlockRegistry);
27
    }
28
29
    function it_is_a_template_event_renderer(): void
30
    {
31
        $this->shouldImplement(TemplateEventRendererInterface::class);
32
    }
33
34
    function it_renders_html_debug_comment_if_at_least_one_template_is_a_html_one(
35
        TemplateEventRendererInterface $templateEventRenderer,
36
        TemplateBlockRegistryInterface $templateBlockRegistry
37
    ): void {
38
        $firstTemplateBlock = new TemplateBlock('first_block', 'firstBlock.txt.twig', [], 0, true);
39
        $secondTemplateBlock = new TemplateBlock('second_block', 'secondBlock.html.twig', [], 0, true);
40
41
        $templateBlockRegistry->findEnabledForEvent('best_event_ever')->willReturn([$firstTemplateBlock, $secondTemplateBlock]);
42
43
        $templateEventRenderer->render('best_event_ever', ['foo' => 'bar'])->willReturn("First block\nSecond block");
44
45
        $this->render('best_event_ever', ['foo' => 'bar'])->shouldReturn(
46
            '<!-- BEGIN EVENT | event name: "best_event_ever" -->' . "\n" .
47
            'First block' . "\n" .
48
            'Second block' . "\n" .
49
            '<!-- END EVENT | event name: "best_event_ever" -->'
50
        );
51
    }
52
53
    function it_does_not_render_html_debug_comment_if_no_html_templates_are_found(
54
        TemplateEventRendererInterface $templateEventRenderer,
55
        TemplateBlockRegistryInterface $templateBlockRegistry
56
    ): void {
57
        $firstTemplateBlock = new TemplateBlock('first_block', 'firstBlock.txt.twig', [], 0, true);
58
        $secondTemplateBlock = new TemplateBlock('second_block', 'secondBlock.txt.twig', [], 0, true);
59
60
        $templateBlockRegistry->findEnabledForEvent('best_event_ever')->willReturn([$firstTemplateBlock, $secondTemplateBlock]);
61
62
        $templateEventRenderer->render('best_event_ever', ['foo' => 'bar'])->willReturn("First block\nSecond block");
63
64
        $this->render('best_event_ever', ['foo' => 'bar'])->shouldReturn("First block\nSecond block");
65
    }
66
67
    function it_returns_an_empty_string_if_no_blocks_are_found_for_an_event(
68
        TemplateEventRendererInterface $templateEventRenderer,
69
        TemplateBlockRegistryInterface $templateBlockRegistry
70
    ): void {
71
        $templateBlockRegistry->findEnabledForEvent('best_event_ever')->willReturn([]);
72
73
        $templateEventRenderer->render(Argument::cetera())->willReturn('');
74
75
        $this->render('best_event_ever')->shouldReturn('');
76
    }
77
}
78