Skip to content

Commit ab04d7e

Browse files
#23452: Added unit test.
1 parent a6cec0a commit ab04d7e

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Test class for \Magento\Backend\Block\Widget\Grid\Massaction
9-
*/
107
namespace Magento\Backend\Test\Unit\Block\Widget\Grid;
118

129
use Magento\Backend\Block\Widget\Grid\Massaction\VisibilityCheckerInterface as VisibilityChecker;
1310
use Magento\Framework\Authorization;
11+
use Magento\Framework\Data\Collection\AbstractDb as Collection;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\DB\Select;
1414

15+
/**
16+
* Test class for \Magento\Backend\Block\Widget\Grid\Massaction
17+
*
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
*/
1520
class MassactionTest extends \PHPUnit\Framework\TestCase
1621
{
1722
/**
@@ -54,6 +59,21 @@ class MassactionTest extends \PHPUnit\Framework\TestCase
5459
*/
5560
private $visibilityCheckerMock;
5661

62+
/**
63+
* @var Collection|\PHPUnit\Framework\MockObject\MockObject
64+
*/
65+
private $gridCollectionMock;
66+
67+
/**
68+
* @var Select|\PHPUnit\Framework\MockObject\MockObject
69+
*/
70+
private $gridCollectionSelectMock;
71+
72+
/**
73+
* @var AdapterInterface|\PHPUnit\Framework\MockObject\MockObject
74+
*/
75+
private $connectionMock;
76+
5777
protected function setUp()
5878
{
5979
$this->_gridMock = $this->getMockBuilder(\Magento\Backend\Block\Widget\Grid::class)
@@ -97,6 +117,18 @@ protected function setUp()
97117
->setMethods(['isAllowed'])
98118
->getMock();
99119

120+
$this->gridCollectionMock = $this->createMock(Collection::class);
121+
$this->gridCollectionSelectMock = $this->createMock(Select::class);
122+
$this->connectionMock = $this->createMock(AdapterInterface::class);
123+
124+
$this->gridCollectionMock->expects($this->any())
125+
->method('getSelect')
126+
->willReturn($this->gridCollectionSelectMock);
127+
128+
$this->gridCollectionMock->expects($this->any())
129+
->method('getConnection')
130+
->willReturn($this->connectionMock);
131+
100132
$arguments = [
101133
'layout' => $this->_layoutMock,
102134
'request' => $this->_requestMock,
@@ -269,6 +301,41 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
269301
$this->assertEmpty($this->_block->getGridIdsJson());
270302
}
271303

304+
/**
305+
* Test for getGridIdsJson when select all functionality flag set to true.
306+
*/
307+
public function testGetGridIdsJsonWithUseSelectAll()
308+
{
309+
$this->_block->setUseSelectAll(true);
310+
311+
$this->_gridMock->expects($this->once())
312+
->method('getCollection')
313+
->willReturn($this->gridCollectionMock);
314+
315+
$this->gridCollectionSelectMock->expects($this->exactly(4))
316+
->method('reset')
317+
->withConsecutive(
318+
[Select::ORDER],
319+
[Select::LIMIT_COUNT],
320+
[Select::LIMIT_OFFSET],
321+
[Select::COLUMNS]
322+
);
323+
324+
$this->gridCollectionSelectMock->expects($this->once())
325+
->method('columns')
326+
->with('test_id');
327+
328+
$this->connectionMock->expects($this->once())
329+
->method('fetchCol')
330+
->with($this->gridCollectionSelectMock)
331+
->willReturn([1, 2, 3]);
332+
333+
$this->assertEquals(
334+
'1,2,3',
335+
$this->_block->getGridIdsJson()
336+
);
337+
}
338+
272339
/**
273340
* @param string $itemId
274341
* @param array|\Magento\Framework\DataObject $item

0 commit comments

Comments
 (0)