|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -/** |
8 |
| - * Test class for \Magento\Backend\Block\Widget\Grid\Massaction |
9 |
| - */ |
10 | 7 | namespace Magento\Backend\Test\Unit\Block\Widget\Grid;
|
11 | 8 |
|
12 | 9 | use Magento\Backend\Block\Widget\Grid\Massaction\VisibilityCheckerInterface as VisibilityChecker;
|
13 | 10 | 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; |
14 | 14 |
|
| 15 | +/** |
| 16 | + * Test class for \Magento\Backend\Block\Widget\Grid\Massaction |
| 17 | + * |
| 18 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 19 | + */ |
15 | 20 | class MassactionTest extends \PHPUnit\Framework\TestCase
|
16 | 21 | {
|
17 | 22 | /**
|
@@ -54,6 +59,21 @@ class MassactionTest extends \PHPUnit\Framework\TestCase
|
54 | 59 | */
|
55 | 60 | private $visibilityCheckerMock;
|
56 | 61 |
|
| 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 | + |
57 | 77 | protected function setUp()
|
58 | 78 | {
|
59 | 79 | $this->_gridMock = $this->getMockBuilder(\Magento\Backend\Block\Widget\Grid::class)
|
@@ -97,6 +117,18 @@ protected function setUp()
|
97 | 117 | ->setMethods(['isAllowed'])
|
98 | 118 | ->getMock();
|
99 | 119 |
|
| 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 | + |
100 | 132 | $arguments = [
|
101 | 133 | 'layout' => $this->_layoutMock,
|
102 | 134 | 'request' => $this->_requestMock,
|
@@ -269,6 +301,41 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
|
269 | 301 | $this->assertEmpty($this->_block->getGridIdsJson());
|
270 | 302 | }
|
271 | 303 |
|
| 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 | + |
272 | 339 | /**
|
273 | 340 | * @param string $itemId
|
274 | 341 | * @param array|\Magento\Framework\DataObject $item
|
|
0 commit comments