Skip to content

Commit

Permalink
Merge pull request #3210 from magento-qwerty/2.3-bugfixes-240918
Browse files Browse the repository at this point in the history
[Qwerty] Bugfixes
  • Loading branch information
cpartica authored Sep 25, 2018
2 parents e2c0d0f + 8487750 commit 547ad4a
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Controller\Adminhtml\System\Store;

use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;

class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store
/**
* Delete store.
*/
class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
{
/**
* @inheritDoc
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Controller\Adminhtml\System\Store;

use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;

class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store
/**
* Delete store view.
*/
class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
{
/**
* Delete store view post action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;

/**
* Delete website.
*/
class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
{
/**
* @inheritDoc
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/
namespace Magento\Catalog\Controller\Adminhtml\Category\Image;

use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;

/**
* Class Upload
*/
class Upload extends \Magento\Backend\App\Action
class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterface
{
/**
* Image uploader
Expand Down Expand Up @@ -54,14 +55,6 @@ public function execute()

try {
$result = $this->imageUploader->saveFileToTmpDir($imageId);

$result['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
} catch (\Exception $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
}
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,6 @@ public function uploadFile($targetPath, $type = null)
// create thumbnail
$this->resizeFile($targetPath . '/' . $uploader->getUploadedFileName(), true);

$result['cookie'] = [
'name' => $this->getSession()->getName(),
'value' => $this->getSession()->getSessionId(),
'lifetime' => $this->getSession()->getCookieLifetime(),
'path' => $this->getSession()->getCookiePath(),
'domain' => $this->getSession()->getCookieDomain(),
];

return $result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,7 @@ public function testUploadFile()
$thumbnailDestination = $thumbnailTargetPath . '/' . $fileName;
$type = 'image';
$result = [
'result',
'cookie' => [
'name' => 'session_name',
'value' => '1',
'lifetime' => '50',
'path' => 'cookie/path',
'domain' => 'cookie_domain',
],
'result'
];
$uploader = $this->getMockBuilder(\Magento\MediaStorage\Model\File\Uploader::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -507,17 +500,6 @@ public function testUploadFile()

$this->adapterFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($image);

$this->sessionMock->expects($this->atLeastOnce())->method('getName')
->willReturn($result['cookie']['name']);
$this->sessionMock->expects($this->atLeastOnce())->method('getSessionId')
->willReturn($result['cookie']['value']);
$this->sessionMock->expects($this->atLeastOnce())->method('getCookieLifetime')
->willReturn($result['cookie']['lifetime']);
$this->sessionMock->expects($this->atLeastOnce())->method('getCookiePath')
->willReturn($result['cookie']['path']);
$this->sessionMock->expects($this->atLeastOnce())->method('getCookieDomain')
->willReturn($result['cookie']['domain']);

$this->assertEquals($result, $this->imagesStorage->uploadFile($targetPath, $type));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\File;

use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;

class Upload extends \Magento\Downloadable\Controller\Adminhtml\Downloadable\File
/**
* Class Upload
*
* @package Magento\Downloadable\Controller\Adminhtml\Downloadable\File
*/
class Upload extends \Magento\Downloadable\Controller\Adminhtml\Downloadable\File implements HttpPostActionInterface
{
/**
* @var \Magento\Downloadable\Model\Link
Expand Down Expand Up @@ -96,17 +101,10 @@ public function execute()
$relativePath = rtrim($tmpPath, '/') . '/' . ltrim($result['file'], '/');
$this->storageDatabase->saveFile($relativePath);
}

$result['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
} catch (\Exception $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
}

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ class UploadTest extends \PHPUnit\Framework\TestCase
*/
protected $fileHelper;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Session
*/
protected $session;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Controller\ResultFactory
*/
Expand All @@ -81,9 +76,6 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$this->session = $this->getMockBuilder(\Magento\Backend\Model\Session::class)
->disableOriginalConstructor()
->getMock();
$this->resultFactory = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
Expand All @@ -108,9 +100,6 @@ protected function setUp()
$this->context->expects($this->any())
->method('getRequest')
->will($this->returnValue($this->request));
$this->context->expects($this->any())
->method('getSession')
->will($this->returnValue($this->session));
$this->context->expects($this->any())
->method('getResultFactory')
->will($this->returnValue($this->resultFactory));
Expand Down Expand Up @@ -154,11 +143,6 @@ public function testExecute()
$this->uploaderFactory->expects($this->once())->method('create')->willReturn($uploader);
$this->fileHelper->expects($this->once())->method('uploadFromTmp')->willReturn($data);
$this->storageDatabase->expects($this->once())->method('saveFile');
$this->session->expects($this->once())->method('getName')->willReturn('Name');
$this->session->expects($this->once())->method('getSessionId')->willReturn('SessionId');
$this->session->expects($this->once())->method('getCookieLifetime')->willReturn('CookieLifetime');
$this->session->expects($this->once())->method('getCookiePath')->willReturn('CookiePath');
$this->session->expects($this->once())->method('getCookieDomain')->willReturn('CookieDomain');
$this->resultFactory->expects($this->once())->method('create')->willReturn($resultJson);
$resultJson->expects($this->once())->method('setData')->willReturnSelf();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\PageCache\Model\System\Config\Backend;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;

/**
* Access List config field.
*/
class AccessList extends Varnish
{
/**
* @inheritDoc
*/
public function beforeSave()
{
parent::beforeSave();

$value = $this->getValue();
if (!is_string($value) || !preg_match('/^[\w\s\.\-\,\:]+$/', $value)) {
throw new LocalizedException(
new Phrase(
'Access List value "%1" is not valid. '
.'Please use only IP addresses and host names.',
[$value]
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\PageCache\Test\Unit\Model\System\Config\Backend;

use Magento\PageCache\Model\System\Config\Backend\AccessList;
use PHPUnit\Framework\TestCase;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\App\Config\ScopeConfigInterface;

class AccessListTest extends TestCase
{
/**
* @var AccessList
*/
private $accessList;

/**
* @inheritDoc
*/
protected function setUp()
{
$objectManager = new ObjectManager($this);
$configMock = $this->getMockForAbstractClass(
ScopeConfigInterface::class
);
$configMock->expects($this->any())
->method('getValue')
->with('system/full_page_cache/default')
->willReturn(['access_list' => 'localhost']);
$this->accessList = $objectManager->getObject(
AccessList::class,
[
'config' => $configMock,
'data' => ['field' => 'access_list']
]
);
}

/**
* @return array
*/
public function getValidValues(): array
{
return [
['localhost', 'localhost'],
[null, 'localhost'],
['127.0.0.1', '127.0.0.1'],
['127.0.0.1, localhost, ::2', '127.0.0.1, localhost, ::2'],
];
}

/**
* @param mixed $value
* @param mixed $expectedValue
* @dataProvider getValidValues
*/
public function testBeforeSave($value, $expectedValue)
{
$this->accessList->setValue($value);
$this->accessList->beforeSave();
$this->assertEquals($expectedValue, $this->accessList->getValue());
}

/**
* @return array
*/
public function getInvalidValues(): array
{
return [
['\\bull val\\'],
['{*I am not an IP*}'],
['{*I am not an IP*}, 127.0.0.1'],
];
}

/**
* @param mixed $value
* @expectedException \Magento\Framework\Exception\LocalizedException
* @dataProvider getInvalidValues
*/
public function testBeforeSaveInvalid($value)
{
$this->accessList->setValue($value);
$this->accessList->beforeSave();
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/PageCache/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<label>Access list</label>
<comment>IPs access list separated with ',' that can purge Varnish configuration for config file generation.
If field is empty default value localhost will be saved.</comment>
<backend_model>Magento\PageCache\Model\System\Config\Backend\Varnish</backend_model>
<backend_model>Magento\PageCache\Model\System\Config\Backend\AccessList</backend_model>
<depends>
<field id="caching_application">1</field>
</depends>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ define([
* @private
*/
_doUpdate: function () {
var uploaderLinkUrl,
uploaderLink;

this.reset();
this.element.find(this.options.container).append(
'<div class="' +
Expand All @@ -105,20 +108,15 @@ define([
this.element.find(this.options.metaData.DOM.duration).text(this.options.metaData.data.duration);

if (this.options.videoProvider === 'youtube') {
this.element.find(this.options.metaData.DOM.uploader).html(
'<a href="https://youtube.com/channel/' +
this.options.metaData.data.uploaderUrl +
'" target="_blank">' +
this.options.metaData.data.uploader +
'</a>'
);
uploaderLinkUrl = 'https://youtube.com/channel/' + this.options.metaData.data.uploaderUrl;
} else if (this.options.videoProvider === 'vimeo') {
this.element.find(this.options.metaData.DOM.uploader).html(
'<a href="' +
this.options.metaData.data.uploaderUrl +
'" target="_blank">' + this.options.metaData.data.uploader +
'</a>');
uploaderLinkUrl = this.options.metaData.data.uploaderUrl;
}
uploaderLink = document.createElement('a');
uploaderLink.setAttribute('href', uploaderLinkUrl);
uploaderLink.setAttribute('target', '_blank');
uploaderLink.innerText = this.options.metaData.data.uploader;
this.element.find(this.options.metaData.DOM.uploader)[0].appendChild(uploaderLink);
this.element.find('.' + this.options.videoClass).productVideoLoader();

},
Expand Down
Loading

0 comments on commit 547ad4a

Please sign in to comment.