Skip to content

Commit 6297fe8

Browse files
author
Oleksii Korshenko
authored
ENGCOM-591: [Forwardport] Grid filtration doesn't work for mysql special characters #13784
2 parents cac6fb4 + deb760f commit 6297fe8

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

app/code/Magento/Ui/Component/Filters/Type/Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function prepare()
6565
protected function applyFilter()
6666
{
6767
if (isset($this->filterData[$this->getName()])) {
68-
$value = $this->filterData[$this->getName()];
68+
$value = str_replace(['%', '_'], ['\%', '\_'], $this->filterData[$this->getName()]);
6969

7070
if (!empty($value)) {
7171
$filter = $this->filterBuilder->setConditionType('like')

app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,49 @@ public function testPrepare($name, $filterData, $expectedCondition)
111111
->method('addComponentDefinition')
112112
->with(Input::NAME, ['extends' => Input::NAME]);
113113
$this->contextMock->expects($this->any())
114-
->method('getRequestParam')
115-
->with(UiContext::FILTER_VAR)
114+
->method('getFiltersParams')
116115
->willReturn($filterData);
117116
$dataProvider = $this->getMockForAbstractClass(
118117
\Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface::class,
119118
[],
120119
'',
121120
false
122121
);
122+
123123
$this->contextMock->expects($this->any())
124124
->method('getDataProvider')
125125
->willReturn($dataProvider);
126-
if ($expectedCondition !== null) {
127-
$dataProvider->expects($this->any())
128-
->method('addFilter')
129-
->with($expectedCondition, $name);
130-
}
131126

132127
$this->uiComponentFactory->expects($this->any())
133128
->method('create')
134129
->with($name, Input::COMPONENT, ['context' => $this->contextMock])
135130
->willReturn($uiComponent);
136131

132+
if ($expectedCondition !== null) {
133+
$this->filterBuilderMock->expects($this->once())
134+
->method('setConditionType')
135+
->with('like')
136+
->willReturnSelf();
137+
138+
$this->filterBuilderMock->expects($this->once())
139+
->method('setField')
140+
->with($name)
141+
->willReturnSelf();
142+
143+
$this->filterBuilderMock->expects($this->once())
144+
->method('setValue')
145+
->with($expectedCondition['like'])
146+
->willReturnSelf();
147+
148+
$filterMock = $this->getMockBuilder(\Magento\Framework\Api\Filter::class)
149+
->disableOriginalConstructor()
150+
->getMock();
151+
152+
$this->filterBuilderMock->expects($this->once())
153+
->method('create')
154+
->willReturn($filterMock);
155+
}
156+
137157
$date = new Input(
138158
$this->contextMock,
139159
$this->uiComponentFactory,
@@ -160,7 +180,12 @@ public function getPrepareDataProvider()
160180
[
161181
'test_date',
162182
['test_date' => 'some_value'],
163-
['like' => '%some_value%'],
183+
['like' => '%some\_value%'],
184+
],
185+
[
186+
'test_date',
187+
['test_date' => '%'],
188+
['like' => '%\%%'],
164189
],
165190
];
166191
}

0 commit comments

Comments
 (0)