4
4
5
5
namespace MauticPlugin \CustomObjectsBundle \Tests \Functional \Helper ;
6
6
7
+ use DateTime ;
7
8
use Mautic \CoreBundle \Test \MauticMysqlTestCase ;
8
9
use Mautic \LeadBundle \Segment \ContactSegmentFilterFactory ;
9
10
use Mautic \LeadBundle \Segment \Query \QueryBuilder ;
@@ -200,6 +201,76 @@ public function testGetCustomValueValueExpression(): void
200
201
]
201
202
);
202
203
204
+ $ this ->assertMatchWhere (
205
+ 'test_value.value LIKE :par5 ' ,
206
+ [
207
+ 'glue ' => 'and ' ,
208
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_field1 ' )->getId (),
209
+ 'object ' => 'custom_object ' ,
210
+ 'type ' => 'datetime ' ,
211
+ 'operator ' => 'like ' ,
212
+ 'properties ' => [
213
+ 'filter ' => '2024 ' ,
214
+ ],
215
+ ]
216
+ );
217
+
218
+ $ this ->assertMatchWhere (
219
+ 'test_value.value REGEXP :par6 ' ,
220
+ [
221
+ 'glue ' => 'and ' ,
222
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_field1 ' )->getId (),
223
+ 'object ' => 'custom_object ' ,
224
+ 'type ' => 'datetime ' ,
225
+ 'operator ' => 'regexp ' ,
226
+ 'properties ' => [
227
+ 'filter ' => '2024 ' ,
228
+ ],
229
+ ]
230
+ );
231
+
232
+ $ this ->assertMatchWhere (
233
+ 'test_value.value LIKE :par7 ' ,
234
+ [
235
+ 'glue ' => 'and ' ,
236
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_field1 ' )->getId (),
237
+ 'object ' => 'custom_object ' ,
238
+ 'type ' => 'datetime ' ,
239
+ 'operator ' => 'startsWith ' ,
240
+ 'properties ' => [
241
+ 'filter ' => '2024 ' ,
242
+ ],
243
+ ]
244
+ );
245
+
246
+ $ this ->assertMatchWhere (
247
+ 'test_value.value LIKE :par8 ' ,
248
+ [
249
+ 'glue ' => 'and ' ,
250
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_field1 ' )->getId (),
251
+ 'object ' => 'custom_object ' ,
252
+ 'type ' => 'datetime ' ,
253
+ 'operator ' => 'endsWith ' ,
254
+ 'properties ' => [
255
+ 'filter ' => '2024 ' ,
256
+ ],
257
+ ]
258
+ );
259
+
260
+ $ this ->assertMatchWhere (
261
+ 'test_value.value LIKE :par9 ' ,
262
+ [
263
+ 'glue ' => 'and ' ,
264
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_field1 ' )->getId (),
265
+ 'object ' => 'custom_object ' ,
266
+ 'type ' => 'datetime ' ,
267
+ 'operator ' => 'contains ' ,
268
+ 'properties ' => [
269
+ 'filter ' => '2024 ' ,
270
+ ],
271
+ ]
272
+ );
273
+
203
274
$ this ->assertMatchWhere (
204
275
'test_value.value BETWEEN 0 AND 10 ' ,
205
276
[
@@ -244,9 +315,45 @@ public function testGetCustomValueValueExpression(): void
244
315
],
245
316
]
246
317
);
318
+
319
+ $ this ->assertMatchWhere (
320
+ 'test_value.value >= :pard ' ,
321
+ [
322
+ 'glue ' => 'and ' ,
323
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_object_product ' )->getId (),
324
+ 'object ' => 'custom_object ' ,
325
+ 'type ' => 'date ' ,
326
+ 'operator ' => 'gte ' ,
327
+ 'properties ' => [
328
+ 'filter ' => [
329
+ 'dateTypeMode ' => 'absolute ' ,
330
+ 'absoluteDate ' => 'yesterday ' ,
331
+ ],
332
+ ],
333
+ ],
334
+ (new DateTime ('yesterday ' ))->format ('Y-m-d ' )
335
+ );
336
+
337
+ $ this ->assertMatchWhere (
338
+ 'test_value.value <= :pare ' ,
339
+ [
340
+ 'glue ' => 'and ' ,
341
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_object_product ' )->getId (),
342
+ 'object ' => 'custom_object ' ,
343
+ 'type ' => 'datetime ' ,
344
+ 'operator ' => 'lte ' ,
345
+ 'properties ' => [
346
+ 'filter ' => [
347
+ 'dateTypeMode ' => 'absolute ' ,
348
+ 'absoluteDate ' => 'tomorrow ' ,
349
+ ],
350
+ ],
351
+ ],
352
+ (new DateTime ('tomorrow ' ))->format ('Y-m-d 23:59:59 ' )
353
+ );
247
354
}
248
355
249
- protected function assertMatchWhere (string $ expectedWhere , array $ filter ): void
356
+ protected function assertMatchWhere (string $ expectedWhere , array $ filter, ? string $ expectedValue = null ): void
250
357
{
251
358
$ unionQueryContainer = new UnionQueryContainer ();
252
359
$ qb = new QueryBuilder ($ this ->em ->getConnection ());
@@ -259,7 +366,12 @@ protected function assertMatchWhere(string $expectedWhere, array $filter): void
259
366
);
260
367
261
368
$ unionQueryContainer ->rewind ();
369
+
262
370
$ whereResponse = (string ) $ unionQueryContainer ->current ()->getQueryPart ('where ' );
371
+
263
372
$ this ->assertSame ($ expectedWhere , $ whereResponse );
373
+ if ($ expectedValue ) {
374
+ $ this ->assertSame ($ expectedValue , current ($ unionQueryContainer ->current ()->getParameters ()));
375
+ }
264
376
}
265
377
}
0 commit comments