Skip to content

Commit

Permalink
⏫ Forwardport of #11608 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11608.patch (created by @sylink) based on commit(s):
  1. 40d51e4
  2. c7a6c56

Fixed GitHub Issues in 2.3-develop branch:
  - #9633: Web Setup Wizard 500 error when session storage is configured to use memcache (reported by @dotsoa)
  • Loading branch information
magento-engcom-team committed Jan 24, 2018
1 parent 8e77e2f commit 7b12d50
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ protected function setUp()
$sessionManager->writeClose();
}
$this->deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);

$this->deploymentConfigMock->expects($this->at(0))
->method('get')
->with(Config::PARAM_SESSION_SAVE_PATH)
->will($this->returnValue(null));
$this->deploymentConfigMock->expects($this->at(1))
$this->deploymentConfigMock
->method('get')
->with(Config::PARAM_SESSION_CACHE_LIMITER)
->will($this->returnValue($this->_cacheLimiter));
->willReturnCallback(function ($configPath) {
switch ($configPath) {
case Config::PARAM_SESSION_SAVE_METHOD:
return 'files';
case Config::PARAM_SESSION_CACHE_LIMITER:
return $this->_cacheLimiter;
default:
return null;
}
});

$this->_model = $this->_objectManager->create(
\Magento\Framework\Session\Config::class,
Expand Down Expand Up @@ -83,15 +86,6 @@ public function testDefaultConfiguration()
$this->assertEquals($this->_model->getSavePath(), $this->_model->getOption('save_path'));
}

/**
* Unable to add integration tests for testGetLifetimePathNonDefault
*
* Error: Cannot modify header information - headers already sent
*/
public function testGetLifetimePathNonDefault()
{
}

public function testSetOptionsInvalidValue()
{
$preValue = $this->_model->getOptions();
Expand Down Expand Up @@ -280,16 +274,27 @@ public function testConstructorSavePath($existing, $given, $expected)
$this->markTestSkipped('Cannot set session.save_path with ini_set');
}

$this->deploymentConfigMock->expects($this->at(0))
$deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
$deploymentConfigMock
->method('get')
->with(Config::PARAM_SESSION_SAVE_PATH)
->will($this->returnValue($given));

$this->_model = $this->_objectManager->create(
->willReturnCallback(function ($configPath) use ($given) {
switch ($configPath) {
case Config::PARAM_SESSION_SAVE_METHOD:
return 'files';
case Config::PARAM_SESSION_CACHE_LIMITER:
return $this->_cacheLimiter;
case Config::PARAM_SESSION_SAVE_PATH:
return $given;
default:
return null;
}
});

$model = $this->_objectManager->create(
\Magento\Framework\Session\Config::class,
['deploymentConfig' => $this->deploymentConfigMock]
['deploymentConfig' => $deploymentConfigMock]
);
$this->assertEquals($expected, $this->_model->getOption('save_path'));
$this->assertEquals($expected, $model->getOption('save_path'));

if ($sessionSavePath != ini_get('session.save_path')) {
ini_set('session.save_path', $sessionSavePath);
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/Magento/Framework/Session/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public function __construct(
$this->setSavePath($savePath);
}

/**
* Session save handler - memcache, files, etc
*/
$saveHandler = $deploymentConfig->get(self::PARAM_SESSION_SAVE_METHOD);
if ($saveHandler) {
$this->setOption('session.save_handler', $saveHandler);
}

/**
* Session cache limiter
*/
Expand Down
27 changes: 17 additions & 10 deletions lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,33 +350,36 @@ public function constructorDataProvider()
true,
true,
[
'session.cache_limiter' => 'files',
'session.cache_limiter' => 'private_no_expire',
'session.cookie_lifetime' => 7200,
'session.cookie_path' => '/',
'session.cookie_domain' => 'init.host',
'session.cookie_httponly' => false,
'session.cookie_secure' => false,
'session.save_handler' => 'files'
],
],
'all invalid' => [
true,
false,
[
'session.cache_limiter' => 'files',
'session.cache_limiter' => 'private_no_expire',
'session.cookie_httponly' => false,
'session.cookie_secure' => false,
'session.save_handler' => 'files'
],
],
'invalid_valid' => [
false,
true,
[
'session.cache_limiter' => 'files',
'session.cache_limiter' => 'private_no_expire',
'session.cookie_lifetime' => 3600,
'session.cookie_path' => '/',
'session.cookie_domain' => 'init.host',
'session.cookie_httponly' => false,
'session.cookie_secure' => false,
'session.save_handler' => 'files'
],
],
];
Expand Down Expand Up @@ -429,14 +432,18 @@ protected function getModel($validator)
->will($this->returnValue($dirMock));

$deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
$deploymentConfigMock->expects($this->at(0))
$deploymentConfigMock
->method('get')
->with(Config::PARAM_SESSION_SAVE_PATH)
->will($this->returnValue(null));
$deploymentConfigMock->expects($this->at(1))
->method('get')
->with(Config::PARAM_SESSION_CACHE_LIMITER)
->will($this->returnValue('files'));
->willReturnCallback(function ($configPath) {
switch ($configPath) {
case Config::PARAM_SESSION_SAVE_METHOD:
return 'files';
case Config::PARAM_SESSION_CACHE_LIMITER:
return 'private_no_expire';
default:
return null;
}
});

$this->config = $this->helper->getObject(
\Magento\Framework\Session\Config::class,
Expand Down

0 comments on commit 7b12d50

Please sign in to comment.