Skip to content

Commit 238f457

Browse files
authored
Merge pull request #4111 from magento-trigger/MC-15952
- fixed [2.2] S2 build failed when upgrading from 2.0 to 2.2
2 parents c94674c + 36fe0df commit 238f457

File tree

2 files changed

+34
-78
lines changed

2 files changed

+34
-78
lines changed

setup/src/Magento/Setup/Controller/Session.php

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
*/
66
namespace Magento\Setup\Controller;
77

8-
/**
9-
* Sets up session for setup/index.php/session/prolong or redirects to error page.
10-
*/
118
class Session extends \Zend\Mvc\Controller\AbstractActionController
129
{
1310
/**
@@ -33,7 +30,7 @@ public function __construct(
3330
}
3431

3532
/**
36-
* No index action, return 404 error page.
33+
* No index action, return 404 error page
3734
*
3835
* @return \Zend\View\Model\ViewModel|\Zend\Http\Response
3936
*/
@@ -42,12 +39,11 @@ public function indexAction()
4239
$view = new \Zend\View\Model\ViewModel();
4340
$view->setTemplate('/error/404.phtml');
4441
$this->getResponse()->setStatusCode(\Zend\Http\Response::STATUS_CODE_404);
45-
4642
return $view;
4743
}
4844

4945
/**
50-
* Prolong session.
46+
* Prolong session
5147
*
5248
* @return string
5349
*/
@@ -56,49 +52,39 @@ public function prolongAction()
5652
try {
5753
if ($this->serviceManager->get(\Magento\Framework\App\DeploymentConfig::class)->isAvailable()) {
5854
$objectManager = $this->objectManagerProvider->get();
55+
/** @var \Magento\Framework\App\State $adminAppState */
56+
$adminAppState = $objectManager->get(\Magento\Framework\App\State::class);
57+
$adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
58+
$sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class);
59+
/** @var \Magento\Backend\Model\Url $backendUrl */
60+
$backendUrl = $objectManager->get(\Magento\Backend\Model\Url::class);
61+
$urlPath = parse_url($backendUrl->getBaseUrl(), PHP_URL_PATH);
62+
$cookiePath = $urlPath . 'setup';
63+
$sessionConfig->setCookiePath($cookiePath);
5964
/* @var \Magento\Backend\Model\Auth\Session $session */
60-
$session = $objectManager->get(\Magento\Backend\Model\Auth\Session::class);
61-
// check if session was already set in \Magento\Setup\Mvc\Bootstrap\InitParamListener::authPreDispatch
62-
if (!$session->isSessionExists()) {
63-
/** @var \Magento\Framework\App\State $adminAppState */
64-
$adminAppState = $objectManager->get(\Magento\Framework\App\State::class);
65-
$adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
66-
$sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class);
67-
/** @var \Magento\Backend\Model\Url $backendUrl */
68-
$backendUrl = $objectManager->get(\Magento\Backend\Model\Url::class);
69-
$urlPath = parse_url($backendUrl->getBaseUrl(), PHP_URL_PATH);
70-
$cookiePath = $urlPath . 'setup';
71-
$sessionConfig->setCookiePath($cookiePath);
72-
/* @var \Magento\Backend\Model\Auth\Session $session */
73-
$session = $objectManager->create(
74-
\Magento\Backend\Model\Auth\Session::class,
75-
[
76-
'sessionConfig' => $sessionConfig,
77-
'appState' => $adminAppState
78-
]
79-
);
80-
}
65+
$session = $objectManager->create(
66+
\Magento\Backend\Model\Auth\Session::class,
67+
[
68+
'sessionConfig' => $sessionConfig,
69+
'appState' => $adminAppState
70+
]
71+
);
8172
$session->prolong();
82-
8373
return new \Zend\View\Model\JsonModel(['success' => true]);
8474
}
8575
} catch (\Exception $e) {
8676
}
87-
8877
return new \Zend\View\Model\JsonModel(['success' => false]);
8978
}
9079

9180
/**
92-
* Unlogin action, return 401 error page.
93-
*
9481
* @return \Zend\View\Model\ViewModel|\Zend\Http\Response
9582
*/
9683
public function unloginAction()
9784
{
9885
$view = new \Zend\View\Model\ViewModel();
9986
$view->setTemplate('/error/401.phtml');
10087
$this->getResponse()->setStatusCode(\Zend\Http\Response::STATUS_CODE_401);
101-
10288
return $view;
10389
}
10490
}

setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
use \Magento\Setup\Controller\Session;
1010

11-
/**
12-
* Unit test for \Magento\Setup\Controller\Session.
13-
*/
1411
class SessionTest extends \PHPUnit\Framework\TestCase
1512
{
1613
/**
@@ -19,18 +16,15 @@ class SessionTest extends \PHPUnit\Framework\TestCase
1916
private $objectManager;
2017

2118
/**
22-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ObjectManagerProvider
19+
* @var \PHPUnit_Framework_MockObject_MockObject| \Magento\Setup\Model\ObjectManagerProvider
2320
*/
2421
private $objectManagerProvider;
2522

2623
/**
27-
* @var \PHPUnit_Framework_MockObject_MockObject|\Zend\ServiceManager\ServiceManager
24+
* @var \Zend\ServiceManager\ServiceManager
2825
*/
2926
private $serviceManager;
3027

31-
/**
32-
* @inheritdoc
33-
*/
3428
public function setUp()
3529
{
3630
$objectManager =
@@ -47,40 +41,37 @@ public function setUp()
4741
*/
4842
public function testUnloginAction()
4943
{
50-
$this->objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager);
51-
$deployConfigMock = $this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
52-
$deployConfigMock->expects($this->once())->method('isAvailable')->willReturn(true);
53-
54-
$sessionMock = $this->createPartialMock(
55-
\Magento\Backend\Model\Auth\Session::class,
56-
['prolong', 'isSessionExists']
44+
$this->objectManagerProvider->expects($this->once())->method('get')->will(
45+
$this->returnValue($this->objectManager)
5746
);
58-
$sessionMock->expects($this->once())->method('isSessionExists')->willReturn(false);
47+
$deployConfigMock =
48+
$this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
49+
$deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true));
5950

6051
$stateMock = $this->createPartialMock(\Magento\Framework\App\State::class, ['setAreaCode']);
6152
$stateMock->expects($this->once())->method('setAreaCode');
6253

63-
$sessionConfigMock = $this->createPartialMock(
64-
\Magento\Backend\Model\Session\AdminConfig::class,
65-
['setCookiePath']
66-
);
54+
$sessionConfigMock =
55+
$this->createPartialMock(\Magento\Backend\Model\Session\AdminConfig::class, ['setCookiePath']);
6756
$sessionConfigMock->expects($this->once())->method('setCookiePath');
6857
$urlMock = $this->createMock(\Magento\Backend\Model\Url::class);
6958

7059
$returnValueMap = [
71-
[\Magento\Backend\Model\Auth\Session::class, $sessionMock],
7260
[\Magento\Framework\App\State::class, $stateMock],
7361
[\Magento\Backend\Model\Session\AdminConfig::class, $sessionConfigMock],
74-
[\Magento\Backend\Model\Url::class, $urlMock],
62+
[\Magento\Backend\Model\Url::class, $urlMock]
7563
];
7664

77-
$this->serviceManager->expects($this->once())->method('get')->willReturn($deployConfigMock);
65+
$this->serviceManager->expects($this->once())->method('get')->will($this->returnValue($deployConfigMock));
7866

7967
$this->objectManager->expects($this->atLeastOnce())
8068
->method('get')
81-
->willReturnMap($returnValueMap);
69+
->will($this->returnValueMap($returnValueMap));
8270

83-
$this->objectManager->expects($this->once())->method('create')->willReturn($sessionMock);
71+
$sessionMock = $this->createPartialMock(\Magento\Backend\Model\Auth\Session::class, ['prolong']);
72+
$this->objectManager->expects($this->once())
73+
->method('create')
74+
->will($this->returnValue($sessionMock));
8475
$controller = new Session($this->serviceManager, $this->objectManagerProvider);
8576
$urlMock->expects($this->once())->method('getBaseUrl');
8677
$controller->prolongAction();
@@ -96,25 +87,4 @@ public function testIndexAction()
9687
$viewModel = $controller->unloginAction();
9788
$this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $viewModel);
9889
}
99-
100-
/**
101-
* @covers \Magento\Setup\Controller\SystemConfig::prolongAction
102-
*/
103-
public function testProlongActionWithExistingSession()
104-
{
105-
$this->objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager);
106-
$deployConfigMock = $this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
107-
$deployConfigMock->expects($this->once())->method('isAvailable')->willReturn(true);
108-
$sessionMock = $this->createPartialMock(
109-
\Magento\Backend\Model\Auth\Session::class,
110-
['prolong', 'isSessionExists']
111-
);
112-
$sessionMock->expects($this->once())->method('isSessionExists')->willReturn(true);
113-
114-
$this->serviceManager->expects($this->once())->method('get')->willReturn($deployConfigMock);
115-
$this->objectManager->expects($this->once())->method('get')->willReturn($sessionMock);
116-
117-
$controller = new Session($this->serviceManager, $this->objectManagerProvider);
118-
$this->assertEquals(new \Zend\View\Model\JsonModel(['success' => true]), $controller->prolongAction());
119-
}
12090
}

0 commit comments

Comments
 (0)