Skip to content

Commit 467455c

Browse files
authored
MAUT-11383 : incorrect date value being calculating when the segment filter value is "yesterday" and operator is "gt" for date field (#359)
* Fix custom parameter date issue * add more test case
1 parent 6ad2360 commit 467455c

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-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

+43-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;
@@ -244,9 +245,45 @@ public function testGetCustomValueValueExpression(): void
244245
],
245246
]
246247
);
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+
);
247284
}
248285

249-
protected function assertMatchWhere(string $expectedWhere, array $filter): void
286+
protected function assertMatchWhere(string $expectedWhere, array $filter, ?string $expectedValue = null): void
250287
{
251288
$unionQueryContainer = new UnionQueryContainer();
252289
$qb = new QueryBuilder($this->em->getConnection());
@@ -259,7 +296,12 @@ protected function assertMatchWhere(string $expectedWhere, array $filter): void
259296
);
260297

261298
$unionQueryContainer->rewind();
299+
262300
$whereResponse = (string) $unionQueryContainer->current()->getQueryPart('where');
301+
263302
$this->assertSame($expectedWhere, $whereResponse);
303+
if ($expectedValue) {
304+
$this->assertSame($expectedValue, current($unionQueryContainer->current()->getParameters()));
305+
}
264306
}
265307
}

0 commit comments

Comments
 (0)