Skip to content

Commit 2dfea8e

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-70638' into 2.3-develop-pr1
2 parents e669d9d + eb42ec6 commit 2dfea8e

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
}
1010

1111
namespace Magento\Framework\Session {
12+
13+
use Magento\Framework\App\State;
1214
// @codingStandardsIgnoreEnd
1315

1416
/**
@@ -59,6 +61,16 @@ class SessionManagerTest extends \PHPUnit\Framework\TestCase
5961
*/
6062
protected $objectManager;
6163

64+
/**
65+
* @var \Magento\Framework\App\RequestInterface
66+
*/
67+
private $request;
68+
69+
/**
70+
* @var State|\PHPUnit_Framework_MockObject_MockObject
71+
*/
72+
private $appState;
73+
6274
protected function setUp()
6375
{
6476
$this->sessionName = 'frontEndSession';
@@ -69,7 +81,18 @@ protected function setUp()
6981
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
7082

7183
/** @var \Magento\Framework\Session\SidResolverInterface $sidResolver */
72-
$this->_sidResolver = $this->objectManager->get(\Magento\Framework\Session\SidResolverInterface::class);
84+
$this->appState = $this->getMockBuilder(State::class)
85+
->setMethods(['getAreaCode'])
86+
->disableOriginalConstructor()
87+
->getMock();
88+
89+
/** @var \Magento\Framework\Session\SidResolver $sidResolver */
90+
$this->_sidResolver = $this->objectManager->create(
91+
\Magento\Framework\Session\SidResolver::class,
92+
[
93+
'appState' => $this->appState,
94+
]
95+
);
7396

7497
$this->request = $this->objectManager->get(\Magento\Framework\App\RequestInterface::class);
7598

@@ -144,6 +167,9 @@ public function testDestroy()
144167
public function testSetSessionId()
145168
{
146169
$sessionId = $this->_model->getSessionId();
170+
$this->appState->expects($this->atLeastOnce())
171+
->method('getAreaCode')
172+
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
147173
$this->_model->setSessionId($this->_sidResolver->getSid($this->_model));
148174
$this->assertEquals($sessionId, $this->_model->getSessionId());
149175

@@ -156,6 +182,9 @@ public function testSetSessionId()
156182
*/
157183
public function testSetSessionIdFromParam()
158184
{
185+
$this->appState->expects($this->atLeastOnce())
186+
->method('getAreaCode')
187+
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
159188
$this->assertNotEquals('test_id', $this->_model->getSessionId());
160189
$this->request->getQuery()->set($this->_sidResolver->getSessionIdQueryParam($this->_model), 'test-id');
161190
$this->_model->setSessionId($this->_sidResolver->getSid($this->_model));

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\Session;
77

8+
use Magento\Framework\App\State;
89
use Zend\Stdlib\Parameters;
910

1011
class SidResolverTest extends \PHPUnit\Framework\TestCase
@@ -49,6 +50,11 @@ class SidResolverTest extends \PHPUnit\Framework\TestCase
4950
*/
5051
protected $request;
5152

53+
/**
54+
* @var State|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $appState;
57+
5258
protected function setUp()
5359
{
5460
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -70,13 +76,19 @@ protected function setUp()
7076

7177
$this->request = $objectManager->get(\Magento\Framework\App\RequestInterface::class);
7278

79+
$this->appState = $this->getMockBuilder(State::class)
80+
->setMethods(['getAreaCode'])
81+
->disableOriginalConstructor()
82+
->getMock();
83+
7384
$this->model = $objectManager->create(
7485
\Magento\Framework\Session\SidResolver::class,
7586
[
7687
'scopeConfig' => $this->scopeConfig,
7788
'urlBuilder' => $this->urlBuilder,
7889
'sidNameMap' => [$this->customSessionName => $this->customSessionQueryParam],
7990
'request' => $this->request,
91+
'appState' => $this->appState,
8092
]
8193
);
8294
}
@@ -95,6 +107,10 @@ public function tearDown()
95107
*/
96108
public function testGetSid($sid, $useFrontedSid, $isOwnOriginUrl, $testSid)
97109
{
110+
$this->appState->expects($this->atLeastOnce())
111+
->method('getAreaCode')
112+
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
113+
98114
$this->scopeConfig->expects(
99115
$this->any()
100116
)->method(

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
namespace Magento\Framework\Session;
99

10+
use Magento\Framework\App\State;
11+
1012
class SidResolver implements SidResolverInterface
1113
{
1214
/**
@@ -54,34 +56,47 @@ class SidResolver implements SidResolverInterface
5456
*/
5557
protected $_scopeType;
5658

59+
/**
60+
* @var State
61+
*/
62+
private $appState;
63+
5764
/**
5865
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
5966
* @param \Magento\Framework\UrlInterface $urlBuilder
6067
* @param \Magento\Framework\App\RequestInterface $request
6168
* @param string $scopeType
6269
* @param array $sidNameMap
70+
* @param State|null $appState
6371
*/
6472
public function __construct(
6573
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
6674
\Magento\Framework\UrlInterface $urlBuilder,
6775
\Magento\Framework\App\RequestInterface $request,
6876
$scopeType,
69-
array $sidNameMap = []
77+
array $sidNameMap = [],
78+
State $appState = null
7079
) {
7180
$this->scopeConfig = $scopeConfig;
7281
$this->urlBuilder = $urlBuilder;
7382
$this->request = $request;
7483
$this->sidNameMap = $sidNameMap;
7584
$this->_scopeType = $scopeType;
85+
$this->appState = $appState ?: \Magento\Framework\App\ObjectManager::getInstance()->get(State::class);
7686
}
7787

7888
/**
7989
* @param SessionManagerInterface $session
80-
* @return string
90+
* @return string|null
8191
*/
8292
public function getSid(SessionManagerInterface $session)
8393
{
94+
if ($this->appState->getAreaCode() !== \Magento\Framework\App\Area::AREA_FRONTEND) {
95+
return null;
96+
}
97+
8498
$sidKey = null;
99+
85100
$useSidOnFrontend = $this->getUseSessionInUrl();
86101
if ($useSidOnFrontend && $this->request->getQuery(
87102
$this->getSessionIdQueryParam($session),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface SidResolverInterface
2222
* Get SID
2323
*
2424
* @param \Magento\Framework\Session\SessionManagerInterface $session
25-
* @return string
25+
* @return string|null
2626
*/
2727
public function getSid(\Magento\Framework\Session\SessionManagerInterface $session);
2828

0 commit comments

Comments
 (0)