Skip to content

Commit eefe406

Browse files
Merge pull request #8348 from magento-l3/L3-PR-2023-09-06
L3 pr 2023 09 06
2 parents 9a58794 + 046876e commit eefe406

File tree

13 files changed

+251
-41
lines changed

13 files changed

+251
-41
lines changed

app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
class Plugin
1212
{
13+
private const MESSAGES_LIMIT = 5;
1314
/**
1415
* @var \Magento\AdminNotification\Model\System\MessageFactory
1516
*/
@@ -95,27 +96,32 @@ public function afterToArray(
9596
$this->bulkNotificationManagement->getAcknowledgedBulksByUser($userId)
9697
);
9798
$bulkMessages = [];
99+
$messagesCount = 0;
100+
$data = [];
98101
foreach ($userBulks as $bulk) {
99102
$bulkUuid = $bulk->getBulkId();
100103
if (!in_array($bulkUuid, $acknowledgedBulks)) {
101-
$details = $this->operationDetails->getDetails($bulkUuid);
102-
$text = $this->getText($details);
103-
$bulkStatus = $this->statusMapper->operationStatusToBulkSummaryStatus($bulk->getStatus());
104-
if ($bulkStatus === \Magento\Framework\Bulk\BulkSummaryInterface::IN_PROGRESS) {
105-
$text = __('%1 item(s) are currently being updated.', $details['operations_total']) . $text;
104+
if ($messagesCount < self::MESSAGES_LIMIT) {
105+
$details = $this->operationDetails->getDetails($bulkUuid);
106+
$text = $this->getText($details);
107+
$bulkStatus = $this->statusMapper->operationStatusToBulkSummaryStatus($bulk->getStatus());
108+
if ($bulkStatus === \Magento\Framework\Bulk\BulkSummaryInterface::IN_PROGRESS) {
109+
$text = __('%1 item(s) are currently being updated.', $details['operations_total']) . $text;
110+
}
111+
$data = [
112+
'data' => [
113+
'text' => __('Task "%1": ', $bulk->getDescription()) . $text,
114+
'severity' => \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR,
115+
// md5() here is not for cryptographic use.
116+
// phpcs:ignore Magento2.Security.InsecureFunction
117+
'identity' => md5('bulk' . $bulkUuid),
118+
'uuid' => $bulkUuid,
119+
'status' => $bulkStatus,
120+
'created_at' => $bulk->getStartTime()
121+
]
122+
];
123+
$messagesCount++;
106124
}
107-
$data = [
108-
'data' => [
109-
'text' => __('Task "%1": ', $bulk->getDescription()) . $text,
110-
'severity' => \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR,
111-
// md5() here is not for cryptographic use.
112-
// phpcs:ignore Magento2.Security.InsecureFunction
113-
'identity' => md5('bulk' . $bulkUuid),
114-
'uuid' => $bulkUuid,
115-
'status' => $bulkStatus,
116-
'created_at' => $bulk->getStartTime()
117-
]
118-
];
119125
$bulkMessages[] = $this->messageFactory->create($data)->toArray();
120126
}
121127
}

app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
class PluginTest extends TestCase
2929
{
30+
private const MESSAGES_LIMIT = 5;
3031
/**
3132
* @var Plugin
3233
*/
@@ -163,6 +164,60 @@ public function testAfterTo($operationDetails)
163164
$this->assertEquals(2, $result2['totalRecords']);
164165
}
165166

167+
/**
168+
* Tests that message building operations don't get called more than Plugin::MESSAGES_LIMIT times
169+
*
170+
* @return void
171+
*/
172+
public function testAfterToWithMessageLimit()
173+
{
174+
$result = ['items' =>[], 'totalRecords' => 1];
175+
$messagesCount = self::MESSAGES_LIMIT + 1;
176+
$userId = 1;
177+
$bulkUuid = 2;
178+
$bulkArray = [
179+
'status' => BulkSummaryInterface::NOT_STARTED
180+
];
181+
182+
$bulkMock = $this->getMockBuilder(BulkSummary::class)
183+
->addMethods(['getStatus'])
184+
->onlyMethods(['getBulkId', 'getDescription', 'getStartTime'])
185+
->disableOriginalConstructor()
186+
->getMock();
187+
$userBulks = array_fill(0, $messagesCount, $bulkMock);
188+
$bulkMock->expects($this->exactly($messagesCount))
189+
->method('getBulkId')->willReturn($bulkUuid);
190+
$this->operationsDetailsMock
191+
->expects($this->exactly(self::MESSAGES_LIMIT))
192+
->method('getDetails')
193+
->with($bulkUuid)
194+
->willReturn([
195+
'operations_successful' => 1,
196+
'operations_failed' => 0
197+
]);
198+
$bulkMock->expects($this->exactly(self::MESSAGES_LIMIT))
199+
->method('getDescription')->willReturn('Bulk Description');
200+
$this->messagefactoryMock->expects($this->exactly($messagesCount))
201+
->method('create')->willReturn($this->messageMock);
202+
$this->messageMock->expects($this->exactly($messagesCount))->method('toArray')->willReturn($bulkArray);
203+
$this->authorizationMock
204+
->expects($this->once())
205+
->method('isAllowed')
206+
->with($this->resourceName)
207+
->willReturn(true);
208+
$this->userContextMock->expects($this->once())->method('getUserId')->willReturn($userId);
209+
$this->bulkNotificationMock
210+
->expects($this->once())
211+
->method('getAcknowledgedBulksByUser')
212+
->with($userId)
213+
->willReturn([]);
214+
$this->statusMapper->expects($this->exactly(self::MESSAGES_LIMIT))
215+
->method('operationStatusToBulkSummaryStatus');
216+
$this->bulkStatusMock->expects($this->once())->method('getBulksByUser')->willReturn($userBulks);
217+
$result2 = $this->plugin->afterToArray($this->collectionMock, $result);
218+
$this->assertEquals($result['totalRecords'] + $messagesCount, $result2['totalRecords']);
219+
}
220+
166221
/**
167222
* @return array
168223
*/

app/code/Magento/SalesRule/Model/Quote/Discount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function collect(
158158
$address->setCartFixedRules([]);
159159
$quote->setCartFixedRules([]);
160160
foreach ($items as $item) {
161-
$this->rulesApplier->setAppliedRuleIds($item, []);
161+
$item->setAppliedRuleIds(null);
162162
if ($item->getExtensionAttributes()) {
163163
$item->getExtensionAttributes()->setDiscounts(null);
164164
}

app/code/Magento/SalesRule/Model/Rule/DataProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\SalesRule\Model\Rule;
1212

1313
/**
14-
* Class DataProvider
14+
* Data Provider for sales rule form
1515
*/
1616
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
1717
{
@@ -26,8 +26,6 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
2626
protected $loadedData;
2727

2828
/**
29-
* Core registry
30-
*
3129
* @var \Magento\Framework\Registry
3230
*/
3331
protected $coreRegistry;
@@ -103,6 +101,8 @@ public function getData()
103101
$rule->setDiscountQty($rule->getDiscountQty() * 1);
104102

105103
$this->loadedData[$rule->getId()] = $rule->getData();
104+
$labels = $rule->getStoreLabels();
105+
$this->loadedData[$rule->getId()]['store_labels'] = $labels;
106106
}
107107
$data = $this->dataPersistor->get('sale_rule');
108108
if (!empty($data)) {

app/code/Magento/SalesRule/Model/RulesApplier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public function setAppliedRuleIds(AbstractItem $item, array $appliedRuleIds)
450450
$address = $item->getAddress();
451451
$quote = $item->getQuote();
452452

453-
$item->setAppliedRuleIds(join(',', $appliedRuleIds));
453+
$item->setAppliedRuleIds($this->validatorUtility->mergeIds($item->getAppliedRuleIds(), $appliedRuleIds));
454454
$address->setAppliedRuleIds($this->validatorUtility->mergeIds($address->getAppliedRuleIds(), $appliedRuleIds));
455455
$quote->setAppliedRuleIds($this->validatorUtility->mergeIds($quote->getAppliedRuleIds(), $appliedRuleIds));
456456

app/code/Magento/SalesRule/Test/Unit/Model/Rule/DataProviderTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ protected function setUp(): void
8989
public function testGetData()
9090
{
9191
$ruleId = 42;
92-
$ruleData = ['name' => 'Sales Price Rule'];
92+
$ruleData = ['name' => 'Sales Price Rule', 'store_labels' => ['1' => 'Store Label']];
9393

9494
$ruleMock = $this->getMockBuilder(Rule::class)
95-
->addMethods(['getDiscountAmount', 'setDiscountAmount', 'getDiscountQty', 'setDiscountQty'])
96-
->onlyMethods(['load', 'getId', 'getData'])
95+
->addMethods(['getDiscountAmount', 'setDiscountAmount', 'getDiscountQty', 'setDiscountQty',])
96+
->onlyMethods(['load', 'getId', 'getData', 'getStoreLabels'])
9797
->disableOriginalConstructor()
9898
->getMock();
9999
$this->collectionMock->expects($this->once())->method('getItems')->willReturn([$ruleMock]);
@@ -105,6 +105,7 @@ public function testGetData()
105105
$ruleMock->expects($this->once())->method('setDiscountAmount')->with(50)->willReturn($ruleMock);
106106
$ruleMock->expects($this->once())->method('getDiscountQty')->willReturn(20.010);
107107
$ruleMock->expects($this->once())->method('setDiscountQty')->with(20.01)->willReturn($ruleMock);
108+
$ruleMock->expects($this->once())->method('getStoreLabels')->willReturn(["1" => "Store Label"]);
108109

109110
$this->assertEquals([$ruleId => $ruleData], $this->model->getData());
110111
// Load from object-cache the second time

app/code/Magento/SalesRule/Test/Unit/Model/RulesApplierTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,15 @@ public function testSetAppliedRuleIds()
306306
$item = $this->getPreparedItem();
307307
$ruleId = 1;
308308
$appliedRuleIds = [$ruleId => $ruleId];
309+
$previouslyAppliedRuleIds = '3';
310+
$expectedAppliedRuleIds = '3,1';
309311

310312
$item->expects($this->once())
311313
->method('setAppliedRuleIds')
312-
->with($ruleId);
313-
$item->expects($this->never())
314-
->method('getAppliedRuleIds');
314+
->with($expectedAppliedRuleIds);
315+
$item->expects($this->once())
316+
->method('getAppliedRuleIds')
317+
->willReturn($previouslyAppliedRuleIds);
315318

316319
$this->rulesApplier->setAppliedRuleIds($item, $appliedRuleIds);
317320
}

dev/tests/api-functional/framework/Magento/TestFramework/Bootstrap/WebapiDocBlock.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\TestFramework\Bootstrap;
88

99
use Magento\TestFramework\Annotation\ApiConfigFixture;
10+
use Magento\TestFramework\Annotation\AppArea;
1011
use Magento\TestFramework\Annotation\ConfigFixture;
1112
use Magento\TestFramework\Event\Transaction;
1213

@@ -28,7 +29,7 @@ protected function _getSubscribers(\Magento\TestFramework\Application $applicati
2829
{
2930
$subscribers = parent::_getSubscribers($application);
3031
foreach ($subscribers as $key => $subscriber) {
31-
if (get_class($subscriber) === ConfigFixture::class || get_class($subscriber) === Transaction::class) {
32+
if (in_array(get_class($subscriber), [ConfigFixture::class, Transaction::class, AppArea::class])) {
3233
unset($subscribers[$key]);
3334
}
3435
}
@@ -41,6 +42,7 @@ protected function _getSubscribers(\Magento\TestFramework\Application $applicati
4142
)
4243
);
4344
$subscribers[] = new ApiConfigFixture();
45+
$subscribers[] = new AppArea($application);
4446

4547
return $subscribers;
4648
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,21 +1933,18 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
19331933
$product = $this->productRepository->get($links[$itemIndex]->getSku());
19341934
$this->assertEquals($response['products']['items'][$itemIndex]['name'], $product->getName());
19351935
$this->assertEquals($response['products']['items'][$itemIndex]['type_id'], $product->getTypeId());
1936-
$categoryIds = $product->getCategoryIds();
1937-
foreach ($categoryIds as $index => $value) {
1938-
$categoryIds[$index] = (int)$value;
1939-
}
1940-
$categoryInResponse = array_map(
1941-
null,
1942-
$categoryIds,
1936+
$categoryIds = array_map('intval', $product->getCategoryIds());
1937+
$this->assertCount(count($categoryIds), $response['products']['items'][$itemIndex]['categories']);
1938+
$categoryInResponse = array_combine(
1939+
array_column($response['products']['items'][$itemIndex]['categories'], 'id'),
19431940
$response['products']['items'][$itemIndex]['categories']
19441941
);
1945-
foreach ($categoryInResponse as $key => $categoryData) {
1946-
$this->assertNotEmpty($categoryData);
1942+
foreach ($categoryIds as $categoryId) {
1943+
$this->assertArrayHasKey($categoryId, $categoryInResponse);
19471944
/** @var CategoryInterface | Category $category */
1948-
$category = $this->categoryRepository->get($categoryInResponse[$key][0]);
1945+
$category = $this->categoryRepository->get($categoryId);
19491946
$this->assertResponseFields(
1950-
$categoryInResponse[$key][1],
1947+
$categoryInResponse[$categoryId],
19511948
[
19521949
'name' => $category->getName(),
19531950
'id' => $category->getId(),

dev/tests/integration/testsuite/Magento/Config/App/Config/Type/SystemTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ public function testEnvGetValueStoreScope()
7373
$this->system->get('stores/default/abc/qrs/xyz')
7474
);
7575
}
76+
77+
protected function tearDown(): void
78+
{
79+
unset($_ENV['CONFIG__STORES__DEFAULT__ABC__QRS__XYZ']);
80+
parent::tearDown();
81+
}
7682
}

0 commit comments

Comments
 (0)