Skip to content

Commit b5180c0

Browse files
author
Viktor Kopin
committed
adobe-stock-integration#1806: refactoring and cover by mftf test
1 parent 22da500 commit b5180c0

File tree

9 files changed

+233
-144
lines changed

9 files changed

+233
-144
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategoryContentSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<element name="selectFromGalleryButton" type="button" selector="//*[@class='file-uploader-area']/label[text()='Select from Gallery']"/>
1515
<element name="uploadImageFile" type="input" selector=".file-uploader-area>input"/>
1616
<element name="imageFileName" type="text" selector=".file-uploader-filename"/>
17+
<element name="imageFileMeta" type="text" selector=".file-uploader-meta"/>
1718
<element name="removeImageButton" type="button" selector=".file-uploader-summary .action-remove"/>
1819
<element name="AddCMSBlock" type="select" selector="//*[@name='landing_page']"/>
1920
<element name="description" type="input" selector="//*[@name='description']"/>

app/code/Magento/Cms/Model/Wysiwyg/Images/GetInsertImageContent.php

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,14 @@ class GetInsertImageContent
2828
*/
2929
private $catalogHelper;
3030

31-
/**
32-
* @var Filesystem
33-
*/
34-
private $filesystem;
35-
36-
/**
37-
* @var Mime
38-
*/
39-
private $mime;
40-
41-
/**
42-
* @var WriteInterface
43-
*/
44-
private $pubDirectory;
45-
4631
/**
4732
* @param ImagesHelper $imagesHelper
4833
* @param CatalogHelper $catalogHelper
49-
* @param Filesystem $fileSystem
50-
* @param Mime $mime
5134
*/
52-
public function __construct(
53-
ImagesHelper $imagesHelper,
54-
CatalogHelper $catalogHelper,
55-
Filesystem $fileSystem,
56-
Mime $mime
57-
) {
35+
public function __construct(ImagesHelper $imagesHelper, CatalogHelper $catalogHelper)
36+
{
5837
$this->imagesHelper = $imagesHelper;
5938
$this->catalogHelper = $catalogHelper;
60-
$this->filesystem = $fileSystem;
61-
$this->mime = $mime;
6239
}
6340

6441
/**
@@ -88,43 +65,4 @@ public function execute(
8865

8966
return $this->imagesHelper->getImageHtmlDeclaration($filename, $renderAsTag);
9067
}
91-
92-
/**
93-
* Retrieve size of requested file
94-
*
95-
* @param string $path
96-
* @return int
97-
*/
98-
public function getImageSize(string $path): int
99-
{
100-
$directory = $this->getPubDirectory();
101-
102-
return $directory->isExist($path) ? $directory->stat($path)['size'] : 0;
103-
}
104-
105-
/**
106-
* Retrieve MIME type of requested file
107-
*
108-
* @param string $path
109-
* @return string
110-
*/
111-
public function getMimeType(string $path)
112-
{
113-
$absoluteFilePath = $this->getPubDirectory()->getAbsolutePath($path);
114-
115-
return $this->mime->getMimeType($absoluteFilePath);
116-
}
117-
118-
/**
119-
* Retrieve pub directory read interface instance
120-
*
121-
* @return ReadInterface
122-
*/
123-
private function getPubDirectory()
124-
{
125-
if ($this->pubDirectory === null) {
126-
$this->pubDirectory = $this->filesystem->getDirectoryRead(DirectoryList::PUB);
127-
}
128-
return $this->pubDirectory;
129-
}
13068
}

app/code/Magento/MediaGalleryRenditions/Controller/Adminhtml/Image/OnInsert.php

Lines changed: 0 additions & 64 deletions
This file was deleted.
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminMediaGalleryInsertLargeImageFileSizeTest">
12+
<annotations>
13+
<features value="AdminMediaGalleryInsertLargeImageFileSizeTest"/>
14+
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1806"/>
15+
<title value="Admin user should see correct image file size after rendition"/>
16+
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1507933/scenarios/5200023"/>
17+
<description value="Admin user should see correct image file size after rendition"/>
18+
<severity value="MAJOR"/>
19+
<group value="media_gallery_ui"/>
20+
</annotations>
21+
<before>
22+
<createData entity="SimpleSubCategory" stepKey="category"/>
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
</before>
25+
<after>
26+
<!-- Delete uploaded image -->
27+
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPageFoDelete"/>
28+
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItemForDelete">
29+
<argument name="categoryName" value="$category.name$"/>
30+
</actionGroup>
31+
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryForDelete"/>
32+
<actionGroup ref="AdminEnhancedMediaGalleryEnableMassActionModeActionGroup" stepKey="enableMassActionToDeleteImages"/>
33+
<actionGroup ref="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup" stepKey="selectSecondImageToDelete">
34+
<argument name="imageName" value="{{LargeImage.title}}"/>
35+
</actionGroup>
36+
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clickDeleteSelectedButton"/>
37+
<actionGroup ref="AdminEnhancedMediaGalleryConfirmDeleteImagesActionGroup" stepKey="deleteImages"/>
38+
39+
<!-- Delete category -->
40+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
41+
</after>
42+
43+
<!-- Open category page -->
44+
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPage"/>
45+
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem">
46+
<argument name="categoryName" value="$category.name$"/>
47+
</actionGroup>
48+
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
49+
50+
<!-- Add image to category from gallery -->
51+
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGallery"/>
52+
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="addCategoryImage">
53+
<argument name="image" value="LargeImage"/>
54+
</actionGroup>
55+
<actionGroup ref="AdminMediaGalleryClickImageInGridActionGroup" stepKey="selectImage">
56+
<argument name="imageName" value="{{LargeImage.title}}"/>
57+
</actionGroup>
58+
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="addSelected"/>
59+
60+
<!-- Assert added image size -->
61+
<actionGroup ref="AdminAssertImageUploadFileSizeThanActionGroup" stepKey="assertSize">
62+
<argument name="fileSize" value="26 KB"/>
63+
</actionGroup>
64+
</test>
65+
</tests>

app/code/Magento/MediaGalleryRenditions/etc/adminhtml/routes.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\MediaGalleryUi\Controller\Adminhtml\Image;
8+
9+
use Magento\Backend\App\Action;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Controller\Result\JsonFactory;
15+
use Magento\Framework\Controller\ResultInterface;
16+
use Magento\Framework\File\Mime;
17+
use Magento\Framework\Filesystem;
18+
use Magento\Framework\Filesystem\Directory\ReadInterface;
19+
use Magento\Framework\Filesystem\File\WriteInterface;
20+
21+
/**
22+
* Class OnInsert
23+
*/
24+
class OnInsert extends Action implements HttpPostActionInterface
25+
{
26+
/**
27+
* @var JsonFactory
28+
*/
29+
private $resultJsonFactory;
30+
31+
/**
32+
* @var GetInsertImageContent
33+
*/
34+
private $getInsertImageContent;
35+
36+
/**
37+
* @var Filesystem
38+
*/
39+
private $filesystem;
40+
41+
/**
42+
* @var Mime
43+
*/
44+
private $mime;
45+
46+
/**
47+
* @var WriteInterface
48+
*/
49+
private $pubDirectory;
50+
51+
/**
52+
* @param Context $context
53+
* @param JsonFactory $resultJsonFactory
54+
* @param GetInsertImageContent|null $getInsertImageContent
55+
* @param Filesystem $fileSystem
56+
* @param Mime $mime
57+
*/
58+
public function __construct(
59+
Context $context,
60+
JsonFactory $resultJsonFactory,
61+
GetInsertImageContent $getInsertImageContent,
62+
Filesystem $fileSystem,
63+
Mime $mime
64+
) {
65+
parent::__construct($context);
66+
$this->resultJsonFactory = $resultJsonFactory;
67+
$this->getInsertImageContent = $getInsertImageContent;
68+
$this->filesystem = $fileSystem;
69+
$this->mime = $mime;
70+
}
71+
72+
/**
73+
* Return a content (just a link or an html block) for inserting image to the content
74+
*
75+
* @return ResultInterface
76+
*/
77+
public function execute()
78+
{
79+
$data = $this->getRequest()->getParams();
80+
$path = $this->getInsertImageContent->execute(
81+
$data['filename'],
82+
$data['force_static_path'],
83+
$data['as_is'],
84+
isset($data['store']) ? (int)$data['store'] : null
85+
);
86+
87+
$size = $data['force_static_path'] ? $this->getImageSize($path) : 0;
88+
$type = $data['force_static_path'] ? $this->getMimeType($path) : '';
89+
return $this->resultJsonFactory->create()->setData(['path' => $path, 'size' => $size, 'type' => $type]);
90+
}
91+
92+
/**
93+
* Retrieve size of requested file
94+
*
95+
* @param string $path
96+
* @return int
97+
*/
98+
private function getImageSize(string $path): int
99+
{
100+
$directory = $this->getPubDirectory();
101+
102+
return $directory->isExist($path) ? $directory->stat($path)['size'] : 0;
103+
}
104+
105+
/**
106+
* Retrieve MIME type of requested file
107+
*
108+
* @param string $path
109+
* @return string
110+
*/
111+
private function getMimeType(string $path)
112+
{
113+
$absoluteFilePath = $this->getPubDirectory()->getAbsolutePath($path);
114+
115+
return $this->mime->getMimeType($absoluteFilePath);
116+
}
117+
118+
/**
119+
* Retrieve pub directory read interface instance
120+
*
121+
* @return ReadInterface
122+
*/
123+
private function getPubDirectory()
124+
{
125+
if ($this->pubDirectory === null) {
126+
$this->pubDirectory = $this->filesystem->getDirectoryRead(DirectoryList::PUB);
127+
}
128+
return $this->pubDirectory;
129+
}
130+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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="AdminAssertImageUploadFileSizeThanActionGroup">
11+
<annotations>
12+
<description>Validates that the provided image has correct file size in category content section.</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="fileSize" type="string"/>
16+
</arguments>
17+
18+
<grabTextFrom selector="{{AdminCategoryContentSection.imageFileMeta}}" stepKey="imageSize"/>
19+
<assertStringContainsString stepKey="assertFileSize">
20+
<expectedResult type="string">{{fileSize}}</expectedResult>
21+
<actualResult type="variable">imageSize</actualResult>
22+
</assertStringContainsString>
23+
24+
</actionGroup>
25+
</actionGroups>

0 commit comments

Comments
 (0)