Completed
Push — master ( b1c6ca...52cd2c )
by Kamil
77:57 queued 60:05
created

SyliusUiExtensionTest::getContainerExtensions()   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 Sylius\Bundle\UiBundle\Tests\DependencyInjection;
15
16
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
17
use Sylius\Bundle\UiBundle\DependencyInjection\SyliusUiExtension;
18
19
final class SyliusUiExtensionTest extends AbstractExtensionTestCase
20
{
21
    /** @test */
22
    public function it_configures_the_multiple_event_block_listener_service_with_events_and_blocks_data(): void
23
    {
24
        $this->load(['events' => [
25
            'first_event' => ['blocks' => [
26
                'first_block' => ['template' => 'first.html.twig', 'enabled' => true, 'priority' => 0],
27
                'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0],
28
            ]],
29
            'second_event' => ['blocks' => [
30
                'another_block' => ['template' => 'another.html.twig', 'enabled' => true, 'priority' => 0],
31
            ]],
32
        ]]);
33
34
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
35
            'sylius.twig.extension.template_event',
36
            1,
37
            [
38
                'first_event' => [
39
                    'first.html.twig',
40
                    'second.html.twig',
41
                ],
42
                'second_event' => [
43
                    'another.html.twig',
44
                ],
45
            ]
46
        );
47
    }
48
49
    /** @test */
50
    public function it_does_not_register_disabled_blocks(): void
51
    {
52
        $this->load(['events' => [
53
            'event_name' => ['blocks' => [
54
                'first_block' => ['template' => 'first.html.twig', 'enabled' => false, 'priority' => 0],
55
                'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0],
56
            ]],
57
        ]]);
58
59
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
60
            'sylius.twig.extension.template_event',
61
            1,
62
            ['event_name' => [
63
                'second.html.twig',
64
            ]]
65
        );
66
    }
67
68
    /** @test */
69
    public function it_sorts_blocks_by_their_priority_and_uses_fifo_ordering(): void
70
    {
71
        $this->load(['events' => [
72
            'event_name' => ['blocks' => [
73
                'fourth_block' => ['template' => 'fourth.html.twig', 'enabled' => true, 'priority' => -5],
74
                'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0],
75
                'third_block' => ['template' => 'third.html.twig', 'enabled' => true, 'priority' => 0],
76
                'first_block' => ['template' => 'first.html.twig', 'enabled' => true, 'priority' => 5],
77
            ]],
78
        ]]);
79
80
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
81
            'sylius.twig.extension.template_event',
82
            1,
83
            ['event_name' => [
84
                'first.html.twig',
85
                'second.html.twig',
86
                'third.html.twig',
87
                'fourth.html.twig',
88
            ]]
89
        );
90
    }
91
92
    protected function getContainerExtensions(): array
93
    {
94
        return [new SyliusUiExtension()];
95
    }
96
}
97