Skip to content

Commit db1b924

Browse files
committed
MAGETWO-66402: Backward Incompatible Change
- fix unit test
1 parent 64b0820 commit db1b924

File tree

1 file changed

+82
-14
lines changed

1 file changed

+82
-14
lines changed

app/code/Magento/Ui/Test/Unit/Component/MassAction/FilterTest.php

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class FilterTest extends \PHPUnit_Framework_TestCase
6262
*/
6363
private $uiComponentMock;
6464

65+
/**
66+
* \PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
private $contextMock;
69+
6570
/**
6671
* Set up
6772
*/
@@ -74,7 +79,7 @@ protected function setUp()
7479
$this->dataProviderMock = $this->getMock(DataProviderInterface::class);
7580
$this->uiComponentMock = $this->getMock(UiComponentInterface::class);
7681
$this->abstractDbMock = $this->getMock(AbstractDb::class, [], [], '', false);
77-
$contextMock = $this->getMock(ContextInterface::class);
82+
$this->contextMock = $this->getMock(ContextInterface::class);
7883
$this->searchResultMock = $this->getMock(SearchResultInterface::class);
7984
$uiComponentMockTwo = $this->getMock(UiComponentInterface::class);
8085
$this->filter = $this->objectManager->getObject(
@@ -96,18 +101,7 @@ protected function setUp()
96101
->willReturn([]);
97102
$this->uiComponentMock->expects($this->any())
98103
->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);
111105
}
112106

113107
/**
@@ -144,6 +138,18 @@ public function applySelectionOnTargetProviderDataProvider()
144138
*/
145139
public function testApplySelectionOnTargetProviderException()
146140
{
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+
147153
$filterMock = $this->getMock(ApiFilter::class, [], [], '', false);
148154
$this->filterBuilderMock->expects($this->any())
149155
->method('setConditionType')
@@ -170,7 +176,7 @@ public function testApplySelectionOnTargetProviderException()
170176
}
171177

172178
/**
173-
* Run test for getCollection method
179+
* Run test for getCollection method with SearchResultInterface
174180
*
175181
* @param int[]|bool $selectedIds
176182
* @param int[]|bool $excludedIds
@@ -196,6 +202,50 @@ public function testGetCollection($selectedIds, $excludedIds, $filterExpected, $
196202
$this->assertEquals($this->abstractDbMock, $this->filter->getCollection($this->abstractDbMock));
197203
}
198204

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+
199249
/**
200250
* This tests the method prepareComponent()
201251
*/
@@ -221,6 +271,9 @@ public function testGetComponent()
221271
*/
222272
public function testGetComponentRefererUrlIsNotNull()
223273
{
274+
$this->contextMock->expects($this->any())
275+
->method('getDataProvider')
276+
->willReturn($this->dataProviderMock);
224277
$returnArray = [
225278
'referer_url' => 'referer_url'
226279
];
@@ -235,6 +288,9 @@ public function testGetComponentRefererUrlIsNotNull()
235288
*/
236289
public function testGetComponentRefererUrlIsNull()
237290
{
291+
$this->contextMock->expects($this->any())
292+
->method('getDataProvider')
293+
->willReturn($this->dataProviderMock);
238294
$this->assertNull($this->filter->getComponentRefererUrl());
239295
}
240296

@@ -248,6 +304,17 @@ public function testGetComponentRefererUrlIsNull()
248304
*/
249305
private function setUpApplySelection($selectedIds, $excludedIds, $filterExpected, $conditionExpected)
250306
{
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])]);
251318
$filterMock = $this->getMock(ApiFilter::class, [], [], '', false);
252319
$this->requestMock->expects($this->at(0))
253320
->method('getParam')
@@ -260,6 +327,7 @@ private function setUpApplySelection($selectedIds, $excludedIds, $filterExpected
260327
$this->dataProviderMock->expects($this->exactly($filterExpected))
261328
->method('addFilter')
262329
->with($filterMock);
330+
263331
$this->filterBuilderMock->expects($this->exactly($filterExpected))
264332
->method('setConditionType')
265333
->with($conditionExpected)

0 commit comments

Comments
 (0)