Skip to content

Commit 6fb5c6f

Browse files
Indrani SonawaneIndrani Sonawane
Indrani Sonawane
authored and
Indrani Sonawane
committed
Merge branch 'cleanup-old-php-versions-code' of https://github.com/hostep/magento2 into cleanup-old-php-versions-code
2 parents ffdf6fd + 2efa430 commit 6fb5c6f

File tree

2,153 files changed

+15705
-11065
lines changed

Some content is hidden

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

2,153 files changed

+15705
-11065
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],
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/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, []],

app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/Media/Synchronization/ErrorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testIsDisplayed($expectedFirstRun, $data)
8282
/**
8383
* @return array
8484
*/
85-
public function isDisplayedDataProvider()
85+
public static function isDisplayedDataProvider()
8686
{
8787
return [
8888
[true, ['has_errors' => 1]],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testIsDisplayed($expectedResult, $cached, $response)
8585
/**
8686
* @return array
8787
*/
88-
public function isDisplayedDataProvider()
88+
public static function isDisplayedDataProvider()
8989
{
9090
return [
9191
'cached_case' => [false, true, ''],

app/code/Magento/AdminNotification/view/adminhtml/layout/adminhtml_notification_block.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@
6161
<item name="mark_as_read" xsi:type="array">
6262
<item name="label" xsi:type="string" translate="true">Mark as Read</item>
6363
<item name="url" xsi:type="string">*/*/massMarkAsRead</item>
64+
<item name="visible" xsi:type="object">Magento\AdminNotification\Block\Grid\MassAction\MarkAsReadVisibility</item>
6465
</item>
6566
<item name="remove" xsi:type="array">
6667
<item name="label" xsi:type="string" translate="true">Remove</item>
6768
<item name="url" xsi:type="string">*/*/massRemove</item>
6869
<item name="confirm" xsi:type="string" translate="true">Are you sure?</item>
70+
<item name="visible" xsi:type="object">Magento\AdminNotification\Block\Grid\MassAction\RemoveVisibility</item>
6971
</item>
7072
</argument>
7173
</arguments>

0 commit comments

Comments
 (0)