Skip to content

Commit c2e5d77

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-70322: [2.1.x][GitHub] SID in URL even if disabled #9453
1 parent ec26ddf commit c2e5d77

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

dev/tests/integration/testsuite/Magento/Framework/Session/SidResolverTest.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function testGetSid($sid, $useFrontedSid, $isOwnOriginUrl, $testSid)
112112
$this->request->getQuery()->set($this->model->getSessionIdQueryParam($this->session), $testSid);
113113
}
114114
$this->assertEquals($sid, $this->model->getSid($this->session));
115+
$this->assertEquals($useFrontedSid, $this->model->getUseSessionInUrl());
115116
}
116117

117118
/**
@@ -150,10 +151,42 @@ public function testSetGetUseSessionVar()
150151
$this->assertTrue($this->model->getUseSessionVar());
151152
}
152153

153-
public function testSetGetUseSessionInUrl()
154+
/**
155+
* Variations of Use SID on frontend value.
156+
*
157+
* @return array
158+
*/
159+
public function dataProviderSessionInUrl()
160+
{
161+
return [
162+
[true],
163+
[false],
164+
];
165+
}
166+
167+
/**
168+
* Testing "Use SID in URLs" flag.
169+
* Checking that the method returns config value if not explicitly
170+
* overridden.
171+
*
172+
* @param bool $configValue Use SID on frontend config value.
173+
* @dataProvider dataProviderSessionInUrl
174+
*/
175+
public function testSetGetUseSessionInUrl($configValue)
154176
{
155-
$this->assertTrue($this->model->getUseSessionInUrl());
156-
$this->model->setUseSessionInUrl(false);
157-
$this->assertFalse($this->model->getUseSessionInUrl());
177+
$this->scopeConfig->expects(
178+
$this->any()
179+
)->method(
180+
'getValue'
181+
)->with(
182+
\Magento\Framework\Session\SidResolver::XML_PATH_USE_FRONTEND_SID,
183+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
184+
)->will(
185+
$this->returnValue($configValue)
186+
);
187+
188+
$this->assertEquals($configValue, $this->model->getUseSessionInUrl());
189+
$this->model->setUseSessionInUrl(!$configValue);
190+
$this->assertEquals(!$configValue, $this->model->getUseSessionInUrl());
158191
}
159192
}

lib/internal/Magento/Framework/Session/SidResolver.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class SidResolver implements SidResolverInterface
4444
/**
4545
* Use session in URL flag
4646
*
47-
* @var bool
47+
* @var bool|null
4848
* @see \Magento\Framework\UrlInterface
4949
*/
50-
protected $_useSessionInUrl = true;
50+
protected $_useSessionInUrl;
5151

5252
/**
5353
* @var string
@@ -82,10 +82,7 @@ public function __construct(
8282
public function getSid(SessionManagerInterface $session)
8383
{
8484
$sidKey = null;
85-
$useSidOnFrontend = $this->scopeConfig->getValue(
86-
self::XML_PATH_USE_FRONTEND_SID,
87-
$this->_scopeType
88-
);
85+
$useSidOnFrontend = $this->getUseSessionInUrl();
8986
if ($useSidOnFrontend && $this->request->getQuery(
9087
$this->getSessionIdQueryParam($session),
9188
false
@@ -147,13 +144,22 @@ public function setUseSessionInUrl($flag = true)
147144
}
148145

149146
/**
150-
* Retrieve use session in URL flag
147+
* Retrieve use session in URL flag.
151148
*
152149
* @return bool
153150
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
154151
*/
155152
public function getUseSessionInUrl()
156153
{
154+
if ($this->_useSessionInUrl === null) {
155+
//Using config value by default, can be overridden by using the
156+
//setter.
157+
$this->_useSessionInUrl = (bool)$this->scopeConfig->getValue(
158+
self::XML_PATH_USE_FRONTEND_SID,
159+
$this->_scopeType
160+
);
161+
}
162+
157163
return $this->_useSessionInUrl;
158164
}
159165
}

0 commit comments

Comments
 (0)