/
GridSpec.php
192 lines (155 loc) · 5.5 KB
/
GridSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Grid\Definition;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Grid\Definition\Action;
use Sylius\Component\Grid\Definition\ActionGroup;
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\Definition\Filter;
use Sylius\Component\Grid\Definition\Grid;
/**
* @mixin Grid
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class GridSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedThrough('fromCodeAndDriverConfiguration', ['sylius_admin_tax_category', 'doctrine/orm', [
'resource' => 'sylius.tax_category',
'method' => 'createByCodeQueryBuilder',
'arguments' => ['$code']
]]);
}
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Grid\Definition\Grid');
}
function it_has_code()
{
$this->getCode()->shouldReturn('sylius_admin_tax_category');
}
function it_has_driver()
{
$this->getDriver()->shouldReturn('doctrine/orm');
}
function it_has_driver_configuration()
{
$this->getDriverConfiguration()->shouldReturn([
'resource' => 'sylius.tax_category',
'method' => 'createByCodeQueryBuilder',
'arguments' => ['$code']
]);
}
function its_driver_configuration_is_mutable()
{
$this->setDriverConfiguration(['foo' => 'bar']);
$this->getDriverConfiguration()->shouldReturn(['foo' => 'bar']);
}
function it_has_empty_sorting_configuration_by_default()
{
$this->getSorting()->shouldReturn([]);
}
function it_can_have_sorting_configuration()
{
$this->setSorting(['name' => 'desc']);
$this->getSorting()->shouldReturn(['name' => 'desc']);
}
function it_does_not_have_any_fields_by_default()
{
$this->getFields()->shouldReturn([]);
}
function it_can_have_field_definitions(Field $field)
{
$field->getName()->willReturn('description');
$this->addField($field);
$this->getField('description')->shouldReturn($field);
}
function it_cannot_have_two_fields_with_the_same_name(Field $firstField, Field $secondField)
{
$firstField->getName()->willReturn('created_at');
$secondField->getName()->willReturn('created_at');
$this->addField($firstField);
$this
->shouldThrow(\InvalidArgumentException::class)
->during('addField', [$secondField])
;
}
function it_knows_if_field_with_given_name_already_exists(Field $field)
{
$field->getName()->willReturn('enabled');
$this->addField($field);
$this->hasField('enabled')->shouldReturn(true);
$this->hasField('parent')->shouldReturn(false);
}
function it_does_not_have_any_action_groups_by_default()
{
$this->getActionGroups()->shouldReturn([]);
}
function it_can_have_action_group_definitions(ActionGroup $actionGroup)
{
$actionGroup->getName()->willReturn('default');
$this->addActionGroup($actionGroup);
$this->getActionGroup('default')->shouldReturn($actionGroup);
}
function it_cannot_have_two_action_groups_with_the_same_name(ActionGroup $firstActionGroup, ActionGroup $secondActionGroup)
{
$firstActionGroup->getName()->willReturn('row');
$secondActionGroup->getName()->willReturn('row');
$this->addActionGroup($firstActionGroup);
$this
->shouldThrow(\InvalidArgumentException::class)
->during('addActionGroup', [$secondActionGroup])
;
}
function it_knows_if_action_group_with_given_name_already_exists(ActionGroup $actionGroup)
{
$actionGroup->getName()->willReturn('row');
$this->addActionGroup($actionGroup);
$this->hasActionGroup('row')->shouldReturn(true);
$this->hasActionGroup('default')->shouldReturn(false);
}
function it_returns_actions_for_given_group(ActionGroup $actionGroup, Action $action)
{
$actionGroup->getName()->willReturn('row');
$actionGroup->getActions()->willReturn([$action]);
$this->addActionGroup($actionGroup);
$this->getActions('row')->shouldReturn([$action]);
}
function it_does_not_have_any_filters_by_default()
{
$this->getFilters()->shouldReturn([]);
}
function it_can_have_filter_definitions(Filter $filter)
{
$filter->getName()->willReturn('enabled');
$this->addFilter($filter);
$this->getFilter('enabled')->shouldReturn($filter);
}
function it_cannot_have_two_filters_with_the_same_name(Filter $firstFilter, Filter $secondFilter)
{
$firstFilter->getName()->willReturn('created_at');
$secondFilter->getName()->willReturn('created_at');
$this->addFilter($firstFilter);
$this
->shouldThrow(\InvalidArgumentException::class)
->during('addFilter', [$secondFilter])
;
}
function it_knows_if_filter_with_given_name_already_exists(Filter $filter)
{
$filter->getName()->willReturn('enabled');
$this->addFilter($filter);
$this->hasFilter('enabled')->shouldReturn(true);
$this->hasFilter('created_at')->shouldReturn(false);
}
}