Skip to content

Commit 9a8658f

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-fast-lane-prs
- merged with '2.4-develop-express-lane-prs' branch
2 parents 0582e16 + 378b48e commit 9a8658f

File tree

22 files changed

+440
-75
lines changed

22 files changed

+440
-75
lines changed

app/code/Magento/Catalog/Block/Product/ImageFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function getLabel(Product $product, string $imageType): string
123123
if (empty($label)) {
124124
$label = $product->getName();
125125
}
126-
return (string) $label;
126+
return (string)$label;
127127
}
128128

129129
/**
@@ -161,15 +161,15 @@ public function create(Product $product, string $imageId, array $attributes = nu
161161
}
162162

163163
$attributes = $attributes === null ? [] : $attributes;
164-
164+
165165
$data = [
166166
'data' => [
167167
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
168168
'image_url' => $imageAsset->getUrl(),
169169
'width' => $imageMiscParams['image_width'],
170170
'height' => $imageMiscParams['image_height'],
171171
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
172-
'ratio' => $this->getRatio($imageMiscParams['image_width'], $imageMiscParams['image_height']),
172+
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
173173
'custom_attributes' => $this->getStringCustomAttributes($attributes),
174174
'class' => $this->getClass($attributes),
175175
'product_id' => $product->getId()

app/code/Magento/Catalog/Test/Unit/Block/Product/ImageFactoryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function createDataProvider(): array
9595
return [
9696
$this->getTestDataWithoutAttributes(),
9797
$this->getTestDataWithAttributes(),
98+
$this->getTestDataWithoutDimensions()
9899
];
99100
}
100101

@@ -209,4 +210,21 @@ private function getTestDataWithAttributes(): array
209210
],
210211
];
211212
}
213+
214+
/**
215+
* @return array
216+
*/
217+
private function getTestDataWithoutDimensions(): array
218+
{
219+
$data = $this->getTestDataWithoutAttributes();
220+
221+
$data['data']['imageParamsBuilder']['image_width'] = null;
222+
$data['data']['imageParamsBuilder']['image_height'] = null;
223+
224+
$data['expected']['data']['width'] = null;
225+
$data['expected']['data']['height'] = null;
226+
$data['expected']['data']['ratio'] = 1.0;
227+
228+
return $data;
229+
}
212230
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminSaveAndDuplicateCMSPageWithSplitButtonActionGroup">
12+
<annotations>
13+
<description>Clicks on the Save and Duplicate button.</description>
14+
</annotations>
15+
16+
<waitForElementVisible selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="waitForExpandSplitButtonToBeVisible"/>
17+
<click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitBtn2" />
18+
<click selector="{{CmsNewPagePageActionsSection.saveAndDuplicate}}" stepKey="clickSaveAndDuplicate" />
19+
<waitForPageLoad stepKey="waitForPageLoadAfterClickingSaveAndDuplicate"/>
20+
<see userInput="You saved the page." stepKey="seeSavedPageMsgOnForm"/>
21+
<see userInput="You duplicated the page." stepKey="seeDuplicatedPageMsg"/>
22+
</actionGroup>
23+
</actionGroups>
Lines changed: 22 additions & 0 deletions
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+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertAdminCmsPageSaveSplitButtonActionGroup">
12+
<annotations>
13+
<description>Verify Save and Duplicate and Save and Close button.</description>
14+
</annotations>
15+
16+
<amOnPage url="{{CmsNewPagePage.url}}" stepKey="amOnPageCreationForm"/>
17+
<waitForPageLoad stepKey="waitForPageLoad1"/>
18+
<click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitBtn1" />
19+
<see selector="{{CmsNewPagePageActionsSection.saveAndDuplicate}}" userInput="Save &amp; Duplicate" stepKey="seeSaveAndDuplicate"/>
20+
<see selector="{{CmsNewPagePageActionsSection.saveAndClose}}" userInput="Save &amp; Close" stepKey="seeSaveAndClose"/>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Cms/Test/Mftf/Test/AdminCreateDuplicatedCmsPageTest.xml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,19 @@
2525
<after>
2626
<actionGroup ref="logout" stepKey="logout"/>
2727
</after>
28-
<amOnPage url="{{CmsNewPagePage.url}}" stepKey="amOnPageCreationForm"/>
29-
<waitForPageLoad stepKey="waitForPageLoad1"/>
30-
<!--Verify Save&Duplicate button and Save&Close button-->
31-
<click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitBtn1" />
32-
<see selector="{{CmsNewPagePageActionsSection.saveAndDuplicate}}" userInput="Save &amp; Duplicate" stepKey="seeSaveAndDuplicate"/>
33-
<see selector="{{CmsNewPagePageActionsSection.saveAndClose}}" userInput="Save &amp; Close" stepKey="seeSaveAndClose"/>
34-
<!--Create new CMS Page page-->
35-
<actionGroup ref="FillOutCMSPageContent" stepKey="FillOutBlockContent"/>
36-
<click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitBtn2" />
37-
<click selector="{{CmsNewPagePageActionsSection.saveAndDuplicate}}" stepKey="clickSaveAndDuplicate" />
38-
<waitForPageLoad stepKey="waitForPageLoad3"/>
39-
<see userInput="You saved the page." stepKey="seeSavedPageMsgOnForm"/>
40-
<see userInput="You duplicated the page." stepKey="seeDuplicatedPageMsg"/>
28+
<!-- Navigate to create a CMS page and Verify Save&Duplicate - Save&Close button -->
29+
<actionGroup ref="AssertAdminCmsPageSaveSplitButtonActionGroup" stepKey="verifyCmsPageSaveButton" />
30+
<!-- Filled out Content -->
31+
<actionGroup ref="FillOutCMSPageContent" stepKey="FillOutPageContent"/>
32+
<!-- Click save and duplicate action -->
33+
<actionGroup ref="AdminSaveAndDuplicateCMSPageWithSplitButtonActionGroup" stepKey="clickSaveAndDuplicateButton"/>
4134
<!--Verify duplicated CMS Page-->
4235
<seeElement selector="{{BlockNewPageBasicFieldsSection.isActive('0')}}" stepKey="seeBlockNotEnable" />
4336
<actionGroup ref="AssertCMSPageContentActionGroup" stepKey="assertContent"/>
44-
<click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandSplitBtn3" />
45-
<click selector="{{CmsNewPagePageActionsSection.saveAndClose}}" stepKey="clickSaveAndClose"/>
46-
<see userInput="You saved the page." stepKey="seeSavedCMSPageMsgOnGrid"/>
47-
<seeElement selector="div[data-role='grid-wrapper']" stepKey="seeGridPage" />
37+
<!-- Click Save Button -->
38+
<actionGroup ref="SaveCmsPageActionGroup" stepKey="clickSaveCmsPageButton"/>
39+
<actionGroup ref="DeletePageByUrlKeyActionGroup" stepKey="deleteCMSPage">
40+
<argument name="UrlKey" value="{{_duplicatedCMSPage.identifier}}"/>
41+
</actionGroup>
4842
</test>
4943
</tests>

app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Eav\Model\Entity\Attribute\Backend;
88

99
/**
10+
* Prepare date for save in DB
11+
*
1012
* @api
1113
* @since 100.0.2
1214
*/
@@ -61,8 +63,8 @@ public function beforeSave($object)
6163
/**
6264
* Prepare date for save in DB
6365
*
64-
* string format used from input fields (all date input fields need apply locale settings)
65-
* int value can be declared in code (this meen whot we use valid date)
66+
* String format is used in input fields (all date input fields need apply locale settings)
67+
* int (Unix) format can be used in other parts of the code
6668
*
6769
* @param string|int|\DateTimeInterface $date
6870
* @return string
@@ -72,7 +74,7 @@ public function formatDate($date)
7274
if (empty($date)) {
7375
return null;
7476
}
75-
// unix timestamp given - simply instantiate date object
77+
// Unix timestamp given - simply instantiate date object
7678
if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) {
7779
$date = (new \DateTime())->setTimestamp($date);
7880
} elseif (!($date instanceof \DateTimeInterface)) {
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Reports\Test\Unit\Observer;
10+
11+
use Magento\Framework\Event\Observer;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Reports\Model\Event;
14+
use Magento\Reports\Model\Product\Index\Compared;
15+
use Magento\Reports\Model\Product\Index\ComparedFactory;
16+
use Magento\Reports\Model\ReportStatus;
17+
use Magento\Reports\Observer\CatalogProductCompareClearObserver;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Unit test for Magento\Reports\Test\Unit\Observer\CatalogProductCompareClearObserver
23+
*/
24+
class CatalogProductCompareClearObserverTest extends TestCase
25+
{
26+
/**
27+
* Testable Object
28+
*
29+
* @var CatalogProductCompareClearObserver
30+
*/
31+
private $observer;
32+
33+
/**
34+
* @var ObjectManager
35+
*/
36+
private $objectManager;
37+
38+
/**
39+
* @var Observer|MockObject
40+
*/
41+
private $observerMock;
42+
43+
/**
44+
* @var ReportStatus|MockObject
45+
*/
46+
private $reportStatusMock;
47+
48+
/**
49+
* @var ComparedFactory|MockObject
50+
*/
51+
private $productCompFactoryMock;
52+
53+
/**
54+
* @var Compared|MockObject
55+
*/
56+
private $productCompModelMock;
57+
58+
/**
59+
* @var Event|MockObject
60+
*/
61+
private $reportEventMock;
62+
63+
/**
64+
* @inheritDoc
65+
*/
66+
protected function setUp(): void
67+
{
68+
$this->objectManager = new ObjectManager($this);
69+
$this->observerMock = $this->createMock(Observer::class);
70+
71+
$this->reportStatusMock = $this->getMockBuilder(ReportStatus::class)
72+
->disableOriginalConstructor()
73+
->setMethods(['isReportEnabled'])
74+
->getMock();
75+
76+
$this->reportEventMock = $this->getMockBuilder(Event::class)
77+
->disableOriginalConstructor()
78+
->getMock();
79+
80+
$this->productCompFactoryMock = $this->getMockBuilder(ComparedFactory::class)
81+
->disableOriginalConstructor()
82+
->setMethods(['create'])
83+
->getMock();
84+
85+
$this->productCompModelMock = $this->getMockBuilder(Compared::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
89+
$this->observer = $this->objectManager->getObject(
90+
CatalogProductCompareClearObserver::class,
91+
[
92+
'reportStatus' => $this->reportStatusMock,
93+
'productCompFactory' => $this->productCompFactoryMock
94+
]
95+
);
96+
}
97+
98+
/**
99+
* Test for execute(), covers test case for remove all products from compare products
100+
*/
101+
public function testExecuteRemoveProducts(): void
102+
{
103+
$this->reportStatusMock
104+
->expects($this->once())
105+
->method('isReportEnabled')
106+
->with(Event::EVENT_PRODUCT_VIEW)
107+
->willReturn(true);
108+
109+
$this->productCompFactoryMock
110+
->expects($this->once())
111+
->method('create')
112+
->willReturn($this->productCompModelMock);
113+
114+
$this->productCompModelMock
115+
->expects($this->once())
116+
->method('calculate')
117+
->willReturnSelf();
118+
119+
$this->observer->execute($this->observerMock);
120+
}
121+
122+
/**
123+
* Test for execute(), covers test case for remove all products from compare products with report disabled
124+
*/
125+
public function testExecuteRemoveProductsWithReportDisable(): void
126+
{
127+
$this->reportStatusMock
128+
->expects($this->once())
129+
->method('isReportEnabled')
130+
->with(Event::EVENT_PRODUCT_VIEW)
131+
->willReturn(false);
132+
133+
$this->productCompFactoryMock
134+
->expects($this->never())
135+
->method('create');
136+
137+
$this->productCompModelMock
138+
->expects($this->never())
139+
->method('calculate');
140+
141+
$this->observer->execute($this->observerMock);
142+
}
143+
}

app/code/Magento/Review/Model/ResourceModel/Review/Summary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public function reAggregate($summary)
7979
* Append review summary fields to product collection
8080
*
8181
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
82-
* @param string $storeId
82+
* @param int $storeId
8383
* @param string $entityCode
8484
* @return Summary
8585
* @throws \Magento\Framework\Exception\LocalizedException
8686
*/
8787
public function appendSummaryFieldsToCollection(
8888
\Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection,
89-
string $storeId,
89+
int $storeId,
9090
string $entityCode
9191
) {
9292
if (!$productCollection->isLoaded()) {

app/code/Magento/Review/Observer/CatalogProductListCollectionAppendSummaryFieldsObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function execute(EventObserver $observer)
5353
$productCollection = $observer->getEvent()->getCollection();
5454
$this->sumResourceFactory->create()->appendSummaryFieldsToCollection(
5555
$productCollection,
56-
$this->storeManager->getStore()->getId(),
56+
(int)$this->storeManager->getStore()->getId(),
5757
\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE
5858
);
5959

app/code/Magento/Review/Test/Unit/Observer/CatalogProductListCollectionAppendSummaryFieldsObserverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class CatalogProductListCollectionAppendSummaryFieldsObserverTest extends TestCase
2525
{
26-
private const STORE_ID = '1';
26+
private const STORE_ID = 1;
2727

2828
/**
2929
* @var Event|MockObject

0 commit comments

Comments
 (0)