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 ;
@@ -244,9 +245,45 @@ public function testGetCustomValueValueExpression(): void
244
245
],
245
246
]
246
247
);
248
+
249
+ $ this ->assertMatchWhere (
250
+ 'test_value.value >= :pard ' ,
251
+ [
252
+ 'glue ' => 'and ' ,
253
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_object_product ' )->getId (),
254
+ 'object ' => 'custom_object ' ,
255
+ 'type ' => 'date ' ,
256
+ 'operator ' => 'gte ' ,
257
+ 'properties ' => [
258
+ 'filter ' => [
259
+ 'dateTypeMode ' => 'absolute ' ,
260
+ 'absoluteDate ' => 'yesterday ' ,
261
+ ],
262
+ ],
263
+ ],
264
+ (new DateTime ('yesterday ' ))->format ('Y-m-d ' )
265
+ );
266
+
267
+ $ this ->assertMatchWhere (
268
+ 'test_value.value <= :pare ' ,
269
+ [
270
+ 'glue ' => 'and ' ,
271
+ 'field ' => 'cmf_ ' .$ this ->getFixtureById ('custom_object_product ' )->getId (),
272
+ 'object ' => 'custom_object ' ,
273
+ 'type ' => 'datetime ' ,
274
+ 'operator ' => 'lte ' ,
275
+ 'properties ' => [
276
+ 'filter ' => [
277
+ 'dateTypeMode ' => 'absolute ' ,
278
+ 'absoluteDate ' => 'tomorrow ' ,
279
+ ],
280
+ ],
281
+ ],
282
+ (new DateTime ('tomorrow ' ))->format ('Y-m-d 23:59:59 ' )
283
+ );
247
284
}
248
285
249
- protected function assertMatchWhere (string $ expectedWhere , array $ filter ): void
286
+ protected function assertMatchWhere (string $ expectedWhere , array $ filter, ? string $ expectedValue = null ): void
250
287
{
251
288
$ unionQueryContainer = new UnionQueryContainer ();
252
289
$ qb = new QueryBuilder ($ this ->em ->getConnection ());
@@ -259,7 +296,12 @@ protected function assertMatchWhere(string $expectedWhere, array $filter): void
259
296
);
260
297
261
298
$ unionQueryContainer ->rewind ();
299
+
262
300
$ whereResponse = (string ) $ unionQueryContainer ->current ()->getQueryPart ('where ' );
301
+
263
302
$ this ->assertSame ($ expectedWhere , $ whereResponse );
303
+ if ($ expectedValue ) {
304
+ $ this ->assertSame ($ expectedValue , current ($ unionQueryContainer ->current ()->getParameters ()));
305
+ }
264
306
}
265
307
}
0 commit comments