Skip to content

Commit

Permalink
Merge pull request #1482 from magento-engcom/2.1-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.1
 - MAGETWO-72254: Backport PR-9713 for Magento 2.1 - stringify cookie value to fix #5596 #10749
  • Loading branch information
ishakhsuvarov authored Sep 12, 2017
2 parents 8390ef4 + ee022ac commit 2951e0a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
13 changes: 12 additions & 1 deletion app/code/Magento/Cookie/Helper/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,22 @@ public function __construct(
public function isUserNotAllowSaveCookie()
{
$acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
return $this->isCookieRestrictionModeEnabled() &&
empty($acceptedSaveCookiesWebsites[$this->_website->getId()]);
}

/**
* Check if cookie restriction mode is enabled for this store
*
* @return bool
*/
public function isCookieRestrictionModeEnabled()
{
return $this->scopeConfig->getValue(
self::XML_PATH_COOKIE_RESTRICTION,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->_currentStore
) && empty($acceptedSaveCookiesWebsites[$this->_website->getId()]);
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

?>
<?php /** @var \Magento\Cookie\Block\Html\Notices $block */ ?>
<?php if ($this->helper('Magento\Cookie\Helper\Cookie')->isUserNotAllowSaveCookie()): ?>
<?php if ($this->helper('Magento\Cookie\Helper\Cookie')->isCookieRestrictionModeEnabled()): ?>
<div class="message global cookie" id="notice-cookie-block" style="display: none">
<div class="content">
<p>
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Cookie/view/frontend/web/js/notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ define([
$(this.options.cookieAllowButtonSelector).on('click', $.proxy(function() {
var cookieExpires = new Date(new Date().getTime() + this.options.cookieLifetime * 1000);

$.mage.cookies.set(this.options.cookieName, this.options.cookieValue, {expires: cookieExpires});
$.mage.cookies.set(this.options.cookieName, JSON.stringify(this.options.cookieValue), {
expires: cookieExpires
});

if ($.mage.cookies.get(this.options.cookieName)) {
window.location.reload();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function _getAdapter($adapterType)
{
try {
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$adapter = $objectManager->get('Magento\Framework\Image\AdapterFactory')->create($adapterType);
$adapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create($adapterType);
return $adapter;
} catch (\Exception $e) {
$this->markTestSkipped($e->getMessage());
Expand Down Expand Up @@ -547,15 +547,15 @@ public function cropDataProvider()
*/
public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expectedColor2, $adapterType)
{
if (!function_exists('imagettfbbox')) {
$this->markTestSkipped('Workaround of problem with imagettfbbox function on Travis');
if (!function_exists('imagettfbbox') || (getenv('TRAVIS'))) {
$this->markTestSkipped('Workaround for problem with imagettfbbox() function on Travis');
}

$adapter = $this->_getAdapter($adapterType);

/** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */
$readFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
'Magento\Framework\Filesystem\Directory\ReadFactory'
\Magento\Framework\Filesystem\Directory\ReadFactory::class
);
$reader = $readFactory->create(BP);
$path = $reader->getAbsolutePath('lib/internal/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
Expand Down Expand Up @@ -611,7 +611,7 @@ public function createPngFromStringDataProvider()
public function testValidateUploadFile()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$imageAdapter = $objectManager->get('Magento\Framework\Image\AdapterFactory')->create();
$imageAdapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
$this->assertTrue($imageAdapter->validateUploadFile($this->_getFixture('magento_thumbnail.jpg')));
}

Expand All @@ -621,7 +621,7 @@ public function testValidateUploadFile()
public function testValidateUploadFileException()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$imageAdapter = $objectManager->get('Magento\Framework\Image\AdapterFactory')->create();
$imageAdapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
$imageAdapter->validateUploadFile(__FILE__);
}
}

0 comments on commit 2951e0a

Please sign in to comment.