Skip to content

Commit bc61275

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop-expedited-prs
- merged with '2.3-develop-prs' branch
2 parents 0479cf9 + 3fe0a61 commit bc61275

File tree

14 files changed

+267
-47
lines changed

14 files changed

+267
-47
lines changed

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,35 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Backend\Block\Widget\Grid\Massaction;
89

10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Backend\Block\Widget;
12+
use Magento\Backend\Block\Widget\Grid\Column;
13+
use Magento\Backend\Block\Widget\Grid\ColumnSet;
914
use Magento\Backend\Block\Widget\Grid\Massaction\VisibilityCheckerInterface as VisibilityChecker;
1015
use Magento\Framework\Data\Collection\AbstractDb;
1116
use Magento\Framework\DataObject;
17+
use Magento\Framework\DB\Select;
18+
use Magento\Framework\Json\EncoderInterface;
19+
use Magento\Quote\Model\Quote;
1220

1321
/**
1422
* Grid widget massaction block
1523
*
24+
* phpcs:disable Magento2.Classes.AbstractApi
1625
* @api
17-
* @method \Magento\Quote\Model\Quote setHideFormElement(boolean $value) Hide Form element to prevent IE errors
26+
* @method Quote setHideFormElement(boolean $value) Hide Form element to prevent IE errors
1827
* @method boolean getHideFormElement()
1928
* @deprecated 100.2.0 in favour of UI component implementation
2029
* @since 100.0.2
2130
*/
22-
abstract class AbstractMassaction extends \Magento\Backend\Block\Widget
31+
abstract class AbstractMassaction extends Widget
2332
{
2433
/**
25-
* @var \Magento\Framework\Json\EncoderInterface
34+
* @var EncoderInterface
2635
*/
2736
protected $_jsonEncoder;
2837

@@ -39,13 +48,13 @@ abstract class AbstractMassaction extends \Magento\Backend\Block\Widget
3948
protected $_template = 'Magento_Backend::widget/grid/massaction.phtml';
4049

4150
/**
42-
* @param \Magento\Backend\Block\Template\Context $context
43-
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
51+
* @param Context $context
52+
* @param EncoderInterface $jsonEncoder
4453
* @param array $data
4554
*/
4655
public function __construct(
47-
\Magento\Backend\Block\Template\Context $context,
48-
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
56+
Context $context,
57+
EncoderInterface $jsonEncoder,
4958
array $data = []
5059
) {
5160
$this->_jsonEncoder = $jsonEncoder;
@@ -122,11 +131,7 @@ private function isVisible(DataObject $item)
122131
*/
123132
public function getItem($itemId)
124133
{
125-
if (isset($this->_items[$itemId])) {
126-
return $this->_items[$itemId];
127-
}
128-
129-
return null;
134+
return $this->_items[$itemId] ?? null;
130135
}
131136

132137
/**
@@ -161,7 +166,7 @@ public function getItemsJson()
161166
*/
162167
public function getCount()
163168
{
164-
return sizeof($this->_items);
169+
return count($this->_items);
165170
}
166171

167172
/**
@@ -288,11 +293,11 @@ public function getGridIdsJson()
288293

289294
if ($collection instanceof AbstractDb) {
290295
$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+
$idsSelect->reset(Select::ORDER);
297+
$idsSelect->reset(Select::LIMIT_COUNT);
298+
$idsSelect->reset(Select::LIMIT_OFFSET);
299+
$idsSelect->reset(Select::COLUMNS);
300+
$idsSelect->columns($this->getMassactionIdField());
296301
$idList = $collection->getConnection()->fetchCol($idsSelect);
297302
} else {
298303
$idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField());
@@ -358,7 +363,7 @@ public function prepareMassactionColumn()
358363
{
359364
$columnId = 'massaction';
360365
$massactionColumn = $this->getLayout()->createBlock(
361-
\Magento\Backend\Block\Widget\Grid\Column::class
366+
Column::class
362367
)->setData(
363368
[
364369
'index' => $this->getMassactionIdField(),
@@ -378,7 +383,7 @@ public function prepareMassactionColumn()
378383
$gridBlock = $this->getParentBlock();
379384
$massactionColumn->setSelected($this->getSelected())->setGrid($gridBlock)->setId($columnId);
380385

381-
/** @var $columnSetBlock \Magento\Backend\Block\Widget\Grid\ColumnSet */
386+
/** @var $columnSetBlock ColumnSet */
382387
$columnSetBlock = $gridBlock->getColumnSet();
383388
$childNames = $columnSetBlock->getChildNames();
384389
$siblingElement = count($childNames) ? current($childNames) : 0;

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

app/code/Magento/Checkout/view/frontend/web/js/model/cart/estimate-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ define([
1313
], function (quote, defaultProcessor, totalsDefaultProvider, shippingService, cartCache, customerData) {
1414
'use strict';
1515

16-
var rateProcessors = [],
17-
totalsProcessors = [],
16+
var rateProcessors = {},
17+
totalsProcessors = {},
1818

1919
/**
2020
* Estimate totals for shipping address and update shipping rates.

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define([
1010
], function (quote, defaultProcessor, customerAddressProcessor) {
1111
'use strict';
1212

13-
var processors = [];
13+
var processors = {};
1414

1515
processors.default = defaultProcessor;
1616
processors['customer-address'] = customerAddressProcessor;

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define([
1111
], function (defaultProcessor) {
1212
'use strict';
1313

14-
var processors = [];
14+
var processors = {};
1515

1616
processors['default'] = defaultProcessor;
1717

app/code/Magento/Integration/Helper/Oauth/Data.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,22 @@ public function getConsumerPostTimeout()
116116
/**
117117
* Get customer token lifetime from config.
118118
*
119-
* @return int hours
119+
* @return float hours
120120
*/
121121
public function getCustomerTokenLifetime()
122122
{
123-
$hours = (int)$this->_scopeConfig->getValue('oauth/access_token_lifetime/customer');
124-
return $hours > 0 ? $hours : 0;
123+
$hours = $this->_scopeConfig->getValue('oauth/access_token_lifetime/customer');
124+
return is_numeric($hours) && $hours > 0 ? $hours : 0;
125125
}
126126

127127
/**
128128
* Get customer token lifetime from config.
129129
*
130-
* @return int hours
130+
* @return float hours
131131
*/
132132
public function getAdminTokenLifetime()
133133
{
134-
$hours = (int)$this->_scopeConfig->getValue('oauth/access_token_lifetime/admin');
135-
return $hours > 0 ? $hours : 0;
134+
$hours = $this->_scopeConfig->getValue('oauth/access_token_lifetime/admin');
135+
return is_numeric($hours) && $hours > 0 ? $hours : 0;
136136
}
137137
}

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public function getData($themePath)
120120
}
121121
}
122122

123+
ksort($dictionary);
124+
123125
return $dictionary;
124126
}
125127

app/code/Magento/Translation/Test/Unit/Model/Js/DataProviderTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testGetData()
9090
$themePath = 'blank';
9191
$areaCode = 'adminhtml';
9292

93-
$filePaths = [['path1'], ['path2'], ['path3'], ['path4']];
93+
$filePaths = [['path1'], ['path2'], ['path4'], ['path3']];
9494

9595
$jsFilesMap = [
9696
['base', $themePath, '*', '*', [$filePaths[0]]],
@@ -111,8 +111,8 @@ public function testGetData()
111111
$contentsMap = [
112112
'content1$.mage.__("hello1")content1',
113113
'content2$.mage.__("hello2")content2',
114+
'content2$.mage.__("hello4")content4', // this value should be last after running data provider
114115
'content2$.mage.__("hello3")content3',
115-
'content2$.mage.__("hello4")content4'
116116
];
117117

118118
$translateMap = [
@@ -147,7 +147,13 @@ public function testGetData()
147147
->method('render')
148148
->willReturnMap($translateMap);
149149

150-
$this->assertEquals($expectedResult, $this->model->getData($themePath));
150+
$actualResult = $this->model->getData($themePath);
151+
$this->assertEquals($expectedResult, $actualResult);
152+
$this->assertEquals(
153+
json_encode($expectedResult),
154+
json_encode($actualResult),
155+
"Translations should be sorted by key"
156+
);
151157
}
152158

153159
/**

app/code/Magento/Webapi/Model/Authorization/TokenUserContext.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __construct(
9999
}
100100

101101
/**
102-
* {@inheritdoc}
102+
* @inheritdoc
103103
*/
104104
public function getUserId()
105105
{
@@ -108,7 +108,7 @@ public function getUserId()
108108
}
109109

110110
/**
111-
* {@inheritdoc}
111+
* @inheritdoc
112112
*/
113113
public function getUserType()
114114
{
@@ -187,6 +187,8 @@ protected function processRequest()
187187
}
188188

189189
/**
190+
* Set user data based on user type received from token data.
191+
*
190192
* @param Token $token
191193
* @return void
192194
*/

0 commit comments

Comments
 (0)