Skip to content

#9453 - ported down c2e5d77a9516c8305585e819c2f0a0629648cc14 #12743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function testGetSid($sid, $useFrontedSid, $isOwnOriginUrl, $testSid)
$this->request->getQuery()->set($this->model->getSessionIdQueryParam($this->session), $testSid);
}
$this->assertEquals($sid, $this->model->getSid($this->session));
$this->assertEquals($useFrontedSid, $this->model->getUseSessionInUrl());
}

/**
Expand Down Expand Up @@ -150,10 +151,42 @@ public function testSetGetUseSessionVar()
$this->assertTrue($this->model->getUseSessionVar());
}

public function testSetGetUseSessionInUrl()
/**
* Variations of Use SID on frontend value.
*
* @return array
*/
public function dataProviderSessionInUrl()
{
return [
[true],
[false],
];
}

/**
* Testing "Use SID in URLs" flag.
* Checking that the method returns config value if not explicitly
* overridden.
*
* @param bool $configValue Use SID on frontend config value.
* @dataProvider dataProviderSessionInUrl
*/
public function testSetGetUseSessionInUrl($configValue)
{
$this->assertTrue($this->model->getUseSessionInUrl());
$this->model->setUseSessionInUrl(false);
$this->assertFalse($this->model->getUseSessionInUrl());
$this->scopeConfig->expects(
$this->any()
)->method(
'getValue'
)->with(
\Magento\Framework\Session\SidResolver::XML_PATH_USE_FRONTEND_SID,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)->will(
$this->returnValue($configValue)
);

$this->assertEquals($configValue, $this->model->getUseSessionInUrl());
$this->model->setUseSessionInUrl(!$configValue);
$this->assertEquals(!$configValue, $this->model->getUseSessionInUrl());
}
}
20 changes: 13 additions & 7 deletions lib/internal/Magento/Framework/Session/SidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class SidResolver implements SidResolverInterface
/**
* Use session in URL flag
*
* @var bool
* @var bool|null
* @see \Magento\Framework\UrlInterface
*/
protected $_useSessionInUrl = true;
protected $_useSessionInUrl;

/**
* @var string
Expand Down Expand Up @@ -82,10 +82,7 @@ public function __construct(
public function getSid(SessionManagerInterface $session)
{
$sidKey = null;
$useSidOnFrontend = $this->scopeConfig->getValue(
self::XML_PATH_USE_FRONTEND_SID,
$this->_scopeType
);
$useSidOnFrontend = $this->getUseSessionInUrl();
if ($useSidOnFrontend && $this->request->getQuery(
$this->getSessionIdQueryParam($session),
false
Expand Down Expand Up @@ -147,13 +144,22 @@ public function setUseSessionInUrl($flag = true)
}

/**
* Retrieve use session in URL flag
* Retrieve use session in URL flag.
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getUseSessionInUrl()
{
if ($this->_useSessionInUrl === null) {
//Using config value by default, can be overridden by using the
//setter.
$this->_useSessionInUrl = (bool)$this->scopeConfig->getValue(
self::XML_PATH_USE_FRONTEND_SID,
$this->_scopeType
);
}

return $this->_useSessionInUrl;
}
}