Completed
Push — master ( 52cd2c...047880 )
by Kamil
47:26 queued 26:32
created

TemplateEventTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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 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
            '<!-- event name: "event", block name: "first", template: "blocks/html/first.html.twig", priority: 5 -->',
53
            '<p id="first">First block</p>',
54
            '<!-- event name: "event", block name: "context", template: "blocks/html/context.html.twig", priority: -5 -->',
55
            '<p class="context">The king is dead, long live the king!</p>',
56
        ];
57
        $renderedLines = array_values(array_filter(explode("\n", $this->twig->render('templateEvents.html.twig'))));
58
59
        Assert::assertSame($expectedLines, $renderedLines);
60
    }
61
62
    /** @test */
63
    public function it_passes_context_defined_in_template_block_configuration_during_rendering(): void
64
    {
65
        // See Kernel.php for the configuration resulting in those lines
66
        $expectedLines = [
67
            'Block: option1=foo, option2=baz',
68
        ];
69
        $renderedLines = array_values(array_filter(explode("\n", $this->twig->render('contextTemplateBlock.txt.twig'))));
70
71
        Assert::assertSame($expectedLines, $renderedLines);
72
    }
73
}
74