Skip to content

Commit cadeba2

Browse files
ENGCOM-8160: fix category image is not removed from tmp folder after category save #29906
2 parents 83ae72b + b8ea9b6 commit cadeba2

7 files changed

+115
-6
lines changed

app/code/Magento/MediaGalleryCatalogIntegration/Plugin/SaveBaseCategoryImageInformation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ public function __construct(
8181
*
8282
* @param ImageUploader $subject
8383
* @param string $imagePath
84+
* @param string $initialImageName
8485
* @return string
8586
* @throws LocalizedException
8687
*/
87-
public function afterMoveFileFromTmp(ImageUploader $subject, string $imagePath): string
88+
public function afterMoveFileFromTmp(ImageUploader $subject, string $imagePath, string $initialImageName): string
8889
{
8990
if (!$this->config->isEnabled()) {
9091
return $imagePath;
9192
}
9293

9394
$absolutePath = $this->storage->getCmsWysiwygImages()->getStorageRoot() . $imagePath;
94-
$tmpPath = $subject->getBaseTmpPath() . '/' . substr(strrchr($imagePath, '/'), 1);
95+
$tmpPath = $subject->getBaseTmpPath() . '/' . $initialImageName;
9596
$tmpAssets = $this->getAssetsByPaths->execute([$tmpPath]);
9697

9798
if (!empty($tmpAssets)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminUploadSameImageDeleteFromTemporaryFolderTest">
12+
<annotations>
13+
<features value="AdminUploadSameImageDeleteFromTemporaryFolderTest"/>
14+
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1792"/>
15+
<title value="Image is deleted from tmp folder if is uploaded second time"/>
16+
<description value="Image is deleted from tmp folder if is uploaded second time"/>
17+
<stories value="Image is deleted from tmp folder if is uploaded second time"/>
18+
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/943908/scenarios/4836631"/>
19+
<severity value="CRITICAL"/>
20+
<group value="media_gallery_ui"/>
21+
</annotations>
22+
<before>
23+
<createData entity="SimpleSubCategory" stepKey="category"/>
24+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
25+
</before>
26+
<after>
27+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
28+
</after>
29+
30+
<!-- Upload test image to category twice -->
31+
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPage"/>
32+
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem">
33+
<argument name="categoryName" value="$category.name$"/>
34+
</actionGroup>
35+
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImage"/>
36+
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
37+
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImageSecondTime"/>
38+
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryFormSecondTime"/>
39+
40+
<!-- Open tmp/category folder -->
41+
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGallery"/>
42+
<actionGroup ref="AdminEnhancedMediaGalleryExpandCatalogTmpFolderActionGroup" stepKey="expandTmpFolder"/>
43+
<actionGroup ref="AdminMediaGalleryFolderSelectByFullPathActionGroup" stepKey="selectCategoryFolder">
44+
<argument name="path" value="catalog/tmp/category"/>
45+
</actionGroup>
46+
47+
<!-- Assert folder is empty -->
48+
<actionGroup ref="AdminAssertMediaGalleryEmptyActionGroup" stepKey="assertEmptyFolder"/>
49+
</test>
50+
</tests>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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="AdminAssertMediaGalleryEmptyActionGroup">
11+
<annotations>
12+
<description>Requires select folder in directory tree. Assert that selected folder is empty.</description>
13+
</annotations>
14+
15+
<seeElement selector="{{AdminMediaGalleryGridSection.noDataMessage}}" stepKey="assertNoDataMessageDisplayed" />
16+
</actionGroup>
17+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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="AdminEnhancedMediaGalleryExpandCatalogTmpFolderActionGroup">
12+
<annotations>
13+
<description>Expand media gallery tmp folder tree</description>
14+
</annotations>
15+
<waitForLoadingMaskToDisappear stepKey="waitLoadingMask"/>
16+
<conditionalClick selector="//li[@id='catalog']/ins" dependentSelector="//li[@id='catalog']/ul" visible="false" stepKey="expandCatalog"/>
17+
<wait time="2" stepKey="waitCatalogExpanded"/>
18+
<conditionalClick selector="//li[@id='catalog/tmp']/ins" dependentSelector="//li[@id='catalog/tmp']/ul" visible="false" stepKey="expandTmp"/>
19+
<wait time="2" stepKey="waitTmpExpanded"/>
20+
</actionGroup>
21+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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="AdminMediaGalleryFolderSelectByFullPathActionGroup">
12+
<arguments>
13+
<argument name="path" type="string"/>
14+
</arguments>
15+
<wait time="2" stepKey="waitBeforeClickOnFolder"/>
16+
<click selector="//li[@id='{{path}}']" stepKey="selectSubFolder" after="waitBeforeClickOnFolder"/>
17+
<waitForLoadingMaskToDisappear stepKey="waitForFolderContents"/>
18+
</actionGroup>
19+
</actionGroups>

app/code/Magento/MediaGalleryUi/Test/Mftf/ActionGroup/AssertAdminEnhancedMediaGallerySortByActionGroup.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
<argument name="thirdImageFile" type="string"/>
1919
</arguments>
2020

21-
<grabAttributeFrom selector="{{AdminEnhancedMediaGalleryGridImagePositionSection.nthImageInGrid('0')}}" userInput="src"
21+
<grabAttributeFrom selector="{{AdminMediaGalleryGridSection.nthImageInGrid('0')}}" userInput="src"
2222
stepKey="getFirstImageSrcAfterSort"/>
23-
<grabAttributeFrom selector="{{AdminEnhancedMediaGalleryGridImagePositionSection.nthImageInGrid('1')}}" userInput="src"
23+
<grabAttributeFrom selector="{{AdminMediaGalleryGridSection.nthImageInGrid('1')}}" userInput="src"
2424
stepKey="getSecondImageSrcAfterSort"/>
25-
<grabAttributeFrom selector="{{AdminEnhancedMediaGalleryGridImagePositionSection.nthImageInGrid('2')}}" userInput="src"
25+
<grabAttributeFrom selector="{{AdminMediaGalleryGridSection.nthImageInGrid('2')}}" userInput="src"
2626
stepKey="getThirdImageSrcAfterSort"/>
2727

2828
<assertStringContainsString stepKey="assertFirstImagePositionAfterSort">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
-->
88
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
10-
<section name="AdminEnhancedMediaGalleryGridImagePositionSection">
10+
<section name="AdminMediaGalleryGridSection">
11+
<element name="noDataMessage" type="text" selector="div.no-data-message-container"/>
1112
<element name="nthImageInGrid" type="text" selector="div[class='masonry-image-column'][data-repeat-index='{{row}}'] img" parameterized="true"/>
1213
</section>
1314
</sections>

0 commit comments

Comments
 (0)