Skip to content

Commit a84b678

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-41471' into 2.4-develop-pr57
2 parents 3f697e0 + 5491222 commit a84b678

File tree

5 files changed

+100
-147
lines changed

5 files changed

+100
-147
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
10+
<entity name="SystemUploadConfigurationMaxWidth">
11+
<data key="path">system/upload_configuration/max_width</data>
12+
<data key="value">1920</data>
13+
</entity>
14+
<entity name="SystemUploadConfigurationMaxHeight">
15+
<data key="path">system/upload_configuration/max_height</data>
16+
<data key="value">1200</data>
17+
</entity>
18+
</entities>

app/code/Magento/Cms/Test/Mftf/Data/CmsPageData.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@
8888
<data key="height">1000</data>
8989
<data key="path">wysiwyg</data>
9090
</entity>
91+
<entity name="ImageUploadMedium" type="uploadImage">
92+
<data key="title" unique="suffix">Medium Image</data>
93+
<data key="price">1.00</data>
94+
<data key="file_type">Upload File</data>
95+
<data key="shareable">Yes</data>
96+
<data key="value">medium.jpg</data>
97+
<data key="file">medium.jpg</data>
98+
<data key="fileName">medium</data>
99+
<data key="extension">jpg</data>
100+
<data key="content">Image content. Yeah.</data>
101+
<data key="height">508</data>
102+
<data key="path">wysiwyg</data>
103+
</entity>
91104
<entity name="ImageFolder" type="uploadImage">
92105
<data key="name" unique="suffix">Test</data>
93106
</entity>

app/code/Magento/Cms/Test/Mftf/Section/StorefrontCMSPageSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<section name="StorefrontCMSPageSection">
1212
<element name="mediaDescription" type="text" selector=".column.main>p>img"/>
1313
<element name="imageSource" type="text" selector="//img[contains(@src,'{{imageName}}')]" parameterized="true"/>
14+
<element name="imageBySource" type="text" selector="img[src*='{{imageName}}']" parameterized="true"/>
1415
<element name="mainTitle" type="text" selector="#maincontent .page-title"/>
1516
<element name="mainContent" type="text" selector="#maincontent"/>
1617
<element name="footerTop" type="text" selector="footer.page-footer"/>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminAddLargeImageToWYSIWYGCMSTest">
11+
<annotations>
12+
<features value="Cms"/>
13+
<stories value="Default WYSIWYG toolbar configuration with Magento Media Gallery"/>
14+
<group value="Cms"/>
15+
<title value="Resize image for CMS according to Upload Configuration"/>
16+
<description value="The large image should be resized according to Upload Configuration"/>
17+
<severity value="BLOCKER"/>
18+
<testCaseId value="MC-41826"/>
19+
</annotations>
20+
<before>
21+
<createData entity="_defaultCmsPage" stepKey="createCMSPage" />
22+
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
23+
</before>
24+
<after>
25+
<deleteData createDataKey="createCMSPage" stepKey="deleteCMSPage" />
26+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
27+
</after>
28+
29+
<actionGroup ref="NavigateToCreatedCMSPageActionGroup" stepKey="navigateToCreatedCMSPage">
30+
<argument name="CMSPage" value="$$createCMSPage$$"/>
31+
</actionGroup>
32+
<waitForElementVisible selector="{{TinyMCESection.TinyMCE4}}" stepKey="waitForTinyMCE4" />
33+
<click selector="{{TinyMCESection.InsertImageIcon}}" stepKey="clickInsertImageIcon" />
34+
<waitForPageLoad stepKey="waitForPageLoad" />
35+
<actionGroup ref="ClickBrowseBtnOnUploadPopupActionGroup" stepKey="clickBrowserBtn"/>
36+
<actionGroup ref="AttachImageActionGroup" stepKey="attachImage">
37+
<argument name="Image" value="ImageUploadMedium"/>
38+
</actionGroup>
39+
<actionGroup ref="SaveImageActionGroup" stepKey="insertImage"/>
40+
<actionGroup ref="FillOutUploadImagePopupActionGroup" stepKey="fillOutUploadImagePopup" />
41+
<click selector="{{CmsNewPagePageSeoSection.header}}" stepKey="clickExpandSearchEngineOptimisation"/>
42+
<fillField selector="{{CmsNewPagePageSeoSection.urlKey}}" userInput="$$createCMSPage.identifier$$" stepKey="fillFieldUrlKey"/>
43+
<actionGroup ref="SaveCmsPageActionGroup" stepKey="clickSavePage"/>
44+
<amOnPage url="$$createCMSPage.identifier$$" stepKey="amOnPageTestPage"/>
45+
<waitForPageLoad stepKey="waitPageLoadOnFrontend"/>
46+
<seeElementInDOM selector="{{StorefrontCMSPageSection.imageSource(ImageUploadMedium.fileName)}}" stepKey="assertMediaSource"/>
47+
<executeJS function='return document.querySelector("{{StorefrontCMSPageSection.imageBySource(ImageUploadMedium.fileName)}}").naturalWidth;' stepKey="imageNaturalWith"/>
48+
<assertLessThanOrEqual stepKey="assertMaxImageWith">
49+
<expectedResult type="int">{{SystemUploadConfigurationMaxWidth.value}}</expectedResult>
50+
<actualResult type="variable">imageNaturalWith</actualResult>
51+
</assertLessThanOrEqual>
52+
<executeJS function='return document.querySelector("{{StorefrontCMSPageSection.imageBySource(ImageUploadMedium.fileName)}}").naturalHeight;' stepKey="imageNaturalHeight"/>
53+
<assertLessThanOrEqual stepKey="assertMaxImageHeight">
54+
<expectedResult type="int">{{SystemUploadConfigurationMaxHeight.value}}</expectedResult>
55+
<actualResult type="variable">imageNaturalHeight</actualResult>
56+
</assertLessThanOrEqual>
57+
</test>
58+
</tests>

app/code/Magento/Cms/view/adminhtml/templates/browser/content/uploader.phtml

Lines changed: 10 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,20 @@
66

77
// phpcs:disable PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound
88
/** @var $block \Magento\Cms\Block\Adminhtml\Wysiwyg\Images\Content\Uploader */
9-
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
109

11-
$filters = $block->getConfig()->getFilters() ?? [];
12-
$allowedExtensions = [];
1310
$blockHtmlId = $block->getHtmlId();
14-
15-
$listExtensions = [];
16-
foreach ($filters as $media_type) {
17-
$listExtensions[] = array_map(function ($fileExt) {
18-
return ltrim($fileExt, '.*');
19-
}, $media_type['files']);
20-
}
21-
22-
$allowedExtensions = array_merge([], ...$listExtensions);
23-
24-
$resizeConfig = $block->getImageUploadConfigData()->getIsResizeEnabled()
25-
? "{action: 'resize', maxWidth: "
26-
. $block->escapeHtml($block->getImageUploadMaxWidth())
27-
. ", maxHeight: "
28-
. $block->escapeHtml($block->getImageUploadMaxHeight())
29-
. "}"
30-
: "{action: 'resize'}";
3111
?>
3212

33-
<div id="<?= /* @noEscape */ $blockHtmlId ?>" class="uploader">
13+
<div id="<?= /* @noEscape */ $blockHtmlId ?>" class="uploader"
14+
data-mage-init='{
15+
"Magento_Backend/js/media-uploader" : {
16+
"maxFileSize": <?= /* @noEscape */ $block->getFileSizeService()->getMaxFileSize() ?>,
17+
"maxWidth": <?= /* @noEscape */ $block->getImageUploadMaxWidth() ?>,
18+
"maxHeight": <?= /* @noEscape */ $block->getImageUploadMaxHeight() ?>,
19+
"isResizeEnabled": <?= /* @noEscape */ $block->getImageUploadConfigData()->getIsResizeEnabled() ?>
20+
}
21+
}'
22+
>
3423
<span class="fileinput-button form-buttons">
3524
<span><?= $block->escapeHtml(__('Upload Images')) ?></span>
3625
<input class="fileupload" type="file"
@@ -47,130 +36,4 @@ $resizeConfig = $block->getImageUploadConfigData()->getIsResizeEnabled()
4736
<div class="clear"></div>
4837
</div>
4938
</script>
50-
<?php $intMaxSize = $block->getFileSizeService()->getMaxFileSize();
51-
$resizeConfig = /* @noEscape */ $resizeConfig;
52-
$blockHtmlId = /* @noEscape */ $blockHtmlId;
53-
$scriptString = <<<script
54-
55-
require([
56-
'jquery',
57-
'mage/template',
58-
'Magento_Ui/js/lib/validation/validator',
59-
'Magento_Ui/js/modal/alert',
60-
'jquery/file-uploader',
61-
'domReady!',
62-
'mage/translate'
63-
], function ($, mageTemplate, validator, uiAlert) {
64-
var maxFileSize = {$block->escapeJs($block->getFileSizeService()->getMaxFileSize())},
65-
allowedExtensions = '{$block->escapeJs(implode(' ', $allowedExtensions))}';
66-
67-
$('#{$blockHtmlId} .fileupload').fileupload({
68-
dataType: 'json',
69-
formData: {
70-
isAjax: 'true',
71-
form_key: FORM_KEY
72-
},
73-
sequentialUploads: true,
74-
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
75-
allowedExtensions: allowedExtensions,
76-
maxFileSize: maxFileSize,
77-
dropZone: $('#{$blockHtmlId}').closest('[role="dialog"]'),
78-
add: function (e, data) {
79-
var progressTmpl = mageTemplate('#{$blockHtmlId}-template'),
80-
fileSize,
81-
tmpl,
82-
validationResult;
83-
84-
data.files = data.files.filter(function (file) {
85-
fileSize = typeof file.size == "undefined" ?
86-
$.mage.__('We could not detect a size.') :
87-
byteConvert(file.size);
88-
89-
if (maxFileSize) {
90-
validationResult = validator('validate-max-size', file.size, maxFileSize);
91-
92-
if (!validationResult.passed) {
93-
uiAlert({
94-
content: validationResult.message
95-
});
96-
97-
return false;
98-
}
99-
}
100-
101-
if (allowedExtensions) {
102-
validationResult = validator('validate-file-type', file.name, allowedExtensions);
103-
104-
if (!validationResult.passed) {
105-
uiAlert({
106-
content: validationResult.message
107-
});
108-
109-
return false;
110-
}
111-
}
112-
113-
data.fileId = Math.random().toString(36).substr(2, 9);
114-
115-
tmpl = progressTmpl({
116-
data: {
117-
name: file.name,
118-
size: fileSize,
119-
id: data.fileId
120-
}
121-
});
122-
123-
$(tmpl).data('image', data).appendTo('#{$blockHtmlId}');
124-
125-
return true;
126-
});
127-
128-
if (data.files.length) {
129-
$(this).fileupload('process', data).done(function () {
130-
data.submit();
131-
});
132-
}
133-
},
134-
done: function (e, data) {
135-
var progressSelector = '#' + data.fileId + ' .progressbar-container .progressbar';
136-
var tempErrorMessage = document.createElement("div");
137-
$(progressSelector).css('width', '100%');
138-
$('[data-action="show-error"]').children(".message").remove();
139-
if (data.result && !data.result.hasOwnProperty('errorcode')) {
140-
$(progressSelector).removeClass('upload-progress').addClass('upload-success');
141-
} else {
142-
tempErrorMessage.className = "message message-warning warning";
143-
tempErrorMessage.innerHTML = data.result.error;
144-
145-
$('[data-action="show-error"]').append(tempErrorMessage);
146-
$(progressSelector).removeClass('upload-progress').addClass('upload-failure');
147-
}
148-
},
149-
progress: function (e, data) {
150-
var progress = parseInt(data.loaded / data.total * 100, 10);
151-
var progressSelector = '#' + data.fileId + ' .progressbar-container .progressbar';
152-
$(progressSelector).css('width', progress + '%');
153-
},
154-
fail: function (e, data) {
155-
var progressSelector = '#' + data.fileId + ' .progressbar-container .progressbar';
156-
$(progressSelector).removeClass('upload-progress').addClass('upload-failure');
157-
}
158-
});
159-
160-
$('#{$blockHtmlId} .fileupload').fileupload('option', {
161-
process: [{
162-
action: 'load',
163-
fileTypes: /^image\/(gif|jpeg|png)$/,
164-
maxFileSize: {$intMaxSize} * 10
165-
},
166-
{$resizeConfig},
167-
{
168-
action: 'save'
169-
}]
170-
});
171-
});
172-
173-
script;
174-
?>
175-
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
17639
</div>

0 commit comments

Comments
 (0)