Skip to content

Commit e981af0

Browse files
committed
Merge remote-tracking branch 'origin/MAUT-11383' into beta
2 parents c66cfbd + dedc290 commit e981af0

File tree

2 files changed

+116
-3
lines changed

2 files changed

+116
-3
lines changed

Helper/QueryFilterHelper.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function addCustomFieldValueExpressionFromSegmentFilter(
8686
ContactSegmentFilter $filter,
8787
bool $filterAlreadyNegated = false
8888
): void {
89+
$filterValue = $filter->getParameterValue();
8990
foreach ($unionQueryContainer as $segmentQueryBuilder) {
9091
$valueParameter = $this->randomParameterNameService->generateRandomParameterName();
9192
$expression = $this->getCustomValueValueExpression(
@@ -94,14 +95,14 @@ public function addCustomFieldValueExpressionFromSegmentFilter(
9495
$filter,
9596
$valueParameter,
9697
$filterAlreadyNegated,
97-
$filter->getParameterValue()
98+
$filterValue
9899
);
99100

100101
$this->addOperatorExpression(
101102
$segmentQueryBuilder,
102103
$expression,
103104
$filter->getOperator(),
104-
$filter->getParameterValue(),
105+
$filterValue,
105106
$valueParameter
106107
);
107108
}

Tests/Functional/Helper/QueryFilterHelperTest.php

+113-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MauticPlugin\CustomObjectsBundle\Tests\Functional\Helper;
66

7+
use DateTime;
78
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
89
use Mautic\LeadBundle\Segment\ContactSegmentFilterFactory;
910
use Mautic\LeadBundle\Segment\Query\QueryBuilder;
@@ -200,6 +201,76 @@ public function testGetCustomValueValueExpression(): void
200201
]
201202
);
202203

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+
203274
$this->assertMatchWhere(
204275
'test_value.value BETWEEN 0 AND 10',
205276
[
@@ -244,9 +315,45 @@ public function testGetCustomValueValueExpression(): void
244315
],
245316
]
246317
);
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+
);
247354
}
248355

249-
protected function assertMatchWhere(string $expectedWhere, array $filter): void
356+
protected function assertMatchWhere(string $expectedWhere, array $filter, ?string $expectedValue = null): void
250357
{
251358
$unionQueryContainer = new UnionQueryContainer();
252359
$qb = new QueryBuilder($this->em->getConnection());
@@ -259,7 +366,12 @@ protected function assertMatchWhere(string $expectedWhere, array $filter): void
259366
);
260367

261368
$unionQueryContainer->rewind();
369+
262370
$whereResponse = (string) $unionQueryContainer->current()->getQueryPart('where');
371+
263372
$this->assertSame($expectedWhere, $whereResponse);
373+
if ($expectedValue) {
374+
$this->assertSame($expectedValue, current($unionQueryContainer->current()->getParameters()));
375+
}
264376
}
265377
}

0 commit comments

Comments
 (0)