Skip to content

Commit 1695982

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-express-lane-prs
- merged with '2.4-develop-fast-lane-prs' branch
2 parents 897c2dd + 3fac0b3 commit 1695982

File tree

18 files changed

+322
-162
lines changed

18 files changed

+322
-162
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AssertStorefrontProductDetailPageFinalPriceActionGroup">
11+
<arguments>
12+
<argument name="finalProductPrice" type="string"/>
13+
</arguments>
14+
<grabTextFrom selector="{{StorefrontProductInfoMainSection.price}}" stepKey="productPriceText"/>
15+
<assertEquals stepKey="assertProductPriceOnProductPage">
16+
<expectedResult type="string">${{finalProductPrice}}</expectedResult>
17+
<actualResult type="variable">productPriceText</actualResult>
18+
</assertEquals>
19+
</actionGroup>
20+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AssertStorefrontProductDetailPageNameActionGroup">
11+
<arguments>
12+
<argument name="productName" type="string"/>
13+
</arguments>
14+
<grabTextFrom selector="{{StorefrontProductInfoMainSection.productName}}" stepKey="productNameText"/>
15+
<assertEquals stepKey="assertProductNameOnProductPage">
16+
<expectedResult type="string">{{productName}}</expectedResult>
17+
<actualResult type="variable">productNameText</actualResult>
18+
</assertEquals>
19+
</actionGroup>
20+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AssertStorefrontProductDetailPageTierPriceActionGroup">
11+
<arguments>
12+
<argument name="tierProductPriceDiscountQuantity" type="string"/>
13+
<argument name="productPriceWithAppliedTierPriceDiscount" type="string"/>
14+
<argument name="productSavedPricePercent" type="string"/>
15+
</arguments>
16+
<grabTextFrom selector="{{StorefrontProductInfoMainSection.tierPriceText}}" stepKey="tierPriceText"/>
17+
<assertEquals stepKey="assertTierPriceTextOnProductPage">
18+
<expectedResult type="string">Buy {{tierProductPriceDiscountQuantity}} for ${{productPriceWithAppliedTierPriceDiscount}} each and save {{productSavedPricePercent}}%</expectedResult>
19+
<actualResult type="variable">tierPriceText</actualResult>
20+
</assertEquals>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Data/TierPriceData.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@
6464
<data key="quantity">30</data>
6565
<var key="sku" entityType="product" entityKey="sku" />
6666
</entity>
67-
</entities>
67+
<entity name="tierProductPriceDiscount" type="catalogTierPrice">
68+
<data key="price">36.00</data>
69+
<data key="price_type">discount</data>
70+
<data key="website_id">0</data>
71+
<data key="customer_group">ALL GROUPS</data>
72+
<data key="quantity">3</data>
73+
<var key="sku" entityType="product" entityKey="sku" />
74+
</entity>
75+
</entities>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StoreFrontSimpleProductWithSpecialAndTierDiscountPriceTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<title value="Apply discount tier price and custom price values for simple product"/>
14+
<description value="Apply discount tier price and custom price values for simple product"/>
15+
<severity value="MAJOR"/>
16+
<group value="Catalog"/>
17+
</annotations>
18+
<before>
19+
<createData entity="_defaultCategory" stepKey="createCategory"/>
20+
21+
<createData entity="ApiSimpleProduct" stepKey="createProduct">
22+
<requiredEntity createDataKey="createCategory"/>
23+
<field key="price">100.00</field>
24+
</createData>
25+
26+
<createData entity="tierProductPriceDiscount" stepKey="addTierPrice">
27+
<requiredEntity createDataKey="createProduct"/>
28+
</createData>
29+
</before>
30+
<after>
31+
<deleteData createDataKey="createProduct" stepKey="deleteSimpleProduct"/>
32+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
33+
</after>
34+
35+
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>
36+
37+
<actionGroup ref="GoToProductPageViaIDActionGroup" stepKey="openAdminProductEditPage">
38+
<argument name="productId" value="$createProduct.id$"/>
39+
</actionGroup>
40+
41+
<actionGroup ref="AddSpecialPriceToProductActionGroup" stepKey="addSpecialPriceToProduct">
42+
<argument name="price" value="65.00"/>
43+
</actionGroup>
44+
45+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProductForm"/>
46+
47+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
48+
<argument name="productUrl" value="$createProduct.custom_attributes[url_key]$"/>
49+
</actionGroup>
50+
51+
<actionGroup ref="AssertStorefrontProductDetailPageNameActionGroup" stepKey="assertProductNameText">
52+
<argument name="productName" value="$createProduct.name$"/>
53+
</actionGroup>
54+
55+
<actionGroup ref="AssertStorefrontProductDetailPageTierPriceActionGroup" stepKey="assertProductTierPriceText">
56+
<argument name="tierProductPriceDiscountQuantity" value="{{tierProductPriceDiscount.quantity}}"/>
57+
<argument name="productPriceWithAppliedTierPriceDiscount" value="64.00"/>
58+
<argument name="productSavedPricePercent" value="2"/>
59+
</actionGroup>
60+
61+
<actionGroup ref="AssertStorefrontProductDetailPageFinalPriceActionGroup" stepKey="assertProductFinalPriceText">
62+
<argument name="finalProductPrice" value="65.00"/>
63+
</actionGroup>
64+
</test>
65+
</tests>

app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ $tierPrices = $tierPriceModel->getTierPriceList();
1717
$msrpShowOnGesture = $block->getPriceType('msrp_price')->isShowPriceOnGesture();
1818
$product = $block->getSaleableItem();
1919
?>
20-
<?php if (count($tierPrices)) : ?>
20+
<?php if (count($tierPrices)): ?>
2121
<ul class="<?= $block->escapeHtmlAttr(($block->hasListClass() ? $block->getListClass() : 'prices-tier items')) ?>">
22-
<?php foreach ($tierPrices as $index => $price) : ?>
22+
<?php foreach ($tierPrices as $index => $price): ?>
2323
<li class="item">
2424
<?php
2525
$productId = $product->getId();
2626
$isSaleable = $product->isSaleable();
2727
$popupId = 'msrp-popup-' . $productId . $block->getRandomString(20);
28-
if ($msrpShowOnGesture && $price['price']->getValue() < $product->getMsrp()) :
28+
if ($msrpShowOnGesture && $price['price']->getValue() < $product->getMsrp()):
2929
$addToCartUrl = '';
3030
if ($isSaleable) {
3131
$addToCartUrl = $this->helper(\Magento\Checkout\Helper\Cart::class)
@@ -60,7 +60,7 @@ $product = $block->getSaleableItem();
6060
id="<?= $block->escapeHtmlAttr($popupId) ?>"
6161
data-tier-price="<?= $block->escapeHtml($block->jsonEncode($tierPriceData)) ?>">
6262
<?= $block->escapeHtml(__('Click for price')) ?></a>
63-
<?php else :
63+
<?php else:
6464
$priceAmountBlock = $block->renderAmount(
6565
$price['price'],
6666
[
@@ -73,19 +73,20 @@ $product = $block->getSaleableItem();
7373
?>
7474
<?= /* @noEscape */ ($block->getShowDetailedPrice() !== false)
7575
? __(
76-
'Buy %1 for %2 each and <strong class="benefit">save<span class="percent tier-%3">&nbsp;%4</span>%</strong>',
76+
'Buy %1 for %2 each and '.
77+
'<strong class="benefit">save<span class="percent tier-%3">&nbsp;%4</span>%</strong>',
7778
$price['price_qty'],
7879
$priceAmountBlock,
7980
$index,
80-
$block->formatPercent($price['percentage_value'] ?? $tierPriceModel->getSavePercent($price['price']))
81+
$block->formatPercent($tierPriceModel->getSavePercent($price['price']))
8182
)
8283
: __('Buy %1 for %2 each', $price['price_qty'], $priceAmountBlock);
8384
?>
8485
<?php endif; ?>
8586
</li>
8687
<?php endforeach; ?>
8788
</ul>
88-
<?php if ($msrpShowOnGesture) :?>
89+
<?php if ($msrpShowOnGesture):?>
8990
<script type="text/x-magento-init">
9091
{
9192
".product-info-main": {

app/code/Magento/Swatches/Helper/Data.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Data
3535
const EMPTY_IMAGE_VALUE = 'no_selection';
3636

3737
/**
38-
* Default store ID
38+
* The int value of the Default store ID
3939
*/
4040
const DEFAULT_STORE_ID = 0;
4141

@@ -471,13 +471,13 @@ public function getSwatchesByOptionsId(array $optionIds)
471471
$swatches = [];
472472
$fallbackValues = [];
473473
$currentStoreId = $this->storeManager->getStore()->getId();
474-
foreach ($swatchCollection as $item) {
474+
foreach ($swatchCollection->getData() as $item) {
475475
if ($item['type'] != Swatch::SWATCH_TYPE_TEXTUAL) {
476-
$swatches[$item['option_id']] = $item->getData();
476+
$swatches[$item['option_id']] = $item;
477477
} elseif ($item['store_id'] == $currentStoreId && $item['value'] != '') {
478-
$fallbackValues[$item['option_id']][$currentStoreId] = $item->getData();
478+
$fallbackValues[$item['option_id']][$currentStoreId] = $item;
479479
} elseif ($item['store_id'] == self::DEFAULT_STORE_ID) {
480-
$fallbackValues[$item['option_id']][self::DEFAULT_STORE_ID] = $item->getData();
480+
$fallbackValues[$item['option_id']][self::DEFAULT_STORE_ID] = $item;
481481
}
482482
}
483483

app/code/Magento/Swatches/Test/Unit/Helper/DataTest.php

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ public function dataForGettingSwatchAsArray()
669669

670670
public function testGetSwatchesByOptionsIdIf1()
671671
{
672-
$swatchMock = $this->createMock(\Magento\Swatches\Model\Swatch::class);
672+
//Simulate behaviour of \Magento\Swatches\Model\Swatch as array item
673+
$swatchMock = $this->createMock(\ArrayAccess::class);
673674

674675
$optionsData = [
675676
[
@@ -692,22 +693,18 @@ public function testGetSwatchesByOptionsIdIf1()
692693
->willReturn($optionsData[0]['type']);
693694
$swatchMock->expects($this->at(1))->method('offsetGet')->with('option_id')
694695
->willReturn($optionsData[0]['option_id']);
695-
$swatchMock->expects($this->at(2))->method('getData')->with('')
696-
->willReturn($optionsData[0]);
697-
$swatchMock->expects($this->at(3))->method('offsetGet')->with('type')
696+
$swatchMock->expects($this->at(2))->method('offsetGet')->with('type')
698697
->willReturn($optionsData[1]['type']);
699-
$swatchMock->expects($this->at(4))->method('offsetGet')->with('store_id')
698+
$swatchMock->expects($this->at(3))->method('offsetGet')->with('store_id')
700699
->willReturn($optionsData[1]['store_id']);
701-
$swatchMock->expects($this->at(5))->method('offsetGet')->with('store_id')
700+
$swatchMock->expects($this->at(4))->method('offsetGet')->with('store_id')
702701
->willReturn($optionsData[1]['store_id']);
703-
$swatchMock->expects($this->at(6))->method('offsetGet')->with('option_id')
702+
$swatchMock->expects($this->at(5))->method('offsetGet')->with('option_id')
704703
->willReturn($optionsData[1]['option_id']);
705-
$swatchMock->expects($this->at(7))->method('getData')->with('')
706-
->willReturn($optionsData[1]);
707704

708-
$swatchCollectionMock = $this->objectManager
709-
->getCollectionMock(Collection::class, [$swatchMock, $swatchMock]);
705+
$swatchCollectionMock = $this->createMock(Collection::class);
710706
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
707+
$swatchCollectionMock->expects($this->once())->method('getData')->willReturn([$swatchMock, $swatchMock]);
711708
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
712709

713710
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
@@ -719,7 +716,8 @@ public function testGetSwatchesByOptionsIdIf1()
719716

720717
public function testGetSwatchesByOptionsIdIf2()
721718
{
722-
$swatchMock = $this->createMock(\Magento\Swatches\Model\Swatch::class);
719+
//Simulate behaviour of \Magento\Swatches\Model\Swatch as array item
720+
$swatchMock = $this->createMock(\ArrayAccess::class);
723721

724722
$optionsData = [
725723
[
@@ -737,28 +735,21 @@ public function testGetSwatchesByOptionsIdIf2()
737735
'id' => 488,
738736
]
739737
];
740-
741-
$swatchMock->expects($this->at(0))->method('offsetGet')->with('type')->willReturn(0);
742-
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn(1);
743-
$swatchMock->expects($this->at(2))->method('offsetGet')->with('value')->willReturn('test');
744-
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn(35);
745-
$swatchMock->expects($this->at(4))->method('getData')->with('')->willReturn($optionsData[0]);
746-
$swatchMock->expects($this->at(5))->method('offsetGet')->with('type')->willReturn(0);
747-
$swatchMock->expects($this->at(6))->method('offsetGet')->with('store_id')->willReturn(1);
748-
$swatchMock->expects($this->at(7))->method('offsetGet')->with('value')->willReturn('test2');
749-
$swatchMock->expects($this->at(8))->method('offsetGet')->with('option_id')->willReturn(36);
750-
$swatchMock->expects($this->at(9))->method('getData')->with('')->willReturn($optionsData[1]);
751-
752-
$swatchCollectionMock = $this->objectManager->getCollectionMock(
753-
Collection::class,
754-
[
755-
$swatchMock,
756-
$swatchMock,
757-
]
758-
);
738+
// @codingStandardsIgnoreStart
739+
$swatchMock->expects($this->at(0))->method('offsetGet')->with('type')->willReturn($optionsData[0]['type']);
740+
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn($optionsData[0]['store_id']);
741+
$swatchMock->expects($this->at(2))->method('offsetGet')->with('value')->willReturn($optionsData[0]['value']);
742+
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn($optionsData[0]['option_id']);
743+
$swatchMock->expects($this->at(4))->method('offsetGet')->with('type')->willReturn($optionsData[1]['type']);
744+
$swatchMock->expects($this->at(5))->method('offsetGet')->with('store_id')->willReturn($optionsData[1]['store_id']);
745+
$swatchMock->expects($this->at(6))->method('offsetGet')->with('value')->willReturn($optionsData[1]['value']);
746+
$swatchMock->expects($this->at(7))->method('offsetGet')->with('option_id')->willReturn($optionsData[1]['option_id']);
747+
// @codingStandardsIgnoreEnd
748+
$swatchCollectionMock = $this->createMock(Collection::class);
759749
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
760750

761751
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
752+
$swatchCollectionMock->expects($this->once())->method('getData')->willReturn([$swatchMock, $swatchMock]);
762753

763754
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
764755
$this->storeManagerMock->method('getStore')->willReturn($storeMock);
@@ -769,7 +760,8 @@ public function testGetSwatchesByOptionsIdIf2()
769760

770761
public function testGetSwatchesByOptionsIdIf3()
771762
{
772-
$swatchMock = $this->createMock(\Magento\Swatches\Model\Swatch::class);
763+
//Simulate behaviour of \Magento\Swatches\Model\Swatch as array item
764+
$swatchMock = $this->createMock(\ArrayAccess::class);
773765

774766
$optionsData = [
775767
'type' => 0,
@@ -778,22 +770,17 @@ public function testGetSwatchesByOptionsIdIf3()
778770
'option_id' => 35,
779771
'id' => 423,
780772
];
781-
782-
$swatchMock->expects($this->at(0))->method('offsetGet')->with('type')->willReturn(0);
783-
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn(0);
784-
$swatchMock->expects($this->at(2))->method('offsetGet')->with('store_id')->willReturn(0);
785-
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn(35);
786-
$swatchMock->expects($this->at(4))->method('getData')->with('')->willReturn($optionsData);
787-
788-
$swatchCollectionMock = $this->objectManager->getCollectionMock(
789-
Collection::class,
790-
[
791-
$swatchMock,
792-
]
793-
);
773+
// @codingStandardsIgnoreStart
774+
$swatchMock->expects($this->at(0))->method('offsetGet')->with('type')->willReturn($optionsData['type']);
775+
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn($optionsData['store_id']);
776+
$swatchMock->expects($this->at(2))->method('offsetGet')->with('store_id')->willReturn($optionsData['store_id']);
777+
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn($optionsData['option_id']);
778+
// @codingStandardsIgnoreEnd
779+
$swatchCollectionMock = $this->createMock(Collection::class);
794780
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
795781

796782
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
783+
$swatchCollectionMock->expects($this->once())->method('getData')->willReturn([$swatchMock]);
797784

798785
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
799786
$this->storeManagerMock->method('getStore')->willReturn($storeMock);

0 commit comments

Comments
 (0)