From 7b12d50d92e1503f959219a5c8f05ecbef1cc423 Mon Sep 17 00:00:00 2001 From: Magento EngCom Team Date: Wed, 24 Jan 2018 12:11:51 -0600 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#11608 to 2.3-develop branch Applied pull request patch https://github.com/magento/magento2/pull/11608.patch (created by @sylink) based on commit(s): 1. 40d51e4646e47eb3b25ae68b3673ff06e1c51270 2. c7a6c5669660a1dfb909d21a4a7ef70d0d09b8ff Fixed GitHub Issues in 2.3-develop branch: - magento/magento2#9633: Web Setup Wizard 500 error when session storage is configured to use memcache (reported by @dotsoa) --- .../Magento/Framework/Session/ConfigTest.php | 53 ++++++++++--------- .../Magento/Framework/Session/Config.php | 8 +++ .../Session/Test/Unit/ConfigTest.php | 27 ++++++---- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Session/ConfigTest.php b/dev/tests/integration/testsuite/Magento/Framework/Session/ConfigTest.php index 629089ae4d99e..573531cff960a 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Session/ConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Session/ConfigTest.php @@ -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, @@ -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(); @@ -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); diff --git a/lib/internal/Magento/Framework/Session/Config.php b/lib/internal/Magento/Framework/Session/Config.php index 26ae1635f18f1..053bd3e7fd6b9 100644 --- a/lib/internal/Magento/Framework/Session/Config.php +++ b/lib/internal/Magento/Framework/Session/Config.php @@ -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 */ diff --git a/lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php b/lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php index 66fc12b493090..12e28cdb3970d 100644 --- a/lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php +++ b/lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php @@ -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' ], ], ]; @@ -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,