Skip to content

Commit 6310002

Browse files
author
Maksym Savich
committed
MAGETWO-35833: [GitHub] Magento\Framework\Data\Collection\Filesystem filter issue #1160
- CR fixes
1 parent c7d6ac3 commit 6310002

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

lib/internal/Magento/Framework/Data/Collection/Filesystem.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,10 @@ public function getAllIds()
698698
*/
699699
public function filterCallbackLike($field, $filterValue, $row)
700700
{
701-
$filterValueRegex = '(.*?)' . preg_quote(trim(stripslashes($filterValue), '%\''), '/') . '(.*?)';
701+
$filterValue = trim(stripslashes($filterValue), '\'');
702+
$filterValue = trim($filterValue, '%');
703+
$filterValueRegex = '(.*?)' . preg_quote($filterValue, '/') . '(.*?)';
704+
702705
return (bool)preg_match("/^{$filterValueRegex}\$/i", $row[$field]);
703706
}
704707

lib/internal/Magento/Framework/Data/Test/Unit/Collection/FilesystemTest.php

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,67 @@ public function setUp()
1717
$this->model = $objectManager->getObject('Magento\Framework\Data\Collection\Filesystem');
1818
}
1919

20-
public function testFilterCallbackLike()
20+
/**
21+
* @param $field
22+
* @param $filterValue
23+
* @param $row
24+
* @param $expected
25+
*
26+
* @dataProvider testFilterCallbackLikeDataProvider
27+
*/
28+
public function testFilterCallbackLike($field, $filterValue, $row, $expected)
2129
{
22-
$field = 'field';
23-
$row = [$field => 'beginning_filter_target_end',];
24-
$filterValueSuccess = new \Zend_Db_Expr('%filter_target%');
25-
$filterValueFailure = new \Zend_Db_Expr('%not_found_in_the_row%');
30+
$filterValue = new \Zend_Db_Expr($filterValue);
2631

27-
$this->assertTrue($this->model->filterCallbackLike($field, $filterValueSuccess, $row));
28-
$this->assertFalse($this->model->filterCallbackLike($field, $filterValueFailure, $row));
32+
$this->assertEquals($expected, $this->model->filterCallbackLike($field, $filterValue, $row));
33+
}
34+
35+
/**
36+
* @return array
37+
*/
38+
public function testFilterCallbackLikeDataProvider()
39+
{
40+
$field = 'field';
41+
$testValue = '\'\'\'test\'\'\'Filter\'\'\'Value\'\'\'';
42+
return [
43+
[$field, '\'%test%\'', [$field => $testValue,], true],
44+
[$field, '%\'test%', [$field => $testValue,], true],
45+
[$field, '%\'test\'%', [$field => $testValue,], true],
46+
[$field, '%\'\'test%', [$field => $testValue,], true],
47+
[$field, '%\'\'test\'\'%', [$field => $testValue,], true],
48+
[$field, '%\'\'\'test%', [$field => $testValue,], true],
49+
[$field, '%\'\'\'test\'\'\'%', [$field => $testValue,], true],
50+
[$field, '%\'\'\'\'test%', [$field => $testValue,], false],
51+
52+
[$field, '\'%Value%\'', [$field => $testValue,], true],
53+
[$field, '%Value\'%', [$field => $testValue,], true],
54+
[$field, '%\'Value\'%', [$field => $testValue,], true],
55+
[$field, '%Value\'\'%', [$field => $testValue,], true],
56+
[$field, '%\'\'Value\'\'%', [$field => $testValue,], true],
57+
[$field, '%Value\'\'\'%', [$field => $testValue,], true],
58+
[$field, '%\'\'\'Value\'\'\'%', [$field => $testValue,], true],
59+
[$field, '%Value%\'\'\'\'%', [$field => $testValue,], false],
60+
61+
[$field, '\'%\'\'\'test\'\'\'Filter\'\'\'Value\'\'\'%\'', [$field => $testValue,], true],
62+
[$field, '\'\'\'%\'\'\'test\'\'\'Filter\'\'\'Value\'\'\'%\'\'\'', [$field => $testValue,], true],
63+
[$field, '%test\'\'\'Filter\'\'\'Value%', [$field => $testValue,], true],
64+
[$field, '%test\'\'\'Filter\'\'\'Value\'\'\'%', [$field => $testValue,], true],
65+
[$field, '%\'\'\'test\'\'\'Filter\'\'\'Value%', [$field => $testValue,], true],
66+
[$field, '%\'\'\'Filter\'\'\'Value\'\'\'%', [$field => $testValue,], true],
67+
[$field, '%Filter\'\'\'Value\'\'\'%', [$field => $testValue,], true],
68+
[$field, '%\'\'\'Filter\'\'\'Value%', [$field => $testValue,], true],
69+
[$field, '%Filter\'\'\'Value%', [$field => $testValue,], true],
70+
[$field, '%Filter\'\'\'\'Value%', [$field => $testValue,], false],
71+
72+
[$field, '\'%\'\'\'Filter\'\'\'%\'', [$field => $testValue,], true],
73+
[$field, '%Filter\'\'\'%', [$field => $testValue,], true],
74+
[$field, '%\'\'\'Filter%', [$field => $testValue,], true],
75+
[$field, '%\'Filter%', [$field => $testValue,], true],
76+
[$field, '%Filter\'%', [$field => $testValue,], true],
77+
[$field, '%Filter%', [$field => $testValue,], true],
78+
[$field, '%Filter\'\'\'\'%', [$field => $testValue,], false],
79+
80+
[$field, '\'%no_match_value%\'', [$field => $testValue,], false],
81+
];
2982
}
3083
}

0 commit comments

Comments
 (0)