Completed
Push — theme-collector ( e0987d )
by Kamil
23:25
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
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\Component\Grid\Definition;
15
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use Sylius\Component\Grid\Definition\Action;
19
use Sylius\Component\Grid\Definition\ActionGroup;
20
use Sylius\Component\Grid\Definition\ArrayToDefinitionConverterInterface;
21
use Sylius\Component\Grid\Definition\Field;
22
use Sylius\Component\Grid\Definition\Filter;
23
use Sylius\Component\Grid\Definition\Grid;
24
use Sylius\Component\Grid\Event\GridDefinitionConverterEvent;
25
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
26
27
/**
28
 * @author Paweł Jędrzejewski <[email protected]>
29
 */
30
final class ArrayToDefinitionConverterSpec extends ObjectBehavior
31
{
32
    function let(EventDispatcherInterface $eventDispatcher): void
33
    {
34
        $this->beConstructedWith($eventDispatcher);
35
    }
36
37
    function it_implements_array_to_definition_converter(): void
38
    {
39
        $this->shouldImplement(ArrayToDefinitionConverterInterface::class);
40
    }
41
42
    function it_converts_an_array_to_grid_definition(EventDispatcherInterface $eventDispatcher): void
43
    {
44
        $grid = Grid::fromCodeAndDriverConfiguration(
45
            'sylius_admin_tax_category',
46
            'doctrine/orm',
47
            ['resource' => 'sylius.tax_category']
48
        );
49
50
        $grid->setSorting(['code' => 'desc']);
51
52
        $grid->setLimits([9, 18]);
53
54
        $codeField = Field::fromNameAndType('code', 'string');
55
        $codeField->setLabel('System Code');
56
        $codeField->setPath('method.code');
57
        $codeField->setOptions(['template' => 'bar.html.twig']);
58
        $codeField->setSortable('code');
59
60
        $grid->addField($codeField);
61
62
        $viewAction = Action::fromNameAndType('view', 'link');
63
        $viewAction->setLabel('Display Tax Category');
64
        $viewAction->setOptions(['foo' => 'bar']);
65
        $defaultActionGroup = ActionGroup::named('default');
66
        $defaultActionGroup->addAction($viewAction);
67
68
        $grid->addActionGroup($defaultActionGroup);
69
70
        $filter = Filter::fromNameAndType('enabled', 'boolean');
71
        $filter->setOptions(['fields' => ['firstName', 'lastName']]);
72
        $filter->setCriteria('true');
73
        $grid->addFilter($filter);
74
75
        $eventDispatcher
76
            ->dispatch('sylius.grid.admin_tax_category', Argument::type(GridDefinitionConverterEvent::class))
77
            ->shouldBeCalled()
78
        ;
79
80
        $definitionArray = [
81
            'driver' => [
82
                'name' => 'doctrine/orm',
83
                'options' => ['resource' => 'sylius.tax_category'],
84
            ],
85
            'sorting' => [
86
                'code' => 'desc',
87
            ],
88
            'limits' => [9, 18],
89
            'fields' => [
90
                'code' => [
91
                    'type' => 'string',
92
                    'label' => 'System Code',
93
                    'path' => 'method.code',
94
                    'sortable' => 'code',
95
                    'options' => [
96
                        'template' => 'bar.html.twig'
97
                    ],
98
                ],
99
            ],
100
            'filters' => [
101
                'enabled' => [
102
                    'type' => 'boolean',
103
                    'options' => [
104
                        'fields' => ['firstName', 'lastName']
105
                    ],
106
                    'default_value' => 'true',
107
                ]
108
            ],
109
            'actions' => [
110
                'default' => [
111
                    'view' => [
112
                        'type' => 'link',
113
                        'label' => 'Display Tax Category',
114
                        'options' => [
115
                            'foo' => 'bar',
116
                        ],
117
                    ]
118
                ]
119
            ]
120
        ];
121
122
        $this->convert('sylius_admin_tax_category', $definitionArray)->shouldBeLike($grid);
123
    }
124
}
125