diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index cbcb33ffcca04..9cc060ae58172 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -65,7 +65,7 @@ public function prepare() protected function applyFilter() { if (isset($this->filterData[$this->getName()])) { - $value = $this->filterData[$this->getName()]; + $value = str_replace(['%', '_'], ['\%', '\_'], $this->filterData[$this->getName()]); if (!empty($value)) { $filter = $this->filterBuilder->setConditionType('like') diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php index ed571f44dd6e9..d814fdcd153da 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php @@ -111,8 +111,7 @@ public function testPrepare($name, $filterData, $expectedCondition) ->method('addComponentDefinition') ->with(Input::NAME, ['extends' => Input::NAME]); $this->contextMock->expects($this->any()) - ->method('getRequestParam') - ->with(UiContext::FILTER_VAR) + ->method('getFiltersParams') ->willReturn($filterData); $dataProvider = $this->getMockForAbstractClass( \Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface::class, @@ -120,20 +119,41 @@ public function testPrepare($name, $filterData, $expectedCondition) '', false ); + $this->contextMock->expects($this->any()) ->method('getDataProvider') ->willReturn($dataProvider); - if ($expectedCondition !== null) { - $dataProvider->expects($this->any()) - ->method('addFilter') - ->with($expectedCondition, $name); - } $this->uiComponentFactory->expects($this->any()) ->method('create') ->with($name, Input::COMPONENT, ['context' => $this->contextMock]) ->willReturn($uiComponent); + if ($expectedCondition !== null) { + $this->filterBuilderMock->expects($this->once()) + ->method('setConditionType') + ->with('like') + ->willReturnSelf(); + + $this->filterBuilderMock->expects($this->once()) + ->method('setField') + ->with($name) + ->willReturnSelf(); + + $this->filterBuilderMock->expects($this->once()) + ->method('setValue') + ->with($expectedCondition['like']) + ->willReturnSelf(); + + $filterMock = $this->getMockBuilder(\Magento\Framework\Api\Filter::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->filterBuilderMock->expects($this->once()) + ->method('create') + ->willReturn($filterMock); + } + $date = new Input( $this->contextMock, $this->uiComponentFactory, @@ -160,7 +180,12 @@ public function getPrepareDataProvider() [ 'test_date', ['test_date' => 'some_value'], - ['like' => '%some_value%'], + ['like' => '%some\_value%'], + ], + [ + 'test_date', + ['test_date' => '%'], + ['like' => '%\%%'], ], ]; }