diff --git a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php index 4cddc23239b..cd3473c6bab 100644 --- a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php @@ -9,8 +9,6 @@ /** * Wysiwyg Images Helper. - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Images extends \Magento\Framework\App\Helper\AbstractHelper { diff --git a/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js b/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js index 62b5648f4a2..9f082b2ce32 100644 --- a/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js +++ b/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js @@ -94,7 +94,7 @@ define([ lastExistentFolderEl = folderEl; - if (path.length > 1) { + if (path.length) { tree.jstree('open_node', folderEl, recursiveOpen); } else { tree.jstree('open_node', folderEl, function () { diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductFormSection.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductFormSection.xml index 58aad7b2947..20345119582 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductFormSection.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductFormSection.xml @@ -103,6 +103,8 @@ + +
diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGCatalogCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGCatalogCest.xml index 8aa58cf1fb1..0f202e30c50 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGCatalogCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGCatalogCest.xml @@ -21,8 +21,6 @@ - - diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGProductCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGProductCest.xml index ddc904d2ae3..b2eeacb3bc8 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGProductCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminAddImageToWYSIWYGProductCest.xml @@ -16,8 +16,6 @@ - - @@ -47,7 +45,8 @@ - + + diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Data/CmsPageData.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Data/CmsPageData.xml index 324d937df95..857ac2a2f1b 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Data/CmsPageData.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Data/CmsPageData.xml @@ -14,6 +14,12 @@ Sample page content. Yada yada yada. test-page- + + Test CMS Page + Test Content Heading + Sample page content. Yada yada yada. + test-page- + testpage Test Content Heading @@ -33,6 +39,7 @@ Yes magento.jpg magento + jpg Image content. Yeah. 1000 diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGBlockCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGBlockCest.xml index 586be486184..72d08737092 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGBlockCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGBlockCest.xml @@ -16,8 +16,6 @@ - - diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGCMSPageCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGCMSPageCest.xml index 626654b4628..42036145827 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGCMSPageCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddImageToWYSIWYGCMSPageCest.xml @@ -16,8 +16,6 @@ - - @@ -47,7 +45,6 @@ - diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddVariableToWYSIWYGBlockCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddVariableToWYSIWYGBlockCest.xml index 497185362ad..a4616d717dc 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddVariableToWYSIWYGBlockCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminAddVariableToWYSIWYGBlockCest.xml @@ -12,8 +12,6 @@ - - <description value="You should be able to add variable to WYSIWYG content Block"/> <testCaseId value="MAGETWO-84378"/> diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddImageToWYSIWYGNewsletterCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddImageToWYSIWYGNewsletterCest.xml index dcc9c798dc4..28f57332650 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddImageToWYSIWYGNewsletterCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddImageToWYSIWYGNewsletterCest.xml @@ -16,8 +16,6 @@ <description value="Admin should be able to add image to WYSIWYG content Newsletter"/> <severity value="CRITICAL"/> <testCaseId value="MAGETWO-84377"/> - <!--Skip because of issue MAGETWO-88266--> - <group value="skip"/> </annotations> <before> <actionGroup ref="LoginActionGroup" stepKey="login"/> @@ -58,7 +56,6 @@ <waitForPageLoad stepKey="waitForPageLoad9"/> <seeElement selector="{{StorefrontNewsletterSection.mediaDescription}}" stepKey="assertMediaDescription"/> <seeElementInDOM selector="{{StorefrontNewsletterSection.ImageSource(ImageUpload3.fileName,ImageUpload3.extension)}}" stepKey="assertMediaSource"/> - <closeTab stepKey="closeTab"/> <after> <closeTab stepKey="closeTab"/> <actionGroup ref="DisabledWYSIWYG" stepKey="disableWYSIWYG"/> diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddVariableToWYSIWYGNewsletterCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddVariableToWYSIWYGNewsletterCest.xml index fe0f0670392..59e4da42bdd 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddVariableToWYSIWYGNewsletterCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/AdminAddVariableToWYSIWYGNewsletterCest.xml @@ -12,7 +12,6 @@ <features value="MAGETWO-36659-[CMS] WYSIWYG update"/> <stories value="MAGETWO-42158-Variable with WYSIWYG"/> <group value="Newsletter"/> - <group value="skip"/> <title value="Admin should be able to add variable to WYSIWYG Editor of Newsletter"/> <description value="Admin should be able to add variable to WYSIWYG Editor Newsletter"/> <testCaseId value="MAGETWO-84379"/> diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/VerifyTinyMCEv4IsNativeWYSIWYGOnNewsletterCest.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/VerifyTinyMCEv4IsNativeWYSIWYGOnNewsletterCest.xml index dcf36d911e4..7ba78175554 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/VerifyTinyMCEv4IsNativeWYSIWYGOnNewsletterCest.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Newsletter/Test/VerifyTinyMCEv4IsNativeWYSIWYGOnNewsletterCest.xml @@ -16,8 +16,6 @@ <description value="Admin see TinyMCEv4.6 is native WYSIWYG on Newsletter"/> <severity value="CRITICAL"/> <testCaseId value="MAGETWO-84683"/> - <!-- MAGETWO-90659 --> - <group value="skip"/> </annotations> <before> <actionGroup ref="LoginActionGroup" stepKey="loginGetFromGeneralFile"/> @@ -30,6 +28,7 @@ <fillField selector="{{BasicFieldNewsletterSection.templateSubject}}" userInput="{{_defaultNewsletter.subject}}" stepKey="fillTemplateSubject" /> <fillField selector="{{BasicFieldNewsletterSection.senderName}}" userInput="{{_defaultNewsletter.senderName}}" stepKey="fillSenderName" /> <fillField selector="{{BasicFieldNewsletterSection.senderEmail}}" userInput="{{_defaultNewsletter.senderEmail}}" stepKey="fillSenderEmail" /> + <conditionalClick selector="#toggletext" dependentSelector=".mce-tinymce" visible="false" stepKey="clickBtnIfTinyMCEHidden"/> <actionGroup ref="VerifyTinyMCEActionGroup" stepKey="verifyTinyMCE4"/> <actionGroup ref="VerifyMagentoEntityActionGroup" stepKey="verifyMagentoEntities"/> <executeJS function="tinyMCE.get('text').setContent('Hello World From Newsletter Template!');" stepKey="executeJSFillContent"/> diff --git a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Variable/ActionGroup/CreateCustomVariableActionGroup.xml b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Variable/ActionGroup/CreateCustomVariableActionGroup.xml index 001e8549142..84ccf65eb04 100644 --- a/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Variable/ActionGroup/CreateCustomVariableActionGroup.xml +++ b/dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Variable/ActionGroup/CreateCustomVariableActionGroup.xml @@ -21,6 +21,8 @@ <amOnPage url="admin/admin/system_variable/" stepKey="goToVarialeGrid" /> <waitForPageLoad stepKey="waitForPageLoad1" /> <click selector="{{CustomVariableSection.GridCustomVariableCode(customVariable.code)}}" stepKey="goToCustomVariableEditPage" /> + <waitForPageLoad stepKey="waitForPageLoad"/> + <waitForElementVisible selector="{{CustomVariableSection.delete}}" stepKey="waitForDeleteBtn" /> <click selector="{{CustomVariableSection.delete}}" stepKey="deleteCustomVariable" /> <waitForText userInput="Are you sure you want to do this?" stepKey="waitForText" /> <click selector="{{CustomVariableSection.confirmDelete}}" stepKey="confirmDelete" /> diff --git a/dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg/ImagesTest.php b/dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg/ImagesTest.php index 12d2a467360..68273ebe618 100644 --- a/dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg/ImagesTest.php +++ b/dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg/ImagesTest.php @@ -6,9 +6,20 @@ namespace Magento\Cms\Helper\Wysiwyg; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\TestFramework\ObjectManager; class ImagesTest extends \PHPUnit\Framework\TestCase { + /** + * @var ObjectManager + */ + private $objectManager; + + protected function setUp() + { + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + public function testGetStorageRoot() { /** @var \Magento\Framework\Filesystem $filesystem */ @@ -17,17 +28,112 @@ public function testGetStorageRoot() ); $mediaPath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); /** @var \Magento\Cms\Helper\Wysiwyg\Images $helper */ - $helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + $helper = $this->objectManager->create( \Magento\Cms\Helper\Wysiwyg\Images::class ); $this->assertStringStartsWith($mediaPath, $helper->getStorageRoot()); } + /** + * @magentoConfigFixture current_store web/unsecure/base_url http://example.com/ + */ public function testGetCurrentUrl() { - $helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + /** @var \Magento\Cms\Helper\Wysiwyg\Images $helper */ + $helper = $this->objectManager->create( \Magento\Cms\Helper\Wysiwyg\Images::class ); - $this->assertStringStartsWith('http://localhost/', $helper->getCurrentUrl()); + $this->assertStringStartsWith('http://example.com/', $helper->getCurrentUrl()); + } + + /** + * @param bool $isStaticUrlsAllowed + * @param string $filename + * @param bool $renderAsTag + * @param string|callable $expectedResult - string or callable to make unique assertions on $expectedResult + * @magentoConfigFixture current_store web/unsecure/base_url http://example.com/ + * @dataProvider providerGetImageHtmlDeclaration + */ + public function testGetImageHtmlDeclaration( + $isStaticUrlsAllowed, + $filename, + $renderAsTag, + $expectedResult + ) { + $helper = $this->generateHelper($isStaticUrlsAllowed); + + $actualResult = $helper->getImageHtmlDeclaration($filename, $renderAsTag); + + if (is_callable($expectedResult)) { + $expectedResult($actualResult); + } else { + $this->assertEquals( + $expectedResult, + $actualResult + ); + } + } + + /** + * Data provider for testGetImageHtmlDeclaration + * + * @return array + */ + public function providerGetImageHtmlDeclaration() + { + return [ + [true, 'wysiwyg/hello.png', true, '<img src="http://example.com/pub/media/wysiwyg/hello.png" alt="" />'], + [ + false, + 'wysiwyg/hello.png', + false, + function ($actualResult) { + $expectedResult = ( + '/backend/cms/wysiwyg/directive/___directive/' . + 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvaGVsbG8ucG5nIn19/' + ); + + $this->assertContains($expectedResult, parse_url($actualResult, PHP_URL_PATH)); + } + ], + [true, 'wysiwyg/hello.png', false, 'http://example.com/pub/media/wysiwyg/hello.png'], + [false, 'wysiwyg/hello.png', true, '<img src="{{media url="wysiwyg/hello.png"}}" alt="" />'], + ]; + } + + /** + * Generate instance of Images Helper + * + * @param bool $isStaticUrlsAllowed - mock is created to override value of isUsingStaticUrlsAllowed method in class + * @return \Magento\Cms\Helper\Wysiwyg\Images + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + private function generateHelper($isStaticUrlsAllowed = false) + { + $storeId = 1; + + $eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); + + $contextMock = $this->objectManager->create(\Magento\Framework\App\Helper\Context::class, [ + 'eventManager' => $eventManagerMock, + ]); + + $helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class, [ + 'context' => $contextMock + ]); + + $checkResult = new \stdClass(); + $checkResult->isAllowed = false; + + $eventManagerMock->expects($this->any()) + ->method('dispatch') + ->with('cms_wysiwyg_images_static_urls_allowed', ['result' => $checkResult, 'store_id' => $storeId]) + ->willReturnCallback(function ($_, $arr) use ($isStaticUrlsAllowed) { + $arr['result']->isAllowed = $isStaticUrlsAllowed; + }); + + $helper->setStoreId($storeId); + + return $helper; } } diff --git a/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php b/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php index 201a08fa539..b79ccd255f2 100644 --- a/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php @@ -39,9 +39,16 @@ public function testGetConfig() public function testGetConfigCssUrls() { $config = $this->model->getConfig(); - $publicPathPattern = 'http://localhost/pub/static/%s/adminhtml/Magento/backend/en_US/mage/%s'; + $publicPathPattern = 'http://localhost/pub/static/%s/adminhtml/Magento/backend/en_US/%s'; $tinyMce4Config = $config->getData('tinymce4'); - $this->assertStringMatchesFormat($publicPathPattern, $tinyMce4Config['content_css']); + $contentCss = $tinyMce4Config['content_css']; + if (is_array($contentCss)) { + foreach ($contentCss as $url) { + $this->assertStringMatchesFormat($publicPathPattern, $url); + } + } else { + $this->assertStringMatchesFormat($publicPathPattern, $contentCss); + } } /** diff --git a/dev/tests/js/jasmine/tests/lib/mage/wysiwygAdapter.test.js b/dev/tests/js/jasmine/tests/lib/mage/wysiwygAdapter.test.js new file mode 100644 index 00000000000..ff510046e55 --- /dev/null +++ b/dev/tests/js/jasmine/tests/lib/mage/wysiwygAdapter.test.js @@ -0,0 +1,62 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/* eslint-disable max-nested-callbacks */ +define([ + 'wysiwygAdapter' +], function (wysiwygAdapter) { + 'use strict'; + + var obj; + + beforeEach(function () { + + /** + * Dummy constructor to use for instantiation + * @constructor + */ + var Constr = function () {}; + + Constr.prototype = wysiwygAdapter; + + obj = new Constr(); + obj.initialize('id', { + 'directives_url': 'http://example.com/admin/cms/wysiwyg/directive/' + }); + }); + + describe('wysiwygAdapter', function () { + var decodedHtml = '<p>' + + '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>', + encodedHtml = '<p>' + + '<img src="http://example.com/admin/cms/wysiwyg/directive/' + + '___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C" alt="" width="612" height="459">' + + '</p>', + encodedHtmlWithForwardSlashInImgSrc = encodedHtml.replace('%2C%2C', '%2C%2C/'); + + describe('"encodeDirectives" method', function () { + it('converts media directive img src to directive URL', function () { + expect(obj.encodeDirectives(decodedHtml)).toEqual(encodedHtml); + }); + }); + + describe('"decodeDirectives" method', function () { + it( + 'converts directive URL img src without a trailing forward slash ' + + 'to media url without a trailing forward slash', + function () { + expect(obj.decodeDirectives(encodedHtml)).toEqual(decodedHtml); + } + ); + + it('converts directive URL img src with a trailing forward slash ' + + 'to media url without a trailing forward slash', + function () { + expect(obj.decodeDirectives(encodedHtmlWithForwardSlashInImgSrc)).toEqual(decodedHtml); + } + ); + }); + }); +}); diff --git a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js index bfae7a0157c..443ca40862c 100644 --- a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js +++ b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js @@ -608,10 +608,10 @@ define([ decodeDirectives: function (content) { // escape special chars in directives url to use it in regular expression var url = this.makeDirectiveUrl('%directive%').replace(/([$^.?*!+:=()\[\]{}|\\])/g, '\\$1'), - reg = new RegExp(url.replace('%directive%', '([a-zA-Z0-9,_-]+(?:%2[A-Z]|)+)')); + reg = new RegExp(url.replace('%directive%', '([a-zA-Z0-9,_-]+(?:%2[A-Z]|)+\/?)')); return content.gsub(reg, function (match) { //eslint-disable-line no-extra-bind - return Base64.mageDecode(decodeURIComponent(match[1])).replace(/"/g, '"'); + return Base64.mageDecode(decodeURIComponent(match[1]).replace(/\/$/, '')).replace(/"/g, '"'); }); },