Skip to content

Commit 20d1ff7

Browse files
committed
Merge branch 'MAGETWO-98617' of https://github.com/magento-mpi/magento2ce into pr_2019_03_20
2 parents b88fc33 + f5653ab commit 20d1ff7

File tree

4 files changed

+118
-123
lines changed

4 files changed

+118
-123
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,25 +282,23 @@ public function getGridIdsJson()
282282
if (!$this->getUseSelectAll()) {
283283
return '';
284284
}
285-
/** @var \Magento\Framework\Data\Collection $allIdsCollection */
286-
$allIdsCollection = clone $this->getParentBlock()->getCollection();
287285

288-
if ($this->getMassactionIdField()) {
289-
$massActionIdField = $this->getMassactionIdField();
286+
/** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */
287+
$collection = clone $this->getParentBlock()->getCollection();
288+
289+
if ($collection instanceof AbstractDb) {
290+
$idsSelect = clone $collection->getSelect();
291+
$idsSelect->reset(\Magento\Framework\DB\Select::ORDER);
292+
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
293+
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
294+
$idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
295+
$idsSelect->columns($this->getMassactionIdField(), 'main_table');
296+
$idList = $collection->getConnection()->fetchCol($idsSelect);
290297
} else {
291-
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
298+
$idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField());
292299
}
293300

294-
if ($allIdsCollection instanceof AbstractDb) {
295-
$allIdsCollection->getSelect()->limit();
296-
$allIdsCollection->clear();
297-
}
298-
299-
$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
300-
if (!empty($gridIds)) {
301-
return join(",", $gridIds);
302-
}
303-
return '';
301+
return implode(',', $idList);
304302
}
305303

306304
/**

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -269,62 +269,6 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
269269
$this->assertEmpty($this->_block->getGridIdsJson());
270270
}
271271

272-
/**
273-
* @param array $items
274-
* @param string $result
275-
*
276-
* @dataProvider dataProviderGetGridIdsJsonWithUseSelectAll
277-
*/
278-
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
279-
{
280-
$this->_block->setUseSelectAll(true);
281-
282-
if ($this->_block->getMassactionIdField()) {
283-
$massActionIdField = $this->_block->getMassactionIdField();
284-
} else {
285-
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
286-
}
287-
288-
$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
289-
->disableOriginalConstructor()
290-
->getMock();
291-
292-
$this->_gridMock->expects($this->once())
293-
->method('getCollection')
294-
->willReturn($collectionMock);
295-
$collectionMock->expects($this->once())
296-
->method('setPageSize')
297-
->with(0)
298-
->willReturnSelf();
299-
$collectionMock->expects($this->once())
300-
->method('getColumnValues')
301-
->with($massActionIdField)
302-
->willReturn($items);
303-
304-
$this->assertEquals($result, $this->_block->getGridIdsJson());
305-
}
306-
307-
/**
308-
* @return array
309-
*/
310-
public function dataProviderGetGridIdsJsonWithUseSelectAll()
311-
{
312-
return [
313-
[
314-
[],
315-
'',
316-
],
317-
[
318-
[1],
319-
'1',
320-
],
321-
[
322-
[1, 2, 3],
323-
'1,2,3',
324-
],
325-
];
326-
}
327-
328272
/**
329273
* @param string $itemId
330274
* @param array|\Magento\Framework\DataObject $item

dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Grid/MassactionTest.php

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -87,41 +87,6 @@ public function testMassactionDefaultValues()
8787
$this->assertFalse($blockEmpty->isAvailable());
8888
}
8989

90-
public function testGetJavaScript()
91-
{
92-
$this->loadLayout();
93-
94-
$javascript = $this->_block->getJavaScript();
95-
96-
$expectedItemFirst = '#"option_id1":{"label":"Option One",' .
97-
'"url":"http:\\\/\\\/localhost\\\/index\.php\\\/(?:key\\\/([\w\d]+)\\\/)?",' .
98-
'"complete":"Test","id":"option_id1"}#';
99-
$this->assertRegExp($expectedItemFirst, $javascript);
100-
101-
$expectedItemSecond = '#"option_id2":{"label":"Option Two",' .
102-
'"url":"http:\\\/\\\/localhost\\\/index\.php\\\/(?:key\\\/([\w\d]+)\\\/)?",' .
103-
'"confirm":"Are you sure\?","id":"option_id2"}#';
104-
$this->assertRegExp($expectedItemSecond, $javascript);
105-
}
106-
107-
public function testGetJavaScriptWithAddedItem()
108-
{
109-
$this->loadLayout();
110-
111-
$input = [
112-
'id' => 'option_id3',
113-
'label' => 'Option Three',
114-
'url' => '*/*/option3',
115-
'block_name' => 'admin.test.grid.massaction.option3',
116-
];
117-
$expected = '#"option_id3":{"id":"option_id3","label":"Option Three",' .
118-
'"url":"http:\\\/\\\/localhost\\\/index\.php\\\/(?:key\\\/([\w\d]+)\\\/)?",' .
119-
'"block_name":"admin.test.grid.massaction.option3"}#';
120-
121-
$this->_block->addItem($input['id'], $input);
122-
$this->assertRegExp($expected, $this->_block->getJavaScript());
123-
}
124-
12590
/**
12691
* @param string $mageMode
12792
* @param int $expectedCount
@@ -213,21 +178,4 @@ public function getItemsDataProvider()
213178
]
214179
];
215180
}
216-
217-
public function testGridContainsMassactionColumn()
218-
{
219-
$this->loadLayout();
220-
$this->_layout->getBlock('admin.test.grid')->toHtml();
221-
222-
$gridMassactionColumn = $this->_layout->getBlock('admin.test.grid')
223-
->getColumnSet()
224-
->getChildBlock('massaction');
225-
226-
$this->assertNotNull($gridMassactionColumn, 'Massaction column does not exist in the grid column set');
227-
$this->assertInstanceOf(
228-
\Magento\Backend\Block\Widget\Grid\Column::class,
229-
$gridMassactionColumn,
230-
'Massaction column is not an instance of \Magento\Backend\Block\Widget\Column'
231-
);
232-
}
233181
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Newsletter\Block\Adminhtml\Subscriber;
9+
10+
/**
11+
* @magentoAppArea adminhtml
12+
* @magentoDbIsolation enabled
13+
*
14+
* @see \Magento\Newsletter\Block\Adminhtml\Subscriber\Grid
15+
*/
16+
class GridTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* @var null|\Magento\Framework\ObjectManagerInterface
20+
*/
21+
private $objectManager = null;
22+
/**
23+
* @var null|\Magento\Framework\View\LayoutInterface
24+
*/
25+
private $layout = null;
26+
27+
/**
28+
* Set up layout.
29+
*/
30+
protected function setUp()
31+
{
32+
parent::setUp();
33+
34+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
35+
36+
$this->layout = $this->objectManager->create(\Magento\Framework\View\LayoutInterface::class);
37+
$this->layout->getUpdate()->load('newsletter_subscriber_grid');
38+
$this->layout->generateXml();
39+
$this->layout->generateElements();
40+
}
41+
42+
/**
43+
* Check if mass action block exists.
44+
*/
45+
public function testMassActionBlockExists()
46+
{
47+
$this->assertNotFalse(
48+
$this->getMassActionBlock(),
49+
'Mass action block does not exist in the grid, or it name was changed.'
50+
);
51+
}
52+
53+
/**
54+
* Check if mass action id field is correct.
55+
*/
56+
public function testMassActionFieldIdIsCorrect()
57+
{
58+
$this->assertEquals(
59+
'subscriber_id',
60+
$this->getMassActionBlock()->getMassactionIdField(),
61+
'Mass action id field is incorrect.'
62+
);
63+
}
64+
65+
/**
66+
* Check if function returns correct result.
67+
*
68+
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
69+
*/
70+
public function testMassActionBlockContainsCorrectIdList()
71+
{
72+
$this->assertEquals(
73+
implode(',', $this->getAllSubscriberIdList()),
74+
$this->getMassActionBlock()->getGridIdsJson(),
75+
'Function returns incorrect result.'
76+
);
77+
}
78+
79+
/**
80+
* Retrieve mass action block.
81+
*
82+
* @return bool|\Magento\Backend\Block\Widget\Grid\Massaction
83+
*/
84+
private function getMassActionBlock()
85+
{
86+
return $this->layout->getBlock('adminhtml.newslettrer.subscriber.grid.massaction');
87+
}
88+
89+
/**
90+
* Retrieve list of id of all subscribers.
91+
*
92+
* @return array
93+
*/
94+
private function getAllSubscriberIdList()
95+
{
96+
/** @var \Magento\Framework\App\ResourceConnection $resourceConnection */
97+
$resourceConnection = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class);
98+
$select = $resourceConnection->getConnection()
99+
->select()
100+
->from($resourceConnection->getTableName('newsletter_subscriber'))
101+
->columns(['subscriber_id' => 'subscriber_id']);
102+
103+
return $resourceConnection->getConnection()->fetchCol($select);
104+
}
105+
}

0 commit comments

Comments
 (0)