Skip to content

Commit 0f26960

Browse files
authored
Merge branch '2.4-develop' into baudeval-patch-1
2 parents 4be7e6d + a3b1abc commit 0f26960

File tree

26 files changed

+2210
-66
lines changed

26 files changed

+2210
-66
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/StorefrontAddProductWithBackordersAllowedOnProductLevelToCartTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
3030
</after>
3131

32-
<actionGroup ref="NavigateToCreatedProductEditPageActionGroup" stepKey="openCreatedProductEditPage">
33-
<argument name="product" value="$$createProduct$$"/>
32+
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="openCreatedProductEditPage">
33+
<argument name="productId" value="$createProduct.id$"/>
3434
</actionGroup>
3535
<actionGroup ref="AdminClickOnAdvancedInventoryLinkActionGroup" stepKey="clickOnAdvancedInventoryLink"/>
3636
<actionGroup ref="AdminSetBackordersOnProductAdvancedInventoryActionGroup" stepKey="allowBackorders"/>

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Listing/Collector/UrlTest.php

Lines changed: 187 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,21 @@ protected function setUp(): void
7878
);
7979
}
8080

81-
public function testGet()
81+
public function testCollectWithNullButtons()
8282
{
8383
$product = $this->getMockBuilder(Product::class)
8484
->disableOriginalConstructor()
8585
->getMock();
8686
$productRenderInfoDto = $this->getMockForAbstractClass(ProductRenderInterface::class);
87+
88+
// Mock both getAddToCartButton and getAddToCompareButton returning null (line 81-82)
89+
$productRenderInfoDto->expects($this->once())
90+
->method('getAddToCartButton')
91+
->willReturn(null);
92+
$productRenderInfoDto->expects($this->once())
93+
->method('getAddToCompareButton')
94+
->willReturn(null);
95+
8796
$this->catalogProductHelperMock
8897
->expects($this->once())
8998
->method('getPostDataParams')
@@ -92,6 +101,15 @@ public function testGet()
92101
$product->expects($this->once())
93102
->method('getId')
94103
->willReturn(1);
104+
$product->expects($this->once())
105+
->method('getData')
106+
->with('has_options')
107+
->willReturn(true);
108+
$product->expects($this->once())
109+
->method('getProductUrl')
110+
->willReturn('http://example.com/product/1');
111+
112+
// Expect buttonFactory to be called twice (once for cart, once for compare) since both are null
95113
$this->buttonFactoryMock->expects($this->exactly(2))
96114
->method('create')
97115
->willReturn($this->buttonMock);
@@ -113,6 +131,174 @@ public function testGet()
113131
)
114132
->willReturn(['some cart url post data']);
115133

134+
// Verify buttons are set back to productRender
135+
$productRenderInfoDto->expects($this->once())
136+
->method('setAddToCartButton')
137+
->with($this->buttonMock);
138+
$productRenderInfoDto->expects($this->once())
139+
->method('setAddToCompareButton')
140+
->with($this->buttonMock);
141+
$productRenderInfoDto->expects($this->once())
142+
->method('setUrl')
143+
->with('http://example.com/product/1');
144+
145+
$this->model->collect($product, $productRenderInfoDto);
146+
}
147+
148+
public function testCollectWithExistingAddToCompareButton()
149+
{
150+
$product = $this->getMockBuilder(Product::class)
151+
->disableOriginalConstructor()
152+
->getMock();
153+
$productRenderInfoDto = $this->getMockForAbstractClass(ProductRenderInterface::class);
154+
155+
$existingCompareButton = $this->getMockForAbstractClass(ButtonInterface::class);
156+
157+
// Test line 82: getAddToCompareButton returns existing button
158+
$productRenderInfoDto->expects($this->once())
159+
->method('getAddToCartButton')
160+
->willReturn(null);
161+
$productRenderInfoDto->expects($this->once())
162+
->method('getAddToCompareButton')
163+
->willReturn($existingCompareButton);
164+
165+
$this->catalogProductHelperMock
166+
->expects($this->once())
167+
->method('getPostDataParams')
168+
->with($product)
169+
->willReturn(['Some compare Data']);
170+
$product->expects($this->once())
171+
->method('getId')
172+
->willReturn(1);
173+
$product->expects($this->once())
174+
->method('getData')
175+
->with('has_options')
176+
->willReturn(false);
177+
$product->expects($this->once())
178+
->method('getProductUrl')
179+
->willReturn('http://example.com/product/1');
180+
181+
// Expect buttonFactory to be called only once (for cart button) since compare button exists
182+
$this->buttonFactoryMock->expects($this->once())
183+
->method('create')
184+
->willReturn($this->buttonMock);
185+
$this->abstractProductMock->expects($this->exactly(2))
186+
->method('getAddToCartUrl')
187+
->with(
188+
$product,
189+
['useUencPlaceholder' => true]
190+
)
191+
->willReturn('some:url');
192+
$this->postHelperMock->expects($this->once())
193+
->method('getPostData')
194+
->with(
195+
'some:url',
196+
[
197+
'product' => 1,
198+
ActionInterface::PARAM_NAME_URL_ENCODED => "%uenc%"
199+
]
200+
)
201+
->willReturn(['some cart url post data']);
202+
203+
// Verify the existing compare button is used and configured
204+
$existingCompareButton->expects($this->once())
205+
->method('setUrl')
206+
->with(['Some compare Data']);
207+
208+
// Verify buttons are set back to productRender
209+
$productRenderInfoDto->expects($this->once())
210+
->method('setAddToCartButton')
211+
->with($this->buttonMock);
212+
$productRenderInfoDto->expects($this->once())
213+
->method('setAddToCompareButton')
214+
->with($existingCompareButton);
215+
$productRenderInfoDto->expects($this->once())
216+
->method('setUrl')
217+
->with('http://example.com/product/1');
218+
219+
$this->model->collect($product, $productRenderInfoDto);
220+
}
221+
222+
public function testCollectWithExistingButtons()
223+
{
224+
$product = $this->getMockBuilder(Product::class)
225+
->disableOriginalConstructor()
226+
->getMock();
227+
$productRenderInfoDto = $this->getMockForAbstractClass(ProductRenderInterface::class);
228+
229+
$existingCartButton = $this->getMockForAbstractClass(ButtonInterface::class);
230+
$existingCompareButton = $this->getMockForAbstractClass(ButtonInterface::class);
231+
232+
// Test both buttons already exist
233+
$productRenderInfoDto->expects($this->once())
234+
->method('getAddToCartButton')
235+
->willReturn($existingCartButton);
236+
$productRenderInfoDto->expects($this->once())
237+
->method('getAddToCompareButton')
238+
->willReturn($existingCompareButton);
239+
240+
$this->catalogProductHelperMock
241+
->expects($this->once())
242+
->method('getPostDataParams')
243+
->with($product)
244+
->willReturn(['Some compare Data']);
245+
$product->expects($this->once())
246+
->method('getId')
247+
->willReturn(1);
248+
$product->expects($this->once())
249+
->method('getData')
250+
->with('has_options')
251+
->willReturn(true);
252+
$product->expects($this->once())
253+
->method('getProductUrl')
254+
->willReturn('http://example.com/product/1');
255+
256+
// Expect buttonFactory to NOT be called since both buttons exist
257+
$this->buttonFactoryMock->expects($this->never())
258+
->method('create');
259+
$this->abstractProductMock->expects($this->exactly(2))
260+
->method('getAddToCartUrl')
261+
->with(
262+
$product,
263+
['useUencPlaceholder' => true]
264+
)
265+
->willReturn('some:url');
266+
$this->postHelperMock->expects($this->once())
267+
->method('getPostData')
268+
->with(
269+
'some:url',
270+
[
271+
'product' => 1,
272+
ActionInterface::PARAM_NAME_URL_ENCODED => "%uenc%"
273+
]
274+
)
275+
->willReturn(['some cart url post data']);
276+
277+
// Verify both existing buttons are used and configured
278+
$existingCartButton->expects($this->once())
279+
->method('setPostData')
280+
->with(['some cart url post data']);
281+
$existingCartButton->expects($this->once())
282+
->method('setRequiredOptions')
283+
->with(true);
284+
$existingCartButton->expects($this->once())
285+
->method('setUrl')
286+
->with('some:url');
287+
$existingCompareButton->expects($this->once())
288+
->method('setUrl')
289+
->with(['Some compare Data']);
290+
291+
// Verify buttons are set back to productRender
292+
$productRenderInfoDto->expects($this->once())
293+
->method('setAddToCartButton')
294+
->with($existingCartButton);
295+
$productRenderInfoDto->expects($this->once())
296+
->method('setAddToCompareButton')
297+
->with($existingCompareButton);
298+
$productRenderInfoDto->expects($this->once())
299+
->method('setUrl')
300+
->with('http://example.com/product/1');
301+
116302
$this->model->collect($product, $productRenderInfoDto);
117303
}
118304
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Url.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@
2020
*/
2121
class Url implements ProductRenderCollectorInterface
2222
{
23-
/** Compare Data key */
24-
const KEY_COMPARE_URL_POST_DATA = "compare_url_post_data";
25-
26-
/** Add to cart url key post data */
27-
const KEY_ADD_TO_CART_URL_POST_DATA = "add_to_cart_url_post_data";
28-
29-
/** Add to cart url key */
30-
const KEY_ADD_TO_CART_URL = "add_to_cart_url";
31-
32-
/** Product Url */
33-
const KEY_URL = "url";
34-
35-
/** Has Required options key */
36-
const KEY_HAS_REQUIRED_OPTIONS = "has_required_options";
37-
3823
/**
3924
* @var AbstractProduct
4025
*/
@@ -79,7 +64,7 @@ public function __construct(
7964
public function collect(ProductInterface $product, ProductRenderInterface $productRender)
8065
{
8166
$addToCart = $productRender->getAddToCartButton();
82-
$addToCompare = $productRender->getAddToCartButton();
67+
$addToCompare = $productRender->getAddToCompareButton();
8368

8469
if (!$addToCart) {
8570
$addToCart = $this->buttonFactory->create();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright 2025 Adobe
5+
* All Rights Reserved.
6+
*/
7+
-->
8+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
10+
<entity name="CheckoutOutOfStockMessageData">
11+
<data key="headerMessage">Some of the products are out of stock.</data>
12+
<data key="productItemMessage">There are no source items with the in stock status</data>
13+
</entity>
14+
</entities>

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@
5555
<element name="removeProductBySku" type="button" selector="//div[contains(., '{{sku}}')]/ancestor::tbody//button" parameterized="true" timeout="30"/>
5656
<element name="failedItemBySku" type="block" selector="//div[contains(.,'{{sku}}')]/ancestor::tbody" parameterized="true" timeout="30"/>
5757
<element name="attributeText" selector="//tbody[@class='cart item']//a[text()='{{product_name}}']/../..//dl//dt[text()='{{attribute_name}}']/..//dd[contains(text(),'{{attribute_option}}')]" type="text" parameterized="true"/>
58+
<element name="ProductErrorMessageByName" type="text" selector="//a[text()='{{productName}}']/ancestor::strong/following-sibling::div[contains(@class, 'cart item message error')]//div" parameterized="true"/>
5859
</section>
5960
</sections>

0 commit comments

Comments
 (0)