Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix category image is not removed from tmp folder after category save #29906

Merged
merged 8 commits into from
Sep 10, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ public function __construct(
*
* @param ImageUploader $subject
* @param string $imagePath
* @param string $initialImageName
* @return string
* @throws LocalizedException
*/
public function afterMoveFileFromTmp(ImageUploader $subject, string $imagePath): string
public function afterMoveFileFromTmp(ImageUploader $subject, string $imagePath, string $initialImageName): string
{
if (!$this->config->isEnabled()) {
return $imagePath;
}

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

if (!empty($tmpAssets)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminUploadSameImageDeleteFromTemporaryFolderTest">
<annotations>
<features value="AdminUploadSameImageDeleteFromTemporaryFolderTest"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1792"/>
<title value="Image is deleted from tmp folder if is uploaded second time"/>
<description value="Image is deleted from tmp folder if is uploaded second time"/>
sivaschenko marked this conversation as resolved.
Show resolved Hide resolved
<severity value="CRITICAL"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="category"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
</after>

<!-- Upload test image to category twice -->
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPage"/>
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem">
<argument name="categoryName" value="$category.name$"/>
</actionGroup>
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImage"/>
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImageSecondTime"/>
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryFormSecondTime"/>

<!-- Open tmp/category folder -->
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGallery"/>
<actionGroup ref="AdminEnhancedMediaGalleryExpandCatalogTmpFolderActionGroup" stepKey="expandTmpFolder"/>
<actionGroup ref="AdminMediaGalleryFolderSelectByFullPathActionGroup" stepKey="selectCategoryFolder">
<argument name="path" value="catalog/tmp/category"/>
</actionGroup>

<!-- Assert folder is empty -->
<actionGroup ref="AdminAssertMediaGalleryEmptyActionGroup" stepKey="assertEmptyFolder"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminAssertMediaGalleryEmptyActionGroup">
<annotations>
<description>Requires select folder in directory tree. Assert that selected folder is empty.</description>
</annotations>

<seeElement selector="{{AdminMediaGalleryGridSection.noDataMessage}}" stepKey="assertNoDataMessageDisplayed" />
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryExpandCatalogTmpFolderActionGroup">
<annotations>
<description>Expand media gallery tmp folder tree</description>
</annotations>
<waitForLoadingMaskToDisappear stepKey="waitLoadingMask"/>
<conditionalClick selector="//li[@id='catalog']/ins" dependentSelector="//li[@id='catalog']/ul" visible="false" stepKey="expandCatalog"/>
<wait time="2" stepKey="waitCatalogExpanded"/>
<conditionalClick selector="//li[@id='catalog/tmp']/ins" dependentSelector="//li[@id='catalog/tmp']/ul" visible="false" stepKey="expandTmp"/>
<wait time="2" stepKey="waitTmpExpanded"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminMediaGalleryFolderSelectByFullPathActionGroup">
<arguments>
<argument name="path" type="string"/>
</arguments>
<wait time="2" stepKey="waitBeforeClickOnFolder"/>
<click selector="//li[@id='{{path}}']" stepKey="selectSubFolder" after="waitBeforeClickOnFolder"/>
<waitForLoadingMaskToDisappear stepKey="waitForFolderContents"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<argument name="thirdImageFile" type="string"/>
</arguments>

<grabAttributeFrom selector="{{AdminEnhancedMediaGalleryGridImagePositionSection.nthImageInGrid('0')}}" userInput="src"
<grabAttributeFrom selector="{{AdminMediaGalleryGridSection.nthImageInGrid('0')}}" userInput="src"
stepKey="getFirstImageSrcAfterSort"/>
<grabAttributeFrom selector="{{AdminEnhancedMediaGalleryGridImagePositionSection.nthImageInGrid('1')}}" userInput="src"
<grabAttributeFrom selector="{{AdminMediaGalleryGridSection.nthImageInGrid('1')}}" userInput="src"
stepKey="getSecondImageSrcAfterSort"/>
<grabAttributeFrom selector="{{AdminEnhancedMediaGalleryGridImagePositionSection.nthImageInGrid('2')}}" userInput="src"
<grabAttributeFrom selector="{{AdminMediaGalleryGridSection.nthImageInGrid('2')}}" userInput="src"
stepKey="getThirdImageSrcAfterSort"/>

<assertStringContainsString stepKey="assertFirstImagePositionAfterSort">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
-->
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminEnhancedMediaGalleryGridImagePositionSection">
<section name="AdminMediaGalleryGridSection">
<element name="noDataMessage" type="text" selector="div.no-data-message-container"/>
<element name="nthImageInGrid" type="text" selector="div[class='masonry-image-column'][data-repeat-index='{{row}}'] img" parameterized="true"/>
</section>
</sections>