Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MAUT-11383' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
dadarya0 committed Oct 4, 2024
2 parents 526c7a7 + dedc290 commit a067aa9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Helper/QueryFilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function addCustomFieldValueExpressionFromSegmentFilter(
ContactSegmentFilter $filter,
bool $filterAlreadyNegated = false
): void {
$filterValue = $filter->getParameterValue();
foreach ($unionQueryContainer as $segmentQueryBuilder) {
$valueParameter = $this->randomParameterNameService->generateRandomParameterName();
$expression = $this->getCustomValueValueExpression(
Expand All @@ -94,14 +95,14 @@ public function addCustomFieldValueExpressionFromSegmentFilter(
$filter,
$valueParameter,
$filterAlreadyNegated,
$filter->getParameterValue()
$filterValue
);

$this->addOperatorExpression(
$segmentQueryBuilder,
$expression,
$filter->getOperator(),
$filter->getParameterValue(),
$filterValue,
$valueParameter
);
}
Expand Down
114 changes: 113 additions & 1 deletion Tests/Functional/Helper/QueryFilterHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MauticPlugin\CustomObjectsBundle\Tests\Functional\Helper;

use DateTime;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\LeadBundle\Segment\ContactSegmentFilterFactory;
use Mautic\LeadBundle\Segment\Query\QueryBuilder;
Expand Down Expand Up @@ -200,6 +201,76 @@ public function testGetCustomValueValueExpression(): void
]
);

$this->assertMatchWhere(
'test_value.value LIKE :par5',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'like',
'properties' => [
'filter' => '2024',
],
]
);

$this->assertMatchWhere(
'test_value.value REGEXP :par6',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'regexp',
'properties' => [
'filter' => '2024',
],
]
);

$this->assertMatchWhere(
'test_value.value LIKE :par7',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'startsWith',
'properties' => [
'filter' => '2024',
],
]
);

$this->assertMatchWhere(
'test_value.value LIKE :par8',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'endsWith',
'properties' => [
'filter' => '2024',
],
]
);

$this->assertMatchWhere(
'test_value.value LIKE :par9',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'contains',
'properties' => [
'filter' => '2024',
],
]
);

$this->assertMatchWhere(
'test_value.value BETWEEN 0 AND 10',
[
Expand Down Expand Up @@ -261,9 +332,45 @@ public function testGetCustomValueValueExpression(): void
],
]
);

$this->assertMatchWhere(
'test_value.value >= :pard',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_object_product')->getId(),
'object' => 'custom_object',
'type' => 'date',
'operator' => 'gte',
'properties' => [
'filter' => [
'dateTypeMode' => 'absolute',
'absoluteDate' => 'yesterday',
],
],
],
(new DateTime('yesterday'))->format('Y-m-d')
);

$this->assertMatchWhere(
'test_value.value <= :pare',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_object_product')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'lte',
'properties' => [
'filter' => [
'dateTypeMode' => 'absolute',
'absoluteDate' => 'tomorrow',
],
],
],
(new DateTime('tomorrow'))->format('Y-m-d 23:59:59')
);
}

protected function assertMatchWhere(string $expectedWhere, array $filter): void
protected function assertMatchWhere(string $expectedWhere, array $filter, ?string $expectedValue = null): void
{
$unionQueryContainer = new UnionQueryContainer();
$qb = new QueryBuilder($this->em->getConnection());
Expand All @@ -276,7 +383,12 @@ protected function assertMatchWhere(string $expectedWhere, array $filter): void
);

$unionQueryContainer->rewind();

$whereResponse = (string) $unionQueryContainer->current()->getQueryPart('where');

$this->assertSame($expectedWhere, $whereResponse);
if ($expectedValue) {
$this->assertSame($expectedValue, current($unionQueryContainer->current()->getParameters()));
}
}
}

0 comments on commit a067aa9

Please sign in to comment.