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
|
|
|
namespace spec\Sylius\Component\Grid\Filter; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Component\Grid\Data\DataSourceInterface; |
16
|
|
|
use Sylius\Component\Grid\Data\ExpressionBuilderInterface; |
17
|
|
|
use Sylius\Component\Grid\Filter\DateFilter; |
18
|
|
|
use Sylius\Component\Grid\Filtering\FilterInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class DateFilterSpec extends ObjectBehavior |
24
|
|
|
{ |
25
|
|
|
function it_is_initializable() |
26
|
|
|
{ |
27
|
|
|
$this->shouldHaveType(DateFilter::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_implements_a_filter_interface() |
31
|
|
|
{ |
32
|
|
|
$this->shouldImplement(FilterInterface::class); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_filters_date_from( |
36
|
|
|
DataSourceInterface $dataSource, |
37
|
|
|
ExpressionBuilderInterface $expressionBuilder |
38
|
|
|
) { |
39
|
|
|
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder); |
40
|
|
|
|
41
|
|
|
$expressionBuilder |
42
|
|
|
->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05 08:00') |
43
|
|
|
->shouldBeCalled() |
44
|
|
|
; |
45
|
|
|
|
46
|
|
|
$this->apply( |
47
|
|
|
$dataSource, |
48
|
|
|
'checkoutCompletedAt', |
49
|
|
|
[ |
50
|
|
|
'from' => [ |
51
|
|
|
'date' => '2016-12-05', |
52
|
|
|
'time' => '08:00', |
53
|
|
|
], |
54
|
|
|
'to' => [ |
55
|
|
|
'date' => '', |
56
|
|
|
'time' => '', |
57
|
|
|
] |
58
|
|
|
], |
59
|
|
|
[] |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
function it_filters_date_from_without_time( |
64
|
|
|
DataSourceInterface $dataSource, |
65
|
|
|
ExpressionBuilderInterface $expressionBuilder |
66
|
|
|
) { |
67
|
|
|
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder); |
68
|
|
|
|
69
|
|
|
$expressionBuilder |
70
|
|
|
->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05') |
71
|
|
|
->shouldBeCalled() |
72
|
|
|
; |
73
|
|
|
|
74
|
|
|
$this->apply( |
75
|
|
|
$dataSource, |
76
|
|
|
'checkoutCompletedAt', |
77
|
|
|
[ |
78
|
|
|
'from' => [ |
79
|
|
|
'date' => '2016-12-05', |
80
|
|
|
'time' => '', |
81
|
|
|
], |
82
|
|
|
'to' => [ |
83
|
|
|
'date' => '', |
84
|
|
|
'time' => '', |
85
|
|
|
] |
86
|
|
|
], |
87
|
|
|
[] |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function it_filters_date_to( |
92
|
|
|
DataSourceInterface $dataSource, |
93
|
|
|
ExpressionBuilderInterface $expressionBuilder |
94
|
|
|
) { |
95
|
|
|
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder); |
96
|
|
|
|
97
|
|
|
$expressionBuilder |
98
|
|
|
->lessThan('checkoutCompletedAt', '2016-12-06 08:00') |
99
|
|
|
->shouldBeCalled() |
100
|
|
|
; |
101
|
|
|
|
102
|
|
|
$this->apply( |
103
|
|
|
$dataSource, |
104
|
|
|
'checkoutCompletedAt', |
105
|
|
|
[ |
106
|
|
|
'from' => [ |
107
|
|
|
'date' => '', |
108
|
|
|
'time' => '', |
109
|
|
|
], |
110
|
|
|
'to' => [ |
111
|
|
|
'date' => '2016-12-06', |
112
|
|
|
'time' => '08:00', |
113
|
|
|
] |
114
|
|
|
], |
115
|
|
|
[] |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function it_filters_date_to_without_time( |
120
|
|
|
DataSourceInterface $dataSource, |
121
|
|
|
ExpressionBuilderInterface $expressionBuilder |
122
|
|
|
) { |
123
|
|
|
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder); |
124
|
|
|
|
125
|
|
|
$expressionBuilder |
126
|
|
|
->lessThan('checkoutCompletedAt', '2016-12-06') |
127
|
|
|
->shouldBeCalled() |
128
|
|
|
; |
129
|
|
|
|
130
|
|
|
$this->apply( |
131
|
|
|
$dataSource, |
132
|
|
|
'checkoutCompletedAt', |
133
|
|
|
[ |
134
|
|
|
'from' => [ |
135
|
|
|
'date' => '', |
136
|
|
|
'time' => '', |
137
|
|
|
], |
138
|
|
|
'to' => [ |
139
|
|
|
'date' => '2016-12-06', |
140
|
|
|
'time' => '', |
141
|
|
|
] |
142
|
|
|
], |
143
|
|
|
[] |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
function it_filters_date_from_to( |
148
|
|
|
DataSourceInterface $dataSource, |
149
|
|
|
ExpressionBuilderInterface $expressionBuilder |
150
|
|
|
) { |
151
|
|
|
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder); |
152
|
|
|
|
153
|
|
|
$expressionBuilder |
154
|
|
|
->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05 08:00') |
155
|
|
|
->shouldBeCalled() |
156
|
|
|
; |
157
|
|
|
|
158
|
|
|
$expressionBuilder |
159
|
|
|
->lessThan('checkoutCompletedAt', '2016-12-06 08:00') |
160
|
|
|
->shouldBeCalled() |
161
|
|
|
; |
162
|
|
|
|
163
|
|
|
$this->apply( |
164
|
|
|
$dataSource, |
165
|
|
|
'checkoutCompletedAt', |
166
|
|
|
[ |
167
|
|
|
'from' => [ |
168
|
|
|
'date' => '2016-12-05', |
169
|
|
|
'time' => '08:00', |
170
|
|
|
], |
171
|
|
|
'to' => [ |
172
|
|
|
'date' => '2016-12-06', |
173
|
|
|
'time' => '08:00', |
174
|
|
|
] |
175
|
|
|
], |
176
|
|
|
[] |
177
|
|
|
); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|