Skip to content

Commit da850b9

Browse files
Raj MohanRaj Mohan
authored andcommitted
AC-12092_PHPUnit10: Merge 2.4-develop
2 parents 9ee118c + d01ee51 commit da850b9

File tree

312 files changed

+13238
-2103
lines changed

Some content is hidden

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

312 files changed

+13238
-2103
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,15 @@ public function testSaveAndReplaceAdvancedPricesAddRowErrorCall(): void
333333
'bunch'
334334
]
335335
];
336+
$count = 0;
336337
$this->dataSourceModel
337338
->method('getNextUniqueBunch')
338-
->willReturnOnConsecutiveCalls($testBunch);
339+
->willReturnCallback(function () use (&$count, $testBunch) {
340+
if ($count == 0) {
341+
$count++;
342+
return $testBunch;
343+
}
344+
});
339345
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(false);
340346
$this->advancedPricing->method('saveProductPrices')->willReturnSelf();
341347

@@ -405,9 +411,15 @@ public function testSaveAndReplaceAdvancedPricesAppendBehaviourDataAndCalls(
405411
$advancedPricing
406412
->method('getBehavior')
407413
->willReturn(Import::BEHAVIOR_APPEND);
414+
$count = 0;
408415
$this->dataSourceModel
409416
->method('getNextUniqueBunch')
410-
->willReturnOnConsecutiveCalls($data);
417+
->willReturnCallback(function () use (&$count, $data) {
418+
if ($count == 0) {
419+
$count++;
420+
return $data;
421+
}
422+
});
411423
$advancedPricing->method('validateRow')->willReturn(true);
412424

413425
$advancedPricing->method('getCustomerGroupId')->willReturnMap(
@@ -529,9 +541,16 @@ public function testSaveAndReplaceAdvancedPricesReplaceBehaviourInternalCalls():
529541
$this->advancedPricing->method('getBehavior')->willReturn(
530542
Import::BEHAVIOR_REPLACE
531543
);
544+
545+
$count = 0;
532546
$this->dataSourceModel
533547
->method('getNextUniqueBunch')
534-
->willReturnOnConsecutiveCalls($data);
548+
->willReturnCallback(function () use (&$count, $data) {
549+
if ($count == 0) {
550+
$count++;
551+
return $data;
552+
}
553+
});
535554
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(true);
536555

537556
$this->advancedPricing
@@ -582,9 +601,15 @@ public function testDeleteAdvancedPricingFormListSkuToDelete(): void
582601
]
583602
];
584603

604+
$count = 0;
585605
$this->dataSourceModel
586606
->method('getNextUniqueBunch')
587-
->willReturnOnConsecutiveCalls($data);
607+
->willReturnCallback(function () use (&$count, $data) {
608+
if ($count == 0) {
609+
$count++;
610+
return $data;
611+
}
612+
});
588613
$this->advancedPricing->method('validateRow')->willReturn(true);
589614
$expectedSkuList = ['sku value'];
590615
$this->advancedPricing

app/code/Magento/Backend/view/adminhtml/layout/default.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<body>
1616
<attribute name="id" value="html-body"/>
1717
<block name="require.js" class="Magento\Backend\Block\Page\RequireJs" template="Magento_Backend::page/js/require_js.phtml"/>
18+
<block class="Magento\Framework\View\Element\Template" name="head.critical" as="head.critical" template="Magento_Backend::page/container.phtml"/>
1819
<block class="Magento\Framework\View\Element\Template" name="head.additional" template="Magento_Backend::page/container.phtml"/>
1920
<referenceContainer name="global.notices">
2021
<block class="Magento\Backend\Block\Page\Notices" name="global_notices" as="global_notices" template="Magento_Backend::page/notices.phtml"/>

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,9 +1179,11 @@ function ($key) use ($optionCollection, $selectionCollection) {
11791179

11801180
$this->arrayUtility->expects($this->once())->method('flatten')->willReturn($bundleOptions);
11811181

1182-
$selectionCollection
1183-
->method('getItems')
1184-
->willReturnOnConsecutiveCalls([$selection], []);
1182+
$callCount = 0;
1183+
$selectionCollection->method('getItems')
1184+
->willReturnCallback(function () use (&$callCount, $selection) {
1185+
return $callCount++ === 0 ? [$selection] : [];
1186+
});
11851187
$selectionCollection
11861188
->method('getSize')
11871189
->willReturnOnConsecutiveCalls(1, 0);
@@ -1362,6 +1364,7 @@ public function testPrepareForCartAdvancedParentClassReturnString(): void
13621364

13631365
/**
13641366
* @return void
1367+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
13651368
*/
13661369
public function testPrepareForCartAdvancedAllRequiredOption(): void
13671370
{
@@ -1452,12 +1455,14 @@ function ($key) use ($optionCollection) {
14521455
$buyRequest->expects($this->once())
14531456
->method('getBundleOption')
14541457
->willReturn([3 => 5]);
1458+
$callCount = 0;
14551459
$option->method('getId')
1456-
->willReturnOnConsecutiveCalls(3);
1460+
->willReturnCallback(function () use (&$callCount) {
1461+
return $callCount++ === 0 ? 3 : '';
1462+
});
14571463
$option->expects($this->once())
14581464
->method('getRequired')
14591465
->willReturn(true);
1460-
14611466
$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
14621467
$this->assertEquals('Please select all required options.', $result);
14631468
}
@@ -1630,9 +1635,11 @@ public function testGetSkuWithoutType(): void
16301635
$selectionMock->expects(($this->any()))
16311636
->method('getItemByColumnValue')
16321637
->willReturn($selectionItemMock);
1633-
$selectionItemMock
1634-
->method('getEntityId')
1635-
->willReturnOnConsecutiveCalls(1);
1638+
$callCount = 0;
1639+
$selectionItemMock->method('getEntityId')
1640+
->willReturnCallback(function () use (&$callCount) {
1641+
return $callCount++ === 0 ? 1 : '';
1642+
});
16361643
$selectionItemMock->expects($this->once())
16371644
->method('getSku')
16381645
->willReturn($itemSku);
Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* 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+
* ************************************************************************
516
*/
617
declare(strict_types=1);
718

819
namespace Magento\BundleGraphQl\Model\Resolver;
920

21+
use Magento\Bundle\Model\Product\Price;
1022
use Magento\Catalog\Model\Product;
1123
use Magento\Framework\Exception\LocalizedException;
24+
use Magento\Framework\Exception\NoSuchEntityException;
1225
use Magento\Framework\GraphQl\Config\Element\Field;
1326
use Magento\Framework\GraphQl\Query\ResolverInterface;
1427
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
28+
use Magento\Quote\Api\CartRepositoryInterface;
29+
use Magento\Quote\Api\Data\CartItemInterface;
1530

1631
class BundlePriceDetails implements ResolverInterface
1732
{
33+
/**
34+
* BundlePriceDetails Constructor
35+
*
36+
* @param CartRepositoryInterface $cartRepository
37+
*/
38+
public function __construct(
39+
private readonly CartRepositoryInterface $cartRepository
40+
) {
41+
}
42+
1843
/**
1944
* @inheritdoc
2045
*/
@@ -25,14 +50,44 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
2550
}
2651
/** @var Product $product */
2752
$product = $value['model'];
28-
2953
$price = $product->getPrice();
3054
$finalPrice = $product->getFinalPrice();
3155
$discountPercentage = ($price) ? (100 - (($finalPrice * 100) / $price)) : 0;
56+
if ((int)$product->getPriceType() === Price::PRICE_TYPE_DYNAMIC && isset($value['cart_item'])) {
57+
$discountPercentage = $this->getDiscountPercentageForBundleProduct($value['cart_item']);
58+
}
3259
return [
3360
'main_price' => $price,
3461
'main_final_price' => $finalPrice,
3562
'discount_percentage' => $discountPercentage
3663
];
3764
}
65+
66+
/**
67+
* Calculate discount percentage for bundle product with dynamic pricing enabled
68+
*
69+
* @param CartItemInterface $cartItem
70+
* @return float
71+
* @throws NoSuchEntityException
72+
*/
73+
private function getDiscountPercentageForBundleProduct(CartItemInterface $cartItem): float
74+
{
75+
if (empty($cartItem->getAppliedRuleIds())) {
76+
return 0;
77+
}
78+
$itemAmount = 0;
79+
$discountAmount = 0;
80+
$cart = $this->cartRepository->get($cartItem->getQuoteId());
81+
foreach ($cart->getAllItems() as $item) {
82+
if ($item->getParentItemId() == $cartItem->getId()) {
83+
$itemAmount += $item->getPrice();
84+
$discountAmount += $item->getDiscountAmount();
85+
}
86+
}
87+
if ($itemAmount && $discountAmount) {
88+
return ($discountAmount / $itemAmount) * 100;
89+
}
90+
91+
return 0;
92+
}
3893
}

app/code/Magento/BundleImportExport/Test/Unit/Model/Import/Product/Type/BundleTest.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Framework\EntityManager\MetadataPool;
2323
use Magento\ImportExport\Model\Import;
2424
use Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase;
25+
use Magento\Store\Model\StoreManagerInterface;
2526
use PHPUnit\Framework\MockObject\MockObject;
2627

2728
/**
@@ -208,6 +209,19 @@ protected function setUp(): void
208209
->disableOriginalConstructor()
209210
->onlyMethods(['getScope'])
210211
->getMockForAbstractClass();
212+
213+
$objects = [
214+
[
215+
Bundle\RelationsDataSaver::class,
216+
$this->createMock(Bundle\RelationsDataSaver::class)
217+
],
218+
[
219+
StoreManagerInterface::class,
220+
$this->createMock(StoreManagerInterface::class)
221+
]
222+
];
223+
$this->objectManagerHelper->prepareObjectManager($objects);
224+
211225
$this->bundle = $this->objectManagerHelper->getObject(
212226
Bundle::class,
213227
[
@@ -248,9 +262,12 @@ public function testSaveData(array $skus, array $bunch, bool $allowImport): void
248262
{
249263
$this->entityModel->expects($this->any())->method('getBehavior')->willReturn(Import::BEHAVIOR_APPEND);
250264
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn($skus['newSku']);
265+
$callCount = 0;
251266
$this->entityModel
252267
->method('getNextBunch')
253-
->willReturnOnConsecutiveCalls([$bunch]);
268+
->willReturnCallback(function () use (&$callCount, $bunch) {
269+
return $callCount++ === 0 ? [$bunch] : null;
270+
});
254271
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn($allowImport);
255272
$scope = $this->getMockBuilder(ScopeInterface::class)->getMockForAbstractClass();
256273
$this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope);
@@ -395,13 +412,12 @@ public function testSaveDataDelete(): void
395412
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn([
396413
'sku' => ['sku' => 'sku', 'entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'bundle']
397414
]);
415+
$callCount = 0;
398416
$this->entityModel
399417
->method('getNextBunch')
400-
->willReturnOnConsecutiveCalls(
401-
[
402-
['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name']
403-
]
404-
);
418+
->willReturnCallback(function () use (&$callCount) {
419+
return $callCount++ === 0 ? [['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name']] : null;
420+
});
405421
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn(true);
406422
$select = $this->createMock(Select::class);
407423
$this->connection->expects($this->any())->method('select')->willReturn($select);

app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
*/
66
namespace Magento\Catalog\Block\Rss\Product;
77

8-
use Magento\Framework\App\Rss\DataProviderInterface;
8+
use Magento\Framework\App\Rss\DataProviderInterface as DProviderInterface;
9+
use Magento\Framework\DataObject\IdentityInterface as IdInterface;
910

10-
/**
11-
* Class NewProducts
12-
* @package Magento\Catalog\Block\Rss\Product
13-
*/
14-
class NewProducts extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface
11+
class NewProducts extends \Magento\Framework\View\Element\AbstractBlock implements DProviderInterface, IdInterface
1512
{
13+
public const CACHE_TAG = 'rss_p_new';
14+
1615
/**
1716
* @var \Magento\Catalog\Helper\Image
1817
*/
@@ -55,6 +54,8 @@ public function __construct(
5554
}
5655

5756
/**
57+
* Configure class
58+
*
5859
* @return void
5960
*/
6061
protected function _construct()
@@ -64,15 +65,15 @@ protected function _construct()
6465
}
6566

6667
/**
67-
* {@inheritdoc}
68+
* @inheritdoc
6869
*/
6970
public function isAllowed()
7071
{
7172
return $this->_scopeConfig->isSetFlag('rss/catalog/new', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
7273
}
7374

7475
/**
75-
* {@inheritdoc}
76+
* @inheritdoc
7677
*/
7778
public function getRssData()
7879
{
@@ -132,6 +133,8 @@ public function getRssData()
132133
}
133134

134135
/**
136+
* Get current store id
137+
*
135138
* @return int
136139
*/
137140
protected function getStoreId()
@@ -177,14 +180,16 @@ protected function renderPriceHtml(\Magento\Catalog\Model\Product $product)
177180
}
178181

179182
/**
180-
* {@inheritdoc}
183+
* @inheritdoc
181184
*/
182185
public function getCacheLifetime()
183186
{
184187
return 600;
185188
}
186189

187190
/**
191+
* Generate rss feed
192+
*
188193
* @return array
189194
*/
190195
public function getFeeds()
@@ -199,10 +204,18 @@ public function getFeeds()
199204
}
200205

201206
/**
202-
* {@inheritdoc}
207+
* @inheritdoc
203208
*/
204209
public function isAuthRequired()
205210
{
206211
return false;
207212
}
213+
214+
/**
215+
* @inheritdoc
216+
*/
217+
public function getIdentities()
218+
{
219+
return [self::CACHE_TAG];
220+
}
208221
}

0 commit comments

Comments
 (0)