12 use \Magento\Framework\Session\Config;
56 $this->helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
58 $this->validatorMock = $this->getMockBuilder(\
Magento\Framework\
Validator\ValidatorInterface::class)
59 ->disableOriginalConstructor()
61 $this->validatorMock->expects($this->any())
68 $this->
getModel($this->validatorMock);
69 $preVal = $this->config->getOptions();
70 $this->config->setOptions(
'');
71 $this->assertEquals($preVal, $this->config->getOptions());
79 $this->
getModel($this->validatorMock);
82 $this->assertSame(
$value, $this->config->{$getter}());
91 [
'save_path',
'getSavePath',
__DIR__],
92 [
'name',
'getName',
'FOOBAR'],
93 [
'gc_probability',
'getGcProbability', 42],
94 [
'gc_divisor',
'getGcDivisor', 3],
95 [
'gc_maxlifetime',
'getGcMaxlifetime', 180],
96 [
'serialize_handler',
'getSerializeHandler',
'php_binary'],
97 [
'cookie_lifetime',
'getCookieLifetime', 180],
98 [
'cookie_path',
'getCookiePath',
'/foo/bar'],
99 [
'cookie_domain',
'getCookieDomain',
'framework.zend.com'],
100 [
'cookie_secure',
'getCookieSecure',
true],
101 [
'cookie_httponly',
'getCookieHttpOnly',
true],
102 [
'use_cookies',
'getUseCookies',
false],
103 [
'use_only_cookies',
'getUseOnlyCookies',
true],
104 [
'referer_check',
'getRefererCheck',
'foobar'],
105 [
'entropy_file',
'getEntropyFile',
__FILE__],
106 [
'entropy_length',
'getEntropyLength', 42],
107 [
'cache_limiter',
'getCacheLimiter',
'private'],
108 [
'cache_expire',
'getCacheExpire', 42],
109 [
'use_trans_sid',
'getUseTransSid',
true],
110 [
'hash_function',
'getHashFunction',
'md5'],
111 [
'hash_bits_per_character',
'getHashBitsPerCharacter', 5],
112 [
'url_rewriter_tags',
'getUrlRewriterTags',
'a=href']
118 $this->getModel($this->validatorMock);
119 $appStateProperty = new \ReflectionProperty(\
Magento\Framework\Session\Config::class,
'options');
120 $appStateProperty->setAccessible(
true);
121 $original = $appStateProperty->getValue($this->config);
122 $valueForTest = [
'test' =>
'test2'];
123 $appStateProperty->setValue($this->config, $valueForTest);
124 $this->assertEquals($valueForTest, $this->config->getOptions());
125 $this->assertEquals($valueForTest, $this->config->toArray());
126 $appStateProperty->setValue($this->config, $original);
127 $this->assertEquals($original, $this->config->getOptions());
128 $this->assertEquals($original, $this->config->toArray());
133 $this->getModel($this->validatorMock);
134 $this->config->setName(
'FOOBAR');
135 $this->assertEquals(
'FOOBAR', $this->config->getName());
140 $this->getModel($this->validatorMock);
141 $this->config->setCookieLifetime(20);
142 $this->assertEquals(20, $this->config->getCookieLifetime());
147 $this->getModel($this->validatorMock);
148 $this->config->setCookieLifetime(0);
149 $this->assertEquals(0,
ini_get(
'session.cookie_lifetime'));
154 $validatorMock = $this->getMockBuilder(\
Magento\Framework\
Validator\ValidatorInterface::class)
155 ->disableOriginalConstructor()
157 $validatorMock->expects($this->any())
160 $this->getModel($validatorMock);
161 $preVal = $this->config->getCookieLifetime();
162 $this->config->setCookieLifetime(
'foobar_bogus');
163 $this->assertEquals($preVal, $this->config->getCookieLifetime());
168 $validatorMock = $this->getMockBuilder(\
Magento\Framework\
Validator\ValidatorInterface::class)
169 ->disableOriginalConstructor()
171 $validatorMock->expects($this->any())
174 $this->getModel($validatorMock);
175 $preVal = $this->config->getCookieLifetime();
176 $this->config->setCookieLifetime(-1);
177 $this->assertEquals($preVal, $this->config->getCookieLifetime());
182 $this->getModel($this->validatorMock);
183 $this->expectException(
'\BadMethodCallException');
184 $this->expectExceptionMessage(
'Method "methodThatNotExist" does not exist in Magento\Framework\Session\Config');
185 $this->config->methodThatNotExist();
190 $this->getModel($this->validatorMock);
191 $this->assertSame((
bool)
ini_get(
'session.cookie_secure'), $this->config->getCookieSecure());
196 $this->getModel($this->validatorMock);
198 $this->config->setCookieSecure(
$value);
199 $this->assertEquals(
$value, $this->config->getCookieSecure());
204 $this->getModel($this->validatorMock);
205 $this->config->setCookieDomain(
'example.com');
206 $this->assertEquals(
'example.com', $this->config->getCookieDomain());
211 $this->getModel($this->validatorMock);
212 $this->config->setCookieDomain(
'');
213 $this->assertEquals(
'', $this->config->getCookieDomain());
218 $validatorMock = $this->getMockBuilder(\
Magento\Framework\
Validator\ValidatorInterface::class)
219 ->disableOriginalConstructor()
221 $validatorMock->expects($this->any())
224 $this->getModel($validatorMock);
225 $preVal = $this->config->getCookieDomain();
226 $this->config->setCookieDomain(24);
227 $this->assertEquals($preVal, $this->config->getCookieDomain());
232 $validatorMock = $this->getMockBuilder(\
Magento\Framework\
Validator\ValidatorInterface::class)
233 ->disableOriginalConstructor()
235 $validatorMock->expects($this->any())
238 $this->getModel($validatorMock);
239 $preVal = $this->config->getCookieDomain();
240 $this->config->setCookieDomain(
'D:\\WINDOWS\\System32\\drivers\\etc\\hosts');
241 $this->assertEquals($preVal, $this->config->getCookieDomain());
246 $this->getModel($this->validatorMock);
247 $this->assertSame((
bool)
ini_get(
'session.cookie_httponly'), $this->config->getCookieHttpOnly());
252 $this->getModel($this->validatorMock);
254 $this->config->setCookieHttpOnly(
$value);
255 $this->assertEquals(
$value, $this->config->getCookieHttpOnly());
260 $this->getModel($this->validatorMock);
261 $this->assertSame((
bool)
ini_get(
'session.use_cookies'), $this->config->getUseCookies());
266 $this->getModel($this->validatorMock);
268 $this->config->setUseCookies(
$value);
269 $this->assertEquals(
$value, (
bool)$this->config->getUseCookies());
274 $this->getModel($this->validatorMock);
275 $this->assertSame((
bool)
ini_get(
'session.use_only_cookies'), $this->config->getUseOnlyCookies());
280 $this->getModel($this->validatorMock);
282 $this->config->setOption(
'use_only_cookies',
$value);
283 $this->assertEquals(
$value, (
bool)$this->config->getOption(
'use_only_cookies'));
288 $this->getModel($this->validatorMock);
289 $this->assertSame(
ini_get(
'session.referer_check'), $this->config->getRefererCheck());
294 $this->getModel($this->validatorMock);
295 $this->config->setOption(
'referer_check',
'FOOBAR');
296 $this->assertEquals(
'FOOBAR', $this->config->getOption(
'referer_check'));
301 $this->getModel($this->validatorMock);
302 $this->config->setOption(
'referer_check',
'');
303 $this->assertEquals(
'', $this->config->getOption(
'referer_check'));
308 $this->getModel($this->validatorMock);
309 $this->config->setSavePath(
'some_save_path');
310 $this->assertEquals($this->config->getOption(
'save_path'),
'some_save_path');
321 $validatorMock = $this->getMockBuilder(\
Magento\Framework\
Validator\ValidatorInterface::class)
322 ->disableOriginalConstructor()
325 $validatorMock->expects($this->any())
327 ->willReturn($isValid);
329 for ($x = 0; $x<6; $x++) {
331 $validatorMock->expects($this->at($x))
335 $validatorMock->expects($this->at($x))
342 $this->getModel($validatorMock);
344 $this->assertEquals($expected, $this->config->getOptions());
357 'session.cache_limiter' =>
'private_no_expire',
358 'session.cookie_lifetime' => 7200,
359 'session.cookie_path' =>
'/',
360 'session.cookie_domain' =>
'init.host',
361 'session.cookie_httponly' =>
false,
362 'session.cookie_secure' =>
false,
363 'session.save_handler' =>
'files' 370 'session.cache_limiter' =>
'private_no_expire',
371 'session.cookie_httponly' =>
false,
372 'session.cookie_secure' =>
false,
373 'session.save_handler' =>
'files' 380 'session.cache_limiter' =>
'private_no_expire',
381 'session.cookie_lifetime' => 3600,
382 'session.cookie_path' =>
'/',
383 'session.cookie_domain' =>
'init.host',
384 'session.cookie_httponly' =>
false,
385 'session.cookie_secure' =>
false,
386 'session.save_handler' =>
'files' 400 $this->requestMock = $this->createPartialMock(
402 [
'getBasePath',
'isSecure',
'getHttpHost']
404 $this->requestMock->expects($this->atLeastOnce())->method(
'getBasePath')->will($this->returnValue(
'/'));
405 $this->requestMock->expects(
410 $this->returnValue(
'init.host')
413 $this->validatorFactoryMock = $this->getMockBuilder(\
Magento\Framework\ValidatorFactory::class)
414 ->setMethods([
'setInstanceName',
'create'])
415 ->disableOriginalConstructor()
417 $this->validatorFactoryMock->expects($this->any())
418 ->method(
'setInstanceName')
420 $this->validatorFactoryMock->expects($this->any())
422 ->willReturn($validator);
424 $this->configMock = $this->createMock(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class);
425 $getValueReturnMap = [
426 [
'test_web/test_cookie/test_cookie_lifetime',
'store',
null, 7200],
427 [
'web/cookie/cookie_path',
'store',
null,
''],
429 $this->configMock->method(
'getValue')
430 ->will($this->returnValueMap($getValueReturnMap));
432 $filesystemMock = $this->createMock(\
Magento\Framework\Filesystem::class);
433 $dirMock = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\WriteInterface::class);
434 $filesystemMock->expects($this->any())
435 ->method(
'getDirectoryWrite')
436 ->will($this->returnValue($dirMock));
438 $deploymentConfigMock = $this->createMock(\
Magento\Framework\
App\DeploymentConfig::class);
439 $deploymentConfigMock
441 ->willReturnCallback(
function ($configPath) {
442 switch ($configPath) {
446 return 'private_no_expire';
452 $this->config = $this->helper->getObject(
453 \
Magento\Framework\Session\Config::class,
455 'scopeConfig' => $this->configMock,
456 'validatorFactory' => $this->validatorFactoryMock,
457 'scopeType' => \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
458 'cacheLimiter' =>
'files',
459 'lifetimePath' =>
'test_web/test_cookie/test_cookie_lifetime',
460 'request' => $this->requestMock,
461 'filesystem' => $filesystemMock,
462 'deploymentConfig' => $deploymentConfigMock,
const PARAM_SESSION_CACHE_LIMITER
testConstructor($isValidSame, $isValid, $expected)
testSettingInvalidCookieLifetime()
testSetOptionsInvalidValue()
testUseOnlyCookiesIsMutable()
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testRefererCheckDefaultsToIniSettings()
testCookieSecureIsMutable()
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
testSettingInvalidCookieLifetime2()
testUseCookiesIsMutable()
testSettingInvalidCookieDomain()
testUseCookiesDefaultsToIniSettings()
testCookieHttpOnlyIsMutable()
testCookieDomainIsMutable()
testCookieLifetimeIsMutable()
testRefererCheckMayBeEmpty()
testCookieDomainCanBeEmpty()
testCookieHttpOnlyDefaultsToIniSettings()
testRefererCheckIsMutable()
testSetOptions($option, $getter, $value)
constructorDataProvider()
const PARAM_SESSION_SAVE_METHOD
testSettingInvalidCookieDomain2()
testUseOnlyCookiesDefaultsToIniSettings()
testCookieSecureDefaultsToIniSettings()
testCookieLifetimeCanBeZero()