@@ -62,6 +62,11 @@ class FilterTest extends \PHPUnit_Framework_TestCase
62
62
*/
63
63
private $ uiComponentMock ;
64
64
65
+ /**
66
+ * \PHPUnit_Framework_MockObject_MockObject
67
+ */
68
+ private $ contextMock ;
69
+
65
70
/**
66
71
* Set up
67
72
*/
@@ -74,7 +79,7 @@ protected function setUp()
74
79
$ this ->dataProviderMock = $ this ->getMock (DataProviderInterface::class);
75
80
$ this ->uiComponentMock = $ this ->getMock (UiComponentInterface::class);
76
81
$ this ->abstractDbMock = $ this ->getMock (AbstractDb::class, [], [], '' , false );
77
- $ contextMock = $ this ->getMock (ContextInterface::class);
82
+ $ this -> contextMock = $ this ->getMock (ContextInterface::class);
78
83
$ this ->searchResultMock = $ this ->getMock (SearchResultInterface::class);
79
84
$ uiComponentMockTwo = $ this ->getMock (UiComponentInterface::class);
80
85
$ this ->filter = $ this ->objectManager ->getObject (
@@ -96,18 +101,7 @@ protected function setUp()
96
101
->willReturn ([]);
97
102
$ this ->uiComponentMock ->expects ($ this ->any ())
98
103
->method ('getContext ' )
99
- ->willReturn ($ contextMock );
100
- $ contextMock ->expects ($ this ->any ())
101
- ->method ('getDataProvider ' )
102
- ->willReturn ($ this ->dataProviderMock );
103
- $ this ->dataProviderMock ->expects ($ this ->any ())
104
- ->method ('setLimit ' );
105
- $ this ->dataProviderMock ->expects ($ this ->any ())
106
- ->method ('searchResultMock ' )
107
- ->willReturn ($ this ->searchResultMock );
108
- $ this ->searchResultMock ->expects ($ this ->any ())
109
- ->method ('getAllIds ' )
110
- ->willReturn ([]);
104
+ ->willReturn ($ this ->contextMock );
111
105
}
112
106
113
107
/**
@@ -144,6 +138,18 @@ public function applySelectionOnTargetProviderDataProvider()
144
138
*/
145
139
public function testApplySelectionOnTargetProviderException ()
146
140
{
141
+ $ this ->contextMock ->expects ($ this ->any ())
142
+ ->method ('getDataProvider ' )
143
+ ->willReturn ($ this ->dataProviderMock );
144
+ $ this ->dataProviderMock ->expects ($ this ->any ())
145
+ ->method ('setLimit ' );
146
+ $ this ->dataProviderMock ->expects ($ this ->any ())
147
+ ->method ('getSearchResult ' )
148
+ ->willReturn ($ this ->searchResultMock );
149
+ $ this ->searchResultMock ->expects ($ this ->any ())
150
+ ->method ('getItems ' )
151
+ ->willReturn ([]);
152
+
147
153
$ filterMock = $ this ->getMock (ApiFilter::class, [], [], '' , false );
148
154
$ this ->filterBuilderMock ->expects ($ this ->any ())
149
155
->method ('setConditionType ' )
@@ -170,7 +176,7 @@ public function testApplySelectionOnTargetProviderException()
170
176
}
171
177
172
178
/**
173
- * Run test for getCollection method
179
+ * Run test for getCollection method with SearchResultInterface
174
180
*
175
181
* @param int[]|bool $selectedIds
176
182
* @param int[]|bool $excludedIds
@@ -196,6 +202,50 @@ public function testGetCollection($selectedIds, $excludedIds, $filterExpected, $
196
202
$ this ->assertEquals ($ this ->abstractDbMock , $ this ->filter ->getCollection ($ this ->abstractDbMock ));
197
203
}
198
204
205
+ /**
206
+ * Run test for getCollection method with collection
207
+ *
208
+ * @param int[]|bool $selectedIds
209
+ * @param int[]|bool $excludedIds
210
+ * @param int $filterExpected
211
+ * @param string $conditionExpected
212
+ * @dataProvider applySelectionOnTargetProviderDataProvider
213
+ */
214
+ public function testGetCollectionWithCollection ($ selectedIds , $ excludedIds , $ filterExpected , $ conditionExpected )
215
+ {
216
+ $ this ->dataProviderMock = $ this ->getMock (
217
+ \Magento \Ui \DataProvider \AbstractDataProvider::class,
218
+ [],
219
+ [],
220
+ '' ,
221
+ false
222
+ );
223
+ $ this ->contextMock ->expects ($ this ->any ())
224
+ ->method ('getDataProvider ' )
225
+ ->willReturn ($ this ->dataProviderMock );
226
+ $ this ->dataProviderMock ->expects ($ this ->any ())
227
+ ->method ('getAllIds ' )
228
+ ->willReturn ([1 , 2 , 3 ]);
229
+
230
+ $ this ->setUpApplySelection ($ selectedIds , $ excludedIds , $ filterExpected , $ conditionExpected );
231
+
232
+ $ this ->requestMock ->expects ($ this ->at (4 ))
233
+ ->method ('getParam ' )
234
+ ->with ('namespace ' )
235
+ ->willReturn ('' );
236
+ $ this ->requestMock ->expects ($ this ->at (2 ))
237
+ ->method ('getParam ' )
238
+ ->with (Filter::SELECTED_PARAM )
239
+ ->willReturn ($ selectedIds );
240
+ $ this ->requestMock ->expects ($ this ->at (3 ))
241
+ ->method ('getParam ' )
242
+ ->with (Filter::EXCLUDED_PARAM )
243
+ ->willReturn ($ excludedIds );
244
+ $ this ->assertEquals ($ this ->abstractDbMock , $ this ->filter ->getCollection ($ this ->abstractDbMock ));
245
+ }
246
+
247
+
248
+
199
249
/**
200
250
* This tests the method prepareComponent()
201
251
*/
@@ -221,6 +271,9 @@ public function testGetComponent()
221
271
*/
222
272
public function testGetComponentRefererUrlIsNotNull ()
223
273
{
274
+ $ this ->contextMock ->expects ($ this ->any ())
275
+ ->method ('getDataProvider ' )
276
+ ->willReturn ($ this ->dataProviderMock );
224
277
$ returnArray = [
225
278
'referer_url ' => 'referer_url '
226
279
];
@@ -235,6 +288,9 @@ public function testGetComponentRefererUrlIsNotNull()
235
288
*/
236
289
public function testGetComponentRefererUrlIsNull ()
237
290
{
291
+ $ this ->contextMock ->expects ($ this ->any ())
292
+ ->method ('getDataProvider ' )
293
+ ->willReturn ($ this ->dataProviderMock );
238
294
$ this ->assertNull ($ this ->filter ->getComponentRefererUrl ());
239
295
}
240
296
@@ -248,6 +304,17 @@ public function testGetComponentRefererUrlIsNull()
248
304
*/
249
305
private function setUpApplySelection ($ selectedIds , $ excludedIds , $ filterExpected , $ conditionExpected )
250
306
{
307
+ $ this ->contextMock ->expects ($ this ->any ())
308
+ ->method ('getDataProvider ' )
309
+ ->willReturn ($ this ->dataProviderMock );
310
+ $ this ->dataProviderMock ->expects ($ this ->any ())
311
+ ->method ('setLimit ' );
312
+ $ this ->dataProviderMock ->expects ($ this ->any ())
313
+ ->method ('getSearchResult ' )
314
+ ->willReturn ($ this ->searchResultMock );
315
+ $ this ->searchResultMock ->expects ($ this ->any ())
316
+ ->method ('getItems ' )
317
+ ->willReturn ([new \Magento \Framework \DataObject (['id ' => 1 ])]);
251
318
$ filterMock = $ this ->getMock (ApiFilter::class, [], [], '' , false );
252
319
$ this ->requestMock ->expects ($ this ->at (0 ))
253
320
->method ('getParam ' )
@@ -260,6 +327,7 @@ private function setUpApplySelection($selectedIds, $excludedIds, $filterExpected
260
327
$ this ->dataProviderMock ->expects ($ this ->exactly ($ filterExpected ))
261
328
->method ('addFilter ' )
262
329
->with ($ filterMock );
330
+
263
331
$ this ->filterBuilderMock ->expects ($ this ->exactly ($ filterExpected ))
264
332
->method ('setConditionType ' )
265
333
->with ($ conditionExpected )
0 commit comments