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
|
|
|
final class ArrayToDefinitionConverterSpec extends ObjectBehavior |
28
|
|
|
{ |
29
|
|
|
function let(EventDispatcherInterface $eventDispatcher): void |
30
|
|
|
{ |
31
|
|
|
$this->beConstructedWith($eventDispatcher); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_implements_array_to_definition_converter(): void |
35
|
|
|
{ |
36
|
|
|
$this->shouldImplement(ArrayToDefinitionConverterInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_converts_an_array_to_grid_definition(EventDispatcherInterface $eventDispatcher): void |
40
|
|
|
{ |
41
|
|
|
$grid = Grid::fromCodeAndDriverConfiguration( |
42
|
|
|
'sylius_admin_tax_category', |
43
|
|
|
'doctrine/orm', |
44
|
|
|
['resource' => 'sylius.tax_category'] |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$grid->setSorting(['code' => 'desc']); |
48
|
|
|
|
49
|
|
|
$grid->setLimits([9, 18]); |
50
|
|
|
|
51
|
|
|
$codeField = Field::fromNameAndType('code', 'string'); |
52
|
|
|
$codeField->setLabel('System Code'); |
53
|
|
|
$codeField->setPath('method.code'); |
54
|
|
|
$codeField->setOptions(['template' => 'bar.html.twig']); |
55
|
|
|
$codeField->setSortable('code'); |
56
|
|
|
|
57
|
|
|
$grid->addField($codeField); |
58
|
|
|
|
59
|
|
|
$enabledField = Field::fromNameAndType('enabled', 'boolean'); |
60
|
|
|
$enabledField->setLabel('Enabled'); |
61
|
|
|
$enabledField->setPath('method.enabled'); |
62
|
|
|
$enabledField->setSortable('enabled'); |
63
|
|
|
|
64
|
|
|
$grid->addField($enabledField); |
65
|
|
|
|
66
|
|
|
$statusField = Field::fromNameAndType('status', 'string'); |
67
|
|
|
$statusField->setLabel('Status'); |
68
|
|
|
$statusField->setSortable('status'); |
69
|
|
|
|
70
|
|
|
$grid->addField($statusField); |
71
|
|
|
|
72
|
|
|
$nameField = Field::fromNameAndType('name', 'string'); |
73
|
|
|
$nameField->setLabel('Name'); |
74
|
|
|
$nameField->setSortable('name'); |
75
|
|
|
|
76
|
|
|
$grid->addField($nameField); |
77
|
|
|
|
78
|
|
|
$titleField = Field::fromNameAndType('title', 'string'); |
79
|
|
|
$titleField->setLabel('Title'); |
80
|
|
|
|
81
|
|
|
$grid->addField($titleField); |
82
|
|
|
|
83
|
|
|
$viewAction = Action::fromNameAndType('view', 'link'); |
84
|
|
|
$viewAction->setLabel('Display Tax Category'); |
85
|
|
|
$viewAction->setOptions(['foo' => 'bar']); |
86
|
|
|
$defaultActionGroup = ActionGroup::named('default'); |
87
|
|
|
$defaultActionGroup->addAction($viewAction); |
88
|
|
|
|
89
|
|
|
$grid->addActionGroup($defaultActionGroup); |
90
|
|
|
|
91
|
|
|
$filter = Filter::fromNameAndType('enabled', 'boolean'); |
92
|
|
|
$filter->setOptions(['fields' => ['firstName', 'lastName']]); |
93
|
|
|
$filter->setCriteria('true'); |
94
|
|
|
$grid->addFilter($filter); |
95
|
|
|
|
96
|
|
|
$eventDispatcher |
97
|
|
|
->dispatch('sylius.grid.admin_tax_category', Argument::type(GridDefinitionConverterEvent::class)) |
98
|
|
|
->shouldBeCalled() |
99
|
|
|
; |
100
|
|
|
|
101
|
|
|
$definitionArray = [ |
102
|
|
|
'driver' => [ |
103
|
|
|
'name' => 'doctrine/orm', |
104
|
|
|
'options' => ['resource' => 'sylius.tax_category'], |
105
|
|
|
], |
106
|
|
|
'sorting' => [ |
107
|
|
|
'code' => 'desc', |
108
|
|
|
], |
109
|
|
|
'limits' => [9, 18], |
110
|
|
|
'fields' => [ |
111
|
|
|
'code' => [ |
112
|
|
|
'type' => 'string', |
113
|
|
|
'label' => 'System Code', |
114
|
|
|
'path' => 'method.code', |
115
|
|
|
'sortable' => 'code', |
116
|
|
|
'options' => [ |
117
|
|
|
'template' => 'bar.html.twig', |
118
|
|
|
], |
119
|
|
|
], |
120
|
|
|
'enabled' => [ |
121
|
|
|
'type' => 'boolean', |
122
|
|
|
'label' => 'Enabled', |
123
|
|
|
'path' => 'method.enabled', |
124
|
|
|
'sortable' => true, |
125
|
|
|
], |
126
|
|
|
'status' => [ |
127
|
|
|
'type' => 'string', |
128
|
|
|
'label' => 'Status', |
129
|
|
|
'sortable' => true, |
130
|
|
|
], |
131
|
|
|
'name' => [ |
132
|
|
|
'type' => 'string', |
133
|
|
|
'label' => 'Name', |
134
|
|
|
'sortable' => null, |
135
|
|
|
], |
136
|
|
|
'title' => [ |
137
|
|
|
'type' => 'string', |
138
|
|
|
'label' => 'Title', |
139
|
|
|
'sortable' => false, |
140
|
|
|
], |
141
|
|
|
], |
142
|
|
|
'filters' => [ |
143
|
|
|
'enabled' => [ |
144
|
|
|
'type' => 'boolean', |
145
|
|
|
'options' => [ |
146
|
|
|
'fields' => ['firstName', 'lastName'], |
147
|
|
|
], |
148
|
|
|
'default_value' => 'true', |
149
|
|
|
], |
150
|
|
|
], |
151
|
|
|
'actions' => [ |
152
|
|
|
'default' => [ |
153
|
|
|
'view' => [ |
154
|
|
|
'type' => 'link', |
155
|
|
|
'label' => 'Display Tax Category', |
156
|
|
|
'options' => [ |
157
|
|
|
'foo' => 'bar', |
158
|
|
|
], |
159
|
|
|
], |
160
|
|
|
], |
161
|
|
|
], |
162
|
|
|
]; |
163
|
|
|
|
164
|
|
|
$this->convert('sylius_admin_tax_category', $definitionArray)->shouldBeLike($grid); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|