Skip to content

Commit a50615a

Browse files
Merge branch '2.4-develop' into fix-38331
2 parents 569db19 + c893121 commit a50615a

File tree

1,542 files changed

+27497
-8309
lines changed

Some content is hidden

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

1,542 files changed

+27497
-8309
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CloseAllDialogBoxes
2+
SelectAdminUsageSetting

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
namespace Magento\AdminAnalytics\ViewModel;
1010

1111
use Magento\Config\Model\Config\Backend\Admin\Custom;
12+
use Magento\Csp\Helper\CspNonceProvider;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\App\ObjectManager;
1315
use Magento\Framework\App\ProductMetadataInterface;
1416
use Magento\Backend\Model\Auth\Session;
1517
use Magento\Framework\App\State;
@@ -21,6 +23,11 @@
2123
*/
2224
class Metadata implements ArgumentInterface
2325
{
26+
/**
27+
* @var string
28+
*/
29+
private $nonce;
30+
2431
/**
2532
* @var State
2633
*/
@@ -41,22 +48,33 @@ class Metadata implements ArgumentInterface
4148
*/
4249
private $config;
4350

51+
/**
52+
* @var CspNonceProvider
53+
*/
54+
private $nonceProvider;
55+
4456
/**
4557
* @param ProductMetadataInterface $productMetadata
4658
* @param Session $authSession
4759
* @param State $appState
4860
* @param ScopeConfigInterface $config
61+
* @param CspNonceProvider|null $nonceProvider
4962
*/
5063
public function __construct(
5164
ProductMetadataInterface $productMetadata,
5265
Session $authSession,
5366
State $appState,
54-
ScopeConfigInterface $config
67+
ScopeConfigInterface $config,
68+
CspNonceProvider $nonceProvider = null
5569
) {
5670
$this->productMetadata = $productMetadata;
5771
$this->authSession = $authSession;
5872
$this->appState = $appState;
5973
$this->config = $config;
74+
75+
$this->nonceProvider = $nonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
76+
77+
$this->nonce = $this->nonceProvider->generateNonce();
6078
}
6179

6280
/**
@@ -156,4 +174,14 @@ public function getCurrentUserRoleName(): string
156174
{
157175
return $this->authSession->getUser()->getRole()->getRoleName();
158176
}
177+
178+
/**
179+
* Get a random nonce for each request.
180+
*
181+
* @return string
182+
*/
183+
public function getNonce(): string
184+
{
185+
return $this->nonce;
186+
}
159187
}

app/code/Magento/AdminAnalytics/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"magento/module-config": "*",
1212
"magento/module-store": "*",
1313
"magento/module-ui": "*",
14-
"magento/module-release-notification": "*"
14+
"magento/module-release-notification": "*",
15+
"magento/module-csp": "*"
1516
},
1617
"type": "magento2-module",
1718
"license": [

app/code/Magento/AdminAnalytics/view/adminhtml/templates/tracking.phtml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
9+
* @var \Magento\Framework\Escaper $escaper
910
*/
1011
?>
1112

@@ -22,18 +23,25 @@
2223
<?php
2324
/** @var \Magento\AdminAnalytics\ViewModel\Metadata $metadata */
2425
$metadata = $block->getMetadata();
26+
$nonce = $escaper->escapeJs($metadata->getNonce());
2527
$scriptString = '
2628
var adminAnalyticsMetadata = {
27-
"secure_base_url": "' . $block->escapeJs($metadata->getSecureBaseUrlForScope()) . '",
28-
"version": "' . $block->escapeJs($metadata->getMagentoVersion()) . '",
29-
"product_edition": "' . $block->escapeJs($metadata->getProductEdition()) . '",
30-
"user": "' . $block->escapeJs($metadata->getCurrentUser()) . '",
31-
"mode": "' . $block->escapeJs($metadata->getMode()) . '",
32-
"store_name_default": "' . $block->escapeJs($metadata->getStoreNameForScope()) . '",
33-
"admin_user_created": "' . $block->escapeJs($metadata->getCurrentUserCreatedDate()) . '",
34-
"admin_user_logdate": "' . $block->escapeJs($metadata->getCurrentUserLogDate()) . '",
35-
"admin_user_role_name": "' . $block->escapeJs($metadata->getCurrentUserRoleName()) . '"
29+
"secure_base_url": "' . $escaper->escapeJs($metadata->getSecureBaseUrlForScope()) . '",
30+
"version": "' . $escaper->escapeJs($metadata->getMagentoVersion()) . '",
31+
"product_edition": "' . $escaper->escapeJs($metadata->getProductEdition()) . '",
32+
"user": "' . $escaper->escapeJs($metadata->getCurrentUser()) . '",
33+
"mode": "' . $escaper->escapeJs($metadata->getMode()) . '",
34+
"store_name_default": "' . $escaper->escapeJs($metadata->getStoreNameForScope()) . '",
35+
"admin_user_created": "' . $escaper->escapeJs($metadata->getCurrentUserCreatedDate()) . '",
36+
"admin_user_logdate": "' . $escaper->escapeJs($metadata->getCurrentUserLogDate()) . '",
37+
"admin_user_role_name": "' . $escaper->escapeJs($metadata->getCurrentUserRoleName()) . '"
3638
};
39+
40+
var digitalData = {
41+
"nonce": "' . $nonce . '"
42+
};
43+
44+
var cspNonce = "' . $nonce . '";
3745
';
3846
?>
3947
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); ?>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testShouldRenderSeverity() : void
4646
/** @var Column|MockObject $columnMock */
4747
$columnMock = $this->getMockBuilder(Column::class)
4848
->disableOriginalConstructor()
49-
->setMethods(['getIndex'])
49+
->addMethods(['getIndex'])
5050
->getMock();
5151
$columnMock->expects($this->exactly(5))->method('getIndex')->willReturn('index');
5252
$this->sut->setColumn($columnMock);

app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Magento\AdminNotification\Block\ToolbarEntry;
1414
use Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread;
15+
use Magento\Directory\Helper\Data as DirectoryHelper;
16+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1517
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1618
use PHPUnit\Framework\TestCase;
1719

@@ -26,6 +28,17 @@ class ToolbarEntryTest extends TestCase
2628
protected function _getBlockInstance($unreadNotifications)
2729
{
2830
$objectManagerHelper = new ObjectManager($this);
31+
$objects = [
32+
[
33+
JsonHelper::class,
34+
$this->createMock(JsonHelper::class)
35+
],
36+
[
37+
DirectoryHelper::class,
38+
$this->createMock(DirectoryHelper::class)
39+
]
40+
];
41+
$objectManagerHelper->prepareObjectManager($objects);
2942
// mock collection of unread notifications
3043
$notificationList = $this->createPartialMock(
3144
Unread::class,
@@ -52,6 +65,18 @@ public function testGetLatestUnreadNotifications()
5265
{
5366
$helper = new ObjectManager($this);
5467

68+
$objects = [
69+
[
70+
JsonHelper::class,
71+
$this->createMock(JsonHelper::class)
72+
],
73+
[
74+
DirectoryHelper::class,
75+
$this->createMock(DirectoryHelper::class)
76+
]
77+
];
78+
$helper->prepareObjectManager($objects);
79+
5580
// 1. Create mocks
5681
$notificationList = $this->createMock(Unread::class);
5782

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ protected function setUp(): void
225225
'initWebsites',
226226
'initCategories'
227227
];
228+
$mockAddMethods = [
229+
'_headerColumns'
230+
];
228231
$mockMethods = array_merge($constructorMethods, [
229232
'_customHeadersMapping',
230233
'_prepareEntityCollection',
231234
'_getEntityCollection',
232235
'getWriter',
233236
'getExportData',
234-
'_headerColumns',
235237
'_customFieldsMapping',
236238
'getItemsPerPage',
237239
'paginateCollection',
@@ -243,7 +245,8 @@ protected function setUp(): void
243245
$this->advancedPricing = $this->getMockBuilder(
244246
AdvancedPricing::class
245247
)
246-
->setMethods($mockMethods)
248+
->addMethods($mockAddMethods)
249+
->onlyMethods($mockMethods)
247250
->disableOriginalConstructor()
248251
->getMock();
249252
foreach ($constructorMethods as $method) {

app/code/Magento/AdvancedSearch/Model/DataProvider/AutocompleteSuggestions.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
<?php
2-
/************************************************************************
3-
*
2+
/**
43
* Copyright 2023 Adobe
54
* All Rights Reserved.
6-
*
7-
* NOTICE: All information contained herein is, and remains
8-
* the property of Adobe and its suppliers, if any. The intellectual
9-
* and technical concepts contained herein are proprietary to Adobe
10-
* and its suppliers and are protected by all applicable intellectual
11-
* property laws, including trade secret and copyright laws.
12-
* Dissemination of this information or reproduction of this material
13-
* is strictly forbidden unless prior written permission is obtained
14-
* from Adobe.
15-
* ***********************************************************************
165
*/
176
declare(strict_types=1);
187

app/code/Magento/AdvancedSearch/Test/Unit/Model/Client/ClientResolverTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ public function testCreate(): void
6767
$clientOptionsMock = $this->getMockForAbstractClass(ClientOptionsInterface::class);
6868

6969
$this->objectManager->expects($this->exactly(2))->method('create')
70-
->withConsecutive(
71-
[$this->equalTo('engineFactoryClass')],
72-
[$this->equalTo('engineOptionClass')]
73-
)
74-
->willReturnOnConsecutiveCalls(
75-
$factoryMock,
76-
$clientOptionsMock
77-
);
70+
->willReturnCallback(function ($className) use ($factoryMock, $clientOptionsMock) {
71+
if ($className == 'engineFactoryClass') {
72+
return $factoryMock;
73+
} elseif ($className == 'engineOptionClass') {
74+
return $clientOptionsMock;
75+
}
76+
});
7877

7978
$clientOptionsMock->expects($this->once())->method('prepareClientOptions')
8079
->with([])

app/code/Magento/AdvancedSearch/Test/Unit/Model/DataProvider/AutocompleteSuggestionsTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
<?php
2-
/************************************************************************
3-
*
2+
/**
43
* Copyright 2023 Adobe
54
* All Rights Reserved.
6-
*
7-
* NOTICE: All information contained herein is, and remains
8-
* the property of Adobe and its suppliers, if any. The intellectual
9-
* and technical concepts contained herein are proprietary to Adobe
10-
* and its suppliers and are protected by all applicable intellectual
11-
* property laws, including trade secret and copyright laws.
12-
* Dissemination of this information or reproduction of this material
13-
* is strictly forbidden unless prior written permission is obtained
14-
* from Adobe.
15-
* ***********************************************************************
165
*/
176
declare(strict_types=1);
187

app/code/Magento/Amqp/Test/Unit/Setup/ConfigOptionsListTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ protected function setUp(): void
5858
$this->objectManager = new ObjectManager($this);
5959
$this->connectionValidatorMock = $this->getMockBuilder(ConnectionValidator::class)
6060
->disableOriginalConstructor()
61-
->setMethods([])
6261
->getMock();
6362

6463
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
6564
->disableOriginalConstructor()
66-
->setMethods([])
65+
->onlyMethods([])
6766
->getMock();
6867

6968
$this->model = $this->objectManager->getObject(
@@ -171,7 +170,7 @@ public function testValidateNoOptions()
171170
/**
172171
* @return array
173172
*/
174-
public function getCreateConfigDataProvider()
173+
public static function getCreateConfigDataProvider()
175174
{
176175
return [
177176
[

app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/SubscriptionStatusLabelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ protected function setUp(): void
4949
$this->subscriptionStatusProviderMock = $this->createMock(SubscriptionStatusProvider::class);
5050
$this->contextMock = $this->createMock(Context::class);
5151
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
52-
->setMethods(['getComment', 'getElementHtml'])
52+
->addMethods(['getComment'])
53+
->onlyMethods(['getElementHtml'])
5354
->disableOriginalConstructor()
5455
->getMock();
5556

app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/VerticalTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class VerticalTest extends TestCase
4141
protected function setUp(): void
4242
{
4343
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
44-
->setMethods(['getComment', 'getLabel', 'getHint', 'getElementHtml'])
44+
->addMethods(['getComment', 'getLabel', 'getHint'])
45+
->onlyMethods(['getElementHtml'])
4546
->disableOriginalConstructor()
4647
->getMock();
4748

app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ private function addFinalOutputAsserts(bool $isExecuted = true)
100100
$this->flagManagerMock
101101
->expects($this->exactly(2 * $isExecuted))
102102
->method('deleteFlag')
103-
->withConsecutive(
104-
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE],
105-
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE]
106-
);
103+
->willReturnCallback(fn($param) => match ([$param]) {
104+
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE] => $this->flagManagerMock,
105+
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE] => $this->flagManagerMock
106+
});
107107
$this->configWriterMock
108108
->expects($this->exactly((int)$isExecuted))
109109
->method('delete')
@@ -143,7 +143,7 @@ public function testExecuteWithEmptyReverseCounter($counterData)
143143
*
144144
* @return array
145145
*/
146-
public function executeWithEmptyReverseCounterDataProvider()
146+
public static function executeWithEmptyReverseCounterDataProvider()
147147
{
148148
return [
149149
[null],
@@ -189,7 +189,7 @@ public function testExecuteRegularScenario(
189189
/**
190190
* @return array
191191
*/
192-
public function executeRegularScenarioDataProvider()
192+
public static function executeRegularScenarioDataProvider()
193193
{
194194
return [
195195
'The last attempt with command execution result False' => [

app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Baseurl/SubscriptionUpdateHandlerTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ public function testTokenAndPreviousBaseUrlExist()
126126
$this->flagManagerMock
127127
->expects($this->once())
128128
->method('saveFlag')
129-
->withConsecutive(
130-
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue],
131-
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, $url]
132-
);
129+
->willReturnCallback(function ($arg1, $arg2) use ($url) {
130+
if ($arg1 == SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE
131+
&& $arg2 == $this->attemptsInitValue) {
132+
return true;
133+
} elseif ($arg1 == SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE && $arg2 == $url) {
134+
return true;
135+
}
136+
});
137+
133138
$this->configWriterMock
134139
->expects($this->once())
135140
->method('save')
@@ -160,10 +165,14 @@ public function testTokenExistAndWithoutPreviousBaseUrl()
160165
$this->flagManagerMock
161166
->expects($this->exactly(2))
162167
->method('saveFlag')
163-
->withConsecutive(
164-
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, $url],
165-
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue]
166-
);
168+
->willReturnCallback(function ($arg1, $arg2) use ($url) {
169+
if ($arg1 == SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE
170+
&& $arg2 == $this->attemptsInitValue) {
171+
return true;
172+
} elseif ($arg1 == SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE && $arg2 == $url) {
173+
return true;
174+
}
175+
});
167176
$this->configWriterMock
168177
->expects($this->once())
169178
->method('save')

0 commit comments

Comments
 (0)