Skip to content

Commit af5fabc

Browse files
committed
Merge remote-tracking branch 'upstream/2.4-develop' into no-author/catalog-checkout
2 parents c0d9a05 + 6340fa1 commit af5fabc

File tree

5,199 files changed

+48335
-47956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,199 files changed

+48335
-47956
lines changed

app/code/Magento/AdminAnalytics/Test/Unit/Condition/CanViewNotificationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testIsVisibleLoadDataFromLog($expected, $cacheResponse, $logExis
7575
/**
7676
* @return array
7777
*/
78-
public function isVisibleProvider()
78+
public static function isVisibleProvider()
7979
{
8080
return [
8181
[true, false, false],

app/code/Magento/AdminAnalytics/ViewModel/Metadata.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66

77
declare(strict_types=1);
@@ -65,7 +65,7 @@ public function __construct(
6565
Session $authSession,
6666
State $appState,
6767
ScopeConfigInterface $config,
68-
CspNonceProvider $nonceProvider = null
68+
?CspNonceProvider $nonceProvider = null
6969
) {
7070
$this->productMetadata = $productMetadata;
7171
$this->authSession = $authSession;

app/code/Magento/AdminAnalytics/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"sort-packages": true
66
},
77
"require": {
8-
"php": "~8.1.0||~8.2.0||~8.3.0",
8+
"php": "~8.2.0||~8.3.0||~8.4.0",
99
"magento/framework": "*",
1010
"magento/module-backend": "*",
1111
"magento/module-config": "*",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\AdminNotification\Block\Grid\MassAction;
9+
10+
use Magento\AdminNotification\Controller\Adminhtml\Notification\MarkAsRead;
11+
use Magento\Backend\Block\Widget\Grid\Massaction\VisibilityCheckerInterface;
12+
use Magento\Framework\AuthorizationInterface;
13+
14+
/**
15+
* Class checks if mark as read action can be displayed on massaction list
16+
*/
17+
class MarkAsReadVisibility implements VisibilityCheckerInterface
18+
{
19+
/**
20+
* @var AuthorizationInterface
21+
*/
22+
private $authorization;
23+
24+
/**
25+
* @param AuthorizationInterface $authorizationInterface
26+
*/
27+
public function __construct(AuthorizationInterface $authorizationInterface)
28+
{
29+
$this->authorization = $authorizationInterface;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function isVisible()
36+
{
37+
return $this->authorization->isAllowed(MarkAsRead::ADMIN_RESOURCE);
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\AdminNotification\Block\Grid\MassAction;
9+
10+
use Magento\AdminNotification\Controller\Adminhtml\Notification\Remove;
11+
use Magento\Backend\Block\Widget\Grid\Massaction\VisibilityCheckerInterface;
12+
use Magento\Framework\AuthorizationInterface;
13+
14+
/**
15+
* Class checks if remove action can be displayed on massaction list
16+
*/
17+
class RemoveVisibility implements VisibilityCheckerInterface
18+
{
19+
/**
20+
* @var AuthorizationInterface
21+
*/
22+
private $authorization;
23+
24+
/**
25+
* @param AuthorizationInterface $authorizationInterface
26+
*/
27+
public function __construct(AuthorizationInterface $authorizationInterface)
28+
{
29+
$this->authorization = $authorizationInterface;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function isVisible()
36+
{
37+
return $this->authorization->isAllowed(Remove::ADMIN_RESOURCE);
38+
}
39+
}

app/code/Magento/AdminNotification/Block/Grid/Renderer/Actions.php

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?php
2-
declare(strict_types=1);
3-
42
/**
5-
* Adminhtml AdminNotification Severity Renderer
6-
*
73
* Copyright © Magento, Inc. All rights reserved.
84
* See COPYING.txt for license details.
95
*/
6+
declare(strict_types=1);
107

118
namespace Magento\AdminNotification\Block\Grid\Renderer;
129

10+
use Magento\AdminNotification\Controller\Adminhtml\Notification\MarkAsRead;
11+
use Magento\AdminNotification\Controller\Adminhtml\Notification\Remove;
1312
use Magento\Backend\Block\Context;
1413
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
1514
use Magento\Framework\App\ActionInterface;
@@ -45,33 +44,41 @@ public function __construct(Context $context, Data $urlHelper, array $data = [])
4544
*/
4645
public function render(DataObject $row)
4746
{
48-
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' .
47+
$readDetailsHtml = $row->getUrl() ?
48+
'<a class="action-details" target="_blank" href="' .
4949
$this->escapeUrl($row->getUrl())
5050
. '">' .
5151
__('Read Details') . '</a>' : '';
5252

53-
$markAsReadHtml = !$row->getIsRead() ? '<a class="action-mark" href="' . $this->getUrl(
54-
'*/*/markAsRead/',
55-
['_current' => true, 'id' => $row->getNotificationId()]
56-
) . '">' . __(
57-
'Mark as Read'
58-
) . '</a>' : '';
53+
$markAsReadHtml = !$row->getIsRead()
54+
&& $this->_authorization->isAllowed(MarkAsRead::ADMIN_RESOURCE) ?
55+
'<a class="action-mark" href="' . $this->escapeUrl($this->getUrl(
56+
'*/*/markAsRead/',
57+
['_current' => true, 'id' => $row->getNotificationId()]
58+
)) . '">' . __(
59+
'Mark as Read'
60+
) . '</a>' : '';
61+
62+
$removeUrl = $this->getUrl(
63+
'*/*/remove/',
64+
[
65+
'_current' => true,
66+
'id' => $row->getNotificationId(),
67+
ActionInterface::PARAM_NAME_URL_ENCODED => $this->_urlHelper->getEncodedUrl()
68+
]
69+
);
70+
71+
$removeHtml = $this->_authorization->isAllowed(Remove::ADMIN_RESOURCE) ?
72+
'<a class="action-delete" href="'
73+
. $this->escapeUrl($removeUrl)
74+
.'" onClick="deleteConfirm('. __('\'Are you sure?\'') .', this.href); return false;">'
75+
. __('Remove') . '</a>' : '';
5976

60-
$encodedUrl = $this->_urlHelper->getEncodedUrl();
6177
return sprintf(
62-
'%s%s<a class="action-delete" href="%s" onClick="deleteConfirm(\'%s\', this.href); return false;">%s</a>',
78+
'%s%s%s',
6379
$readDetailsHtml,
6480
$markAsReadHtml,
65-
$this->getUrl(
66-
'*/*/remove/',
67-
[
68-
'_current' => true,
69-
'id' => $row->getNotificationId(),
70-
ActionInterface::PARAM_NAME_URL_ENCODED => $encodedUrl
71-
]
72-
),
73-
__('Are you sure?'),
74-
__('Remove')
81+
$removeHtml,
7582
);
7683
}
7784
}

app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\AdminNotification\Controller\Adminhtml\Notification;
79

810
use Magento\AdminNotification\Controller\Adminhtml\Notification;
@@ -16,6 +18,13 @@
1618
*/
1719
class AjaxMarkAsRead extends Notification implements HttpPostActionInterface
1820
{
21+
/**
22+
* Authorization level of a basic admin session
23+
*
24+
* @see _isAllowed()
25+
*/
26+
public const ADMIN_RESOURCE = 'Magento_AdminNotification::mark_as_read';
27+
1928
/**
2029
* @var NotificationService
2130
*/

app/code/Magento/AdminNotification/Model/Feed.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\AdminNotification\Model;
77

@@ -107,10 +107,10 @@ public function __construct(
107107
DeploymentConfig $deploymentConfig,
108108
ProductMetadataInterface $productMetadata,
109109
UrlInterface $urlBuilder,
110-
AbstractResource $resource = null,
111-
AbstractDb $resourceCollection = null,
110+
?AbstractResource $resource = null,
111+
?AbstractDb $resourceCollection = null,
112112
array $data = [],
113-
Escaper $escaper = null
113+
?Escaper $escaper = null
114114
) {
115115
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
116116
$this->_backendConfig = $backendConfig;

app/code/Magento/AdminNotification/Model/ResourceModel/System/Message/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\AdminNotification\Model\ResourceModel\System\Message;
77

@@ -40,8 +40,8 @@ public function __construct(
4040
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
4141
\Magento\Framework\Event\ManagerInterface $eventManager,
4242
\Magento\Framework\Notification\MessageList $messageList,
43-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
44-
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
43+
?\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
44+
?\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
4545
) {
4646
$this->_messageList = $messageList;
4747
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);

app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/ActionsTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\AdminNotification\Block\Grid\Renderer\Actions;
1616
use Magento\Backend\Block\Context;
1717
use Magento\Framework\DataObject;
18+
use Magento\Framework\AuthorizationInterface;
1819
use Magento\Framework\Escaper;
1920
use Magento\Framework\Url\Helper\Data;
2021
use Magento\Framework\UrlInterface;
@@ -35,16 +36,23 @@ protected function setUp(): void
3536

3637
/** @var Escaper|MockObject $escaperMock */
3738
$escaperMock = $this->createMock(Escaper::class);
38-
$escaperMock->expects($this->once())->method('escapeUrl')->willReturn('https://magento.com');
39+
$escaperMock->expects($this->atLeastOnce())->method('escapeUrl')->willReturn('https://magento.com');
40+
41+
/** @var AuthorizationInterface|MockObject $authorizationMock */
42+
$authorizationMock = $this->getMockForAbstractClass(AuthorizationInterface::class);
43+
$authorizationMock->expects($this->atLeastOnce())
44+
->method('isAllowed')
45+
->willReturn(true);
3946

4047
/** @var UrlInterface|MockObject $urlBuilder */
4148
$urlBuilder = $this->getMockForAbstractClass(UrlInterface::class);
4249
$urlBuilder->expects($this->once())->method('getUrl')->willReturn('http://magento.com');
4350

4451
/** @var Context|MockObject $contextMock */
4552
$contextMock = $this->createMock(Context::class);
46-
$contextMock->expects($this->once())->method('getEscaper')->willReturn($escaperMock);
53+
$contextMock->expects($this->atLeastOnce())->method('getEscaper')->willReturn($escaperMock);
4754
$contextMock->expects($this->once())->method('getUrlBuilder')->willReturn($urlBuilder);
55+
$contextMock->expects($this->once())->method('getAuthorization')->willReturn($authorizationMock);
4856

4957
/** @var Data|MockObject $urlHelperMock */
5058
$urlHelperMock = $this->createMock(Data::class);
@@ -65,7 +73,7 @@ public function testShouldRenderMessageWhenUrlIsGiven() : void
6573
// Ignoring Code Style at this point due to the long HEREDOC
6674
// phpcs:disable
6775
$expected = <<<HTML
68-
<a class="action-details" target="_blank" href="https://magento.com">Read Details</a><a class="action-delete" href="http://magento.com" onClick="deleteConfirm('Are you sure?', this.href); return false;">Remove</a>
76+
<a class="action-details" target="_blank" href="https://magento.com">Read Details</a><a class="action-delete" href="https://magento.com" onClick="deleteConfirm('Are you sure?', this.href); return false;">Remove</a>
6977
HTML;
7078
// phpcs:enable
7179

app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function ($initialValue, $item) use ($data) {
217217
/**
218218
* @return array
219219
*/
220-
public function checkUpdateDataProvider(): array
220+
public static function checkUpdateDataProvider(): array
221221
{
222222
return [
223223
[

app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/CacheOutdatedTest.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,37 @@ protected function setUp(): void
6060
* @param array $cacheTypes
6161
* @dataProvider getIdentityDataProvider
6262
*/
63-
public function testGetIdentity($expectedSum, $cacheTypes)
63+
public function testGetIdentity($expectedSum, $types)
6464
{
65+
$cacheType = [];
66+
foreach ($types as $type) {
67+
$cacheType[] = $type($this);
68+
}
69+
6570
$this->_cacheTypeListMock->method(
6671
'getInvalidated'
6772
)->willReturn(
68-
$cacheTypes
73+
$cacheType
6974
);
7075
$this->assertEquals($expectedSum, $this->_messageModel->getIdentity());
7176
}
7277

73-
/**
74-
* @return array
75-
*/
76-
public function getIdentityDataProvider()
78+
protected function getMockForStdClass($mockReturn)
7779
{
78-
$cacheTypeMock1 = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
80+
$cacheTypeMock = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
7981
->disableOriginalConstructor()
8082
->getMock();
81-
$cacheTypeMock1->method('getCacheType')->willReturn('Simple');
83+
$cacheTypeMock->method('getCacheType')->willReturn($mockReturn);
84+
return $cacheTypeMock;
85+
}
8286

83-
$cacheTypeMock2 = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
84-
->disableOriginalConstructor()
85-
->getMock();
86-
$cacheTypeMock2->method('getCacheType')->willReturn('Advanced');
87+
/**
88+
* @return array
89+
*/
90+
public static function getIdentityDataProvider()
91+
{
92+
$cacheTypeMock1 = static fn (self $testCase) => $testCase->getMockForStdClass('Simple');
93+
$cacheTypeMock2 = static fn (self $testCase) => $testCase->getMockForStdClass('Advanced');
8794

8895
return [
8996
['c13cfaddc2c53e8d32f59bfe89719beb', [$cacheTypeMock1]],
@@ -99,24 +106,25 @@ public function getIdentityDataProvider()
99106
*/
100107
public function testIsDisplayed($expected, $allowed, $cacheTypes)
101108
{
109+
$cacheType1 = [];
110+
foreach ($cacheTypes as $cacheType) {
111+
$cacheType1[] = $cacheType($this);
112+
}
102113
$this->_authorizationMock->expects($this->once())->method('isAllowed')->willReturn($allowed);
103114
$this->_cacheTypeListMock->method(
104115
'getInvalidated'
105116
)->willReturn(
106-
$cacheTypes
117+
$cacheType1
107118
);
108119
$this->assertEquals($expected, $this->_messageModel->isDisplayed());
109120
}
110121

111122
/**
112123
* @return array
113124
*/
114-
public function isDisplayedDataProvider()
125+
public static function isDisplayedDataProvider()
115126
{
116-
$cacheTypesMock = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
117-
->disableOriginalConstructor()
118-
->getMock();
119-
$cacheTypesMock->method('getCacheType')->willReturn('someVal');
127+
$cacheTypesMock = static fn (self $testCase) => $testCase->getMockForStdClass('someVal');
120128
$cacheTypes = [$cacheTypesMock, $cacheTypesMock];
121129
return [
122130
[false, false, []],

0 commit comments

Comments
 (0)