Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2439 from magento-trigger/team3-delivery
Browse files Browse the repository at this point in the history
[Team 3] Bugfixes
  • Loading branch information
heyitsroberthe authored Apr 25, 2018
2 parents d3248d0 + 82f3f83 commit 18a7e29
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 28 deletions.
2 changes: 0 additions & 2 deletions app/code/Magento/Cms/Helper/Wysiwyg/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

/**
* Wysiwyg Images Helper.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Images extends \Magento\Framework\App\Helper\AbstractHelper
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
<element name="AcceptFolderName" type="button" selector=".action-primary.action-accept" />
<element name="StorageRootArrow" type="button" selector="#root > .jstree-icon" />
<element name="checkIfArrowExpand" type="button" selector="//li[@id='root' and contains(@class,'jstree-closed')]" />
<element name="WysiwygArrow" type="button" selector="#d3lzaXd5Zw-- > .jstree-icon" />
<element name="checkIfWysiwygArrowExpand" type="button" selector="//li[@id='d3lzaXd5Zw--' and contains(@class,'jstree-closed')]" />
<element name="confirmDelete" type="button" selector=".action-primary.action-accept" />
</section>
<section name="ProductShortDescriptionWYSIWYGToolbarSection">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
<description value="Admin should be able to add image to WYSIWYG Editor on Catalog Page"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-84373"/>
<!--Skip because of issue MAGETWO-88266-->
<group value="skip"/>
</annotations>
<amOnPage url="{{AdminCategoryPage.url}}" stepKey="navigateToNewCatalog"/>
<waitForPageLoad stepKey="wait1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<description value="Admin should be able to add image to WYSIWYG Editor on Product Page"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-84375"/>
<!--Skip because of issue MAGETWO-88266-->
<group value="skip"/>
</annotations>
<before>
<actionGroup ref="LoginActionGroup" stepKey="login"/>
Expand Down Expand Up @@ -47,7 +45,8 @@
<fillField selector="{{ProductDescriptionWYSIWYGToolbarSection.FolderName}}" userInput="{{ImageFolder.name}}" stepKey="fillFolderName1" />
<click selector="{{ProductDescriptionWYSIWYGToolbarSection.AcceptFolderName}}" stepKey="acceptFolderName11" />
<waitForLoadingMaskToDisappear stepKey="waitForLoading3" />
<conditionalClick selector="{{ProductDescriptionWYSIWYGToolbarSection.StorageRootArrow}}" dependentSelector="{{ProductDescriptionWYSIWYGToolbarSection.checkIfArrowExpand}}" stepKey="clickArrowIfCloses1" visible="true"/>
<conditionalClick selector="{{ProductDescriptionWYSIWYGToolbarSection.StorageRootArrow}}" dependentSelector="{{ProductDescriptionWYSIWYGToolbarSection.checkIfArrowExpand}}" stepKey="clickStorageRootArrowIfClosed" visible="true"/>
<conditionalClick selector="{{ProductDescriptionWYSIWYGToolbarSection.WysiwygArrow}}" dependentSelector="{{ProductDescriptionWYSIWYGToolbarSection.checkIfWysiwygArrowExpand}}" stepKey="clickWysiwygArrowIfClosed" visible="true"/>
<waitForText userInput="{{ImageFolder.name}}" stepKey="waitForNewFolder1" />
<click userInput="{{ImageFolder.name}}" stepKey="clickOnCreatedFolder1" />
<waitForLoadingMaskToDisappear stepKey="waitForLoading4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<data key="content">Sample page content. Yada yada yada.</data>
<data key="identifier" unique="suffix">test-page-</data>
</entity>
<entity name="_newDefaultCmsPage" type="cms_page">
<data key="title" unique="suffix">Test CMS Page</data>
<data key="content_heading">Test Content Heading</data>
<data key="content">Sample page content. Yada yada yada.</data>
<data key="identifier" unique="suffix">test-page-</data>
</entity>
<entity name="_duplicatedCMSPage" type="cms_page">
<data key="title">testpage</data>
<data key="content_heading">Test Content Heading</data>
Expand All @@ -33,6 +39,7 @@
<data key="shareable">Yes</data>
<data key="value">magento.jpg</data>
<data key="fileName">magento</data>
<data key="extension">jpg</data>
<data key="content">Image content. Yeah.</data>
<data key="height">1000</data>
</entity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<description value="Admin should be able to add image to WYSIWYG content of Block"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-84376"/>
<!--Skip because of issue MAGETWO-88266-->
<group value="skip"/>
</annotations>
<before>
<createData entity="_defaultCmsPage" stepKey="createCMSPage" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<description value="Admin should be able to add image to WYSIWYG content of CMS Page"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-85825"/>
<!--Skip because of issue MAGETWO-88266-->
<group value="skip"/>
</annotations>
<before>
<createData entity="_defaultCmsPage" stepKey="createCMSPage" />
Expand Down Expand Up @@ -47,7 +45,6 @@
<actionGroup ref="saveImage" stepKey="insertImage"/>
<actionGroup ref="fillOutUploadImagePopup" stepKey="fillOutUploadImagePopup" />
<click selector="{{CmsNewPagePageSeoSection.header}}" stepKey="clickExpandSearchEngineOptimisation"/>
<fillField selector="{{CmsNewPagePageSeoSection.urlKey}}" userInput="{{_defaultCmsPage.identifier}}" stepKey="fillFieldUrlKey"/>
<click selector="{{CmsNewPagePageActionsSection.expandSplitButton}}" stepKey="expandButtonMenu"/>
<waitForElementVisible selector="{{CmsNewPagePageActionsSection.splitButtonMenu}}" stepKey="waitForSplitButtonMenuVisible"/>
<click selector="{{CmsNewPagePageActionsSection.savePage}}" stepKey="clickSavePage"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<features value="MAGETWO-36659-[CMS] WYSIWYG update"/>
<stories value="MAGETWO-42158-Variable with WYSIWYG"/>
<group value="Cms"/>
<group value="skip"/>
<!-- Skipped; see MAGETWO-88218 -->
<title value="Admin should be able to add variable to WYSIWYG content of Block"/>
<description value="You should be able to add variable to WYSIWYG content Block"/>
<testCaseId value="MAGETWO-84378"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand All @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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=&quot;wysiwyg/hello.png&quot;}}" 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
62 changes: 62 additions & 0 deletions dev/tests/js/jasmine/tests/lib/mage/wysiwygAdapter.test.js
Original file line number Diff line number Diff line change
@@ -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=&quot;wysiwyg/banana.jpg&quot;}}" 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);
}
);
});
});
});
4 changes: 2 additions & 2 deletions lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '&quot;');
return Base64.mageDecode(decodeURIComponent(match[1]).replace(/\/$/, '')).replace(/"/g, '&quot;');
});
},

Expand Down

0 comments on commit 18a7e29

Please sign in to comment.