@@ -97,12 +97,18 @@ public function testGetComponentName(): void
97
97
* @param bool $showsTime
98
98
* @param array $filterData
99
99
* @param array|null $expectedCondition
100
+ * @param string|null $dateFormat
100
101
*
101
102
* @return void
102
103
* @dataProvider getPrepareDataProvider
103
104
*/
104
- public function testPrepare (string $ name , bool $ showsTime , array $ filterData , ?array $ expectedCondition ): void
105
- {
105
+ public function testPrepare (
106
+ string $ name ,
107
+ bool $ showsTime ,
108
+ array $ filterData ,
109
+ ?array $ expectedCondition ,
110
+ ?string $ dateFormat
111
+ ): void {
106
112
$ processor = $ this ->getMockBuilder (Processor::class)
107
113
->disableOriginalConstructor ()
108
114
->getMock ();
@@ -132,7 +138,7 @@ public function testPrepare(string $name, bool $showsTime, array $filterData, ?a
132
138
->willReturn ($ this ->dataProviderMock );
133
139
134
140
if ($ expectedCondition !== null ) {
135
- $ this ->processFilters ($ name , $ showsTime , $ filterData , $ expectedCondition , $ uiComponent );
141
+ $ this ->processFilters ($ name , $ showsTime , $ filterData , $ expectedCondition , $ dateFormat , $ uiComponent );
136
142
}
137
143
138
144
$ this ->uiComponentFactory ->expects ($ this ->any ())
@@ -148,7 +154,7 @@ public function testPrepare(string $name, bool $showsTime, array $filterData, ?a
148
154
[],
149
155
[
150
156
'name ' => $ name ,
151
- 'config ' => ['options ' => ['showsTime ' => $ showsTime ]],
157
+ 'config ' => ['options ' => ['showsTime ' => $ showsTime ], ' dateFormat ' => $ dateFormat ],
152
158
]
153
159
);
154
160
$ date ->prepare ();
@@ -164,13 +170,15 @@ public function getPrepareDataProvider(): array
164
170
'name ' => 'test_date ' ,
165
171
'showsTime ' => false ,
166
172
'filterData ' => ['test_date ' => ['from ' => '11-05-2015 ' , 'to ' => null ]],
167
- 'expectedCondition ' => ['date ' => '2015-05-11 00:00:00 ' , 'type ' => 'gteq ' ]
173
+ 'expectedCondition ' => ['date ' => '2015-05-11 00:00:00 ' , 'type ' => 'gteq ' ],
174
+ 'dateFormat ' => null
168
175
],
169
176
[
170
177
'name ' => 'test_date ' ,
171
178
'showsTime ' => false ,
172
179
'filterData ' => ['test_date ' => ['from ' => null , 'to ' => '11-05-2015 ' ]],
173
- 'expectedCondition ' => ['date ' => '2015-05-11 23:59:59 ' , 'type ' => 'lteq ' ]
180
+ 'expectedCondition ' => ['date ' => '2015-05-11 23:59:59 ' , 'type ' => 'lteq ' ],
181
+ 'dateFormat ' => null
174
182
],
175
183
[
176
184
'name ' => 'test_date ' ,
@@ -179,19 +187,22 @@ public function getPrepareDataProvider(): array
179
187
'expectedCondition ' => [
180
188
'date_from ' => '2015-05-11 00:00:00 ' , 'type_from ' => 'gteq ' ,
181
189
'date_to ' => '2015-05-11 23:59:59 ' , 'type_to ' => 'lteq '
182
- ]
190
+ ],
191
+ 'dateFormat ' => null
183
192
],
184
193
[
185
194
'name ' => 'test_date ' ,
186
195
'showsTime ' => false ,
187
196
'filterData ' => ['test_date ' => '11-05-2015 ' ],
188
- 'expectedCondition ' => ['date ' => '2015-05-11 00:00:00 ' , 'type ' => 'eq ' ]
197
+ 'expectedCondition ' => ['date ' => '2015-05-11 00:00:00 ' , 'type ' => 'eq ' ],
198
+ 'dateFormat ' => null
189
199
],
190
200
[
191
201
'name ' => 'test_date ' ,
192
202
'showsTime ' => false ,
193
203
'filterData ' => ['test_date ' => ['from ' => '' , 'to ' => '' ]],
194
- 'expectedCondition ' => null
204
+ 'expectedCondition ' => null ,
205
+ 'dateFormat ' => null
195
206
],
196
207
[
197
208
'name ' => 'test_date ' ,
@@ -200,7 +211,18 @@ public function getPrepareDataProvider(): array
200
211
'expectedCondition ' => [
201
212
'date_from ' => '2015-05-11 10:20:00 ' , 'type_from ' => 'gteq ' ,
202
213
'date_to ' => '2015-05-11 18:25:00 ' , 'type_to ' => 'lteq '
203
- ]
214
+ ],
215
+ 'dateFormat ' => null
216
+ ],
217
+ [
218
+ 'name ' => 'test_date ' ,
219
+ 'showsTime ' => false ,
220
+ 'filterData ' => ['test_date ' => ['from ' => '2015-05-11 ' , 'to ' => '2015-05-11 ' ]],
221
+ 'expectedCondition ' => [
222
+ 'date_from ' => '2015-05-11 00:00:00 ' , 'type_from ' => 'gteq ' ,
223
+ 'date_to ' => '2015-05-11 23:59:59 ' , 'type_to ' => 'lteq '
224
+ ],
225
+ 'dateFormat ' => 'Y-MM-dd '
204
226
]
205
227
];
206
228
}
@@ -210,6 +232,7 @@ public function getPrepareDataProvider(): array
210
232
* @param bool $showsTime
211
233
* @param array $filterData
212
234
* @param array $expectedCondition
235
+ * @param string|null $dateFormat
213
236
* @param MockObject $uiComponent
214
237
*
215
238
* @return void
@@ -220,6 +243,7 @@ private function processFilters(
220
243
bool $ showsTime ,
221
244
array $ filterData ,
222
245
array $ expectedCondition ,
246
+ string |null $ dateFormat ,
223
247
FormDate $ uiComponent
224
248
): void {
225
249
if (is_string ($ filterData [$ name ])) {
@@ -239,6 +263,18 @@ private function processFilters(
239
263
]
240
264
);
241
265
} else {
266
+ if ($ dateFormat === 'Y-MM-dd ' ) {
267
+ $ uiComponent ->method ('convertDateFormat ' )
268
+ ->willReturn (
269
+ date_format (date_create ($ filterData [$ name ]['from ' ]), 'm/d/Y ' )
270
+ );
271
+ $ uiComponent ->method ('convertDateFormat ' )
272
+ ->willReturn (
273
+ date_format (date_create ($ filterData [$ name ]['to ' ]), 'm/d/Y ' )
274
+ );
275
+ $ filterData [$ name ]['from ' ] = date_format (date_create ($ filterData [$ name ]['from ' ]), 'm/d/Y ' );
276
+ $ filterData [$ name ]['to ' ] = date_format (date_create ($ filterData [$ name ]['to ' ]), 'm/d/Y ' );
277
+ }
242
278
$ from = new \DateTime ($ filterData [$ name ]['from ' ] ?? 'now ' );
243
279
$ to = new \DateTime ($ filterData [$ name ]['to ' ] ? $ filterData [$ name ]['to ' ] . ' 23:59:59 ' : 'now ' );
244
280
$ uiComponent ->method ('convertDate ' )
0 commit comments