8 use \Magento\Setup\Mvc\Bootstrap\InitParamListener;
12 use Zend\Mvc\MvcEvent;
28 private $callbackHandler;
37 $events = $this->prepareEventManager();
38 $this->listener->attach($events);
43 $events = $this->prepareEventManager();
44 $this->listener->attach($events);
45 $events->expects($this->once())->method(
'detach')->with($this->callbackHandler)->willReturn(
true);
46 $this->listener->detach($events);
49 public function testOnBootstrap()
52 $mvcEvent = $this->createMock(\
Zend\Mvc\MvcEvent::class);
53 $mvcApplication = $this->getMockBuilder(\
Zend\Mvc\Application::class)->disableOriginalConstructor()->getMock();
54 $mvcEvent->expects($this->once())->method(
'getApplication')->willReturn($mvcApplication);
55 $serviceManager = $this->createMock(\
Zend\ServiceManager\ServiceManager::class);
56 $initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS][
DirectoryList::ROOT] = [
'path' =>
'/test'];
57 $serviceManager->expects($this->once())->method(
'get')
58 ->willReturn($initParams);
59 $serviceManager->expects($this->exactly(2))->method(
'setService')
62 \
Magento\Framework\
App\Filesystem\DirectoryList::class,
63 $this->isInstanceOf(\
Magento\Framework\
App\Filesystem\DirectoryList::class),
66 \
Magento\Framework\Filesystem::class,
67 $this->isInstanceOf(\
Magento\Framework\Filesystem::class),
70 $mvcApplication->expects($this->any())->method(
'getServiceManager')->willReturn($serviceManager);
72 $eventManager = $this->getMockForAbstractClass(\
Zend\EventManager\EventManagerInterface::class);
73 $mvcApplication->expects($this->any())->method(
'getEventManager')->willReturn($eventManager);
74 $eventManager->expects($this->any())->method(
'attach');
76 $this->listener->onBootstrap($mvcEvent);
81 $initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] =
84 $directoryList = $this->listener->createDirectoryList($initParams);
94 $this->listener->createDirectoryList([]);
97 public function testCreateServiceNotConsole()
102 $serviceLocator = $this->createMock(\
Zend\ServiceManager\ServiceLocatorInterface::class);
103 $mvcApplication = $this->getMockBuilder(\
Zend\Mvc\Application::class)->disableOriginalConstructor()->getMock();
104 $request = $this->createMock(\
Zend\Stdlib\RequestInterface::class);
105 $mvcApplication->expects($this->any())->method(
'getRequest')->willReturn(
$request);
106 $serviceLocator->expects($this->once())->method(
'get')->with(
'Application')
107 ->willReturn($mvcApplication);
108 $this->assertEquals([], $this->listener->createService($serviceLocator));
119 public function testCreateService($zfAppConfig, $env, $cliParam, $expectedArray)
121 foreach ($env as $envKey => $envValue) {
122 $_SERVER[$envKey] = $envValue;
124 $listener =
new InitParamListener();
128 $serviceLocator = $this->createMock(\
Zend\ServiceManager\ServiceLocatorInterface::class);
129 $mvcApplication = $this->getMockBuilder(\
Zend\Mvc\Application::class)->disableOriginalConstructor()->getMock();
130 $request = $this->getMockBuilder(\
Zend\Console\Request::class)->disableOriginalConstructor()->getMock();
132 ->method(
'getContent')
134 $cliParam ? [
'install',
'--magento-init-params=' . $cliParam] : [
'install']
136 $mvcApplication->expects($this->any())->method(
'getConfig')->willReturn(
140 $mvcApplication->expects($this->any())->method(
'getRequest')->willReturn(
$request);
141 $serviceLocator->expects($this->once())->method(
'get')->with(
'Application')
142 ->willReturn($mvcApplication);
144 $this->assertEquals($expectedArray, $listener->createService($serviceLocator));
153 'none' => [[], [],
'', []],
154 'mage_mode App' => [[
'MAGE_MODE' =>
'developer'], [],
'', [
'MAGE_MODE' =>
'developer']],
155 'mage_mode Env' => [[], [
'MAGE_MODE' =>
'developer'],
'', [
'MAGE_MODE' =>
'developer']],
156 'mage_mode CLI' => [[], [],
'MAGE_MODE=developer', [
'MAGE_MODE' =>
'developer']],
157 'one MAGE_DIRS CLI' => [
160 'MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/magento2',
161 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2']],
'MAGE_MODE' =>
'developer'],
163 'two MAGE_DIRS CLI' => [
166 'MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/magento2&MAGE_DIRS[cache][path]=/tmp/cache',
168 'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2'],
'cache' => [
'path' =>
'/tmp/cache']],
169 'MAGE_MODE' =>
'developer',
172 'mage_mode only' => [[], [],
'MAGE_MODE=developer', [
'MAGE_MODE' =>
'developer']],
175 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2']],
'MAGE_MODE' =>
'developer'],
177 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2']],
'MAGE_MODE' =>
'developer'],
182 'MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/magento2&MAGE_DIRS[cache][path]=/tmp/cache',
184 'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2'],
'cache' => [
'path' =>
'/tmp/cache']],
185 'MAGE_MODE' =>
'developer',
188 'Env overwrites App' => [
189 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/App']],
'MAGE_MODE' =>
'developer'],
190 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/Env']],
'MAGE_MODE' =>
'developer'],
192 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/Env']],
'MAGE_MODE' =>
'developer'],
194 'CLI overwrites Env' => [
195 [
'MAGE_MODE' =>
'developer'],
196 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/Env']]],
197 'MAGE_DIRS[base][path]=/var/www/magento2/CLI',
198 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/CLI']],
'MAGE_MODE' =>
'developer'],
200 'CLI overwrites All' => [
201 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/App']],
'MAGE_MODE' =>
'production'],
202 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/Env']]],
203 'MAGE_DIRS[base][path]=/var/www/magento2/CLI',
204 [
'MAGE_DIRS' => [
'base' => [
'path' =>
'/var/www/magento2/CLI']],
'MAGE_MODE' =>
'developer'],
209 public function testCreateFilesystem()
211 $testPath =
'test/path/';
217 $directoryList = $this->getMockBuilder(\
Magento\Framework\
App\Filesystem\DirectoryList::class)
218 ->disableOriginalConstructor()->getMock();
219 $directoryList->expects($this->any())->method(
'getPath')->willReturn($testPath);
220 $filesystem = $this->listener->createFilesystem($directoryList);
223 $this->assertEquals($testPath,
$filesystem->getDirectoryRead(
'app')->getAbsolutePath());
231 private function prepareEventManager()
233 $this->callbackHandler = $this->getMockBuilder(\
Zend\Stdlib\CallbackHandler::class)
234 ->disableOriginalConstructor()
238 $eventManager = $this->createMock(\
Zend\EventManager\EventManagerInterface::class);
240 $sharedManager = $this->createMock(\
Zend\EventManager\SharedEventManager::class);
241 $sharedManager->expects($this->once())->method(
'attach')->with(
242 \
Zend\Mvc\Application::class,
243 MvcEvent::EVENT_BOOTSTRAP,
244 [$this->listener,
'onBootstrap']
245 )->willReturn($this->callbackHandler);
246 $eventManager->expects($this->once())->method(
'getSharedManager')->willReturn($sharedManager);
248 return $eventManager;
256 $cookiePath =
'test';
257 $eventMock = $this->getMockBuilder(\
Zend\Mvc\MvcEvent::class)
258 ->disableOriginalConstructor()
260 $routeMatchMock = $this->getMockBuilder(\
Zend\Mvc\Router\Http\RouteMatch::class)
261 ->disableOriginalConstructor()
263 $applicationMock = $this->getMockBuilder(\
Zend\Mvc\Application::class)
264 ->disableOriginalConstructor()
266 $serviceManagerMock = $this->getMockBuilder(\
Zend\ServiceManager\ServiceManager::class)
267 ->disableOriginalConstructor()
269 $deploymentConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\DeploymentConfig::class)
270 ->disableOriginalConstructor()
272 $deploymentConfigMock->expects($this->once())
273 ->method(
'isAvailable')
275 $omProvider = $this->getMockBuilder(\
Magento\Setup\Model\ObjectManagerProvider::class)
276 ->disableOriginalConstructor()
278 $objectManagerMock = $this->getMockForAbstractClass(\
Magento\Framework\ObjectManagerInterface::class);
279 $adminAppStateMock = $this->getMockBuilder(\
Magento\Framework\
App\State::class)
280 ->disableOriginalConstructor()
282 $sessionConfigMock = $this->getMockBuilder(\
Magento\Backend\Model\Session\AdminConfig::class)
283 ->disableOriginalConstructor()
285 $backendAppListMock = $this->getMockBuilder(\
Magento\Backend\
App\BackendAppList::class)
286 ->disableOriginalConstructor()
288 $backendAppMock = $this->getMockBuilder(\
Magento\Backend\
App\BackendApp::class)
289 ->disableOriginalConstructor()
291 $urlMock = $this->getMockBuilder(\
Magento\Backend\Model\Url::class)
292 ->disableOriginalConstructor()
294 $authenticationMock = $this->getMockBuilder(\
Magento\Backend\Model\Auth::class)
295 ->disableOriginalConstructor()
297 $adminSessionMock = $this->getMockBuilder(\
Magento\Backend\Model\Auth\Session::class)
298 ->disableOriginalConstructor()
300 $responseMock = $this->getMockBuilder(\
Zend\Http\Response::class)
301 ->disableOriginalConstructor()
303 $headersMock = $this->getMockBuilder(\
Zend\Http\Headers::class)
304 ->disableOriginalConstructor()
307 $routeMatchMock->expects($this->exactly(2))
310 [
'controller',
null,
'testController'],
311 [
'action',
null,
'testAction']
313 $eventMock->expects($this->once())
314 ->method(
'getRouteMatch')
315 ->willReturn($routeMatchMock);
316 $eventMock->expects($this->once())
317 ->method(
'getApplication')
318 ->willReturn($applicationMock);
319 $serviceManagerMock->expects($this->any())
324 \
Magento\Framework\
App\DeploymentConfig::class,
326 $deploymentConfigMock,
329 \
Magento\Setup\Model\ObjectManagerProvider::class,
335 $objectManagerMock->expects($this->any())
344 \
Magento\Backend\Model\Session\AdminConfig::class,
352 \
Magento\Backend\Model\Auth::class,
357 $objectManagerMock->expects($this->any())
362 \
Magento\Backend\Model\Auth\Session::class,
364 'sessionConfig' => $sessionConfigMock,
365 'appState' => $adminAppStateMock
370 \
Magento\Backend\Model\Url::class,
376 $omProvider->expects($this->once())
378 ->willReturn($objectManagerMock);
379 $adminAppStateMock->expects($this->once())
380 ->method(
'setAreaCode')
381 ->with(\
Magento\Framework\
App\Area::AREA_ADMINHTML);
382 $applicationMock->expects($this->once())
383 ->method(
'getServiceManager')
384 ->willReturn($serviceManagerMock);
385 $backendAppMock->expects($this->once())
386 ->method(
'getCookiePath')
387 ->willReturn($cookiePath);
388 $urlMock->expects($this->once())
389 ->method(
'getBaseUrl')
390 ->willReturn(
'http://base-url/');
391 $sessionConfigMock->expects($this->once())
392 ->method(
'setCookiePath')
393 ->with(
'/' . $cookiePath);
394 $backendAppListMock->expects($this->once())
395 ->method(
'getBackendApp')
396 ->willReturn($backendAppMock);
397 $authenticationMock->expects($this->once())
398 ->method(
'isLoggedIn')
400 $adminSessionMock->expects($this->once())
401 ->method(
'isAllowed')
402 ->with(
'Magento_Backend::setup_wizard',
null)
404 $adminSessionMock->expects($this->once())
406 $eventMock->expects($this->once())
407 ->method(
'getResponse')
408 ->willReturn($responseMock);
409 $responseMock->expects($this->once())
410 ->method(
'getHeaders')
411 ->willReturn($headersMock);
412 $headersMock->expects($this->once())
413 ->method(
'addHeaderLine');
414 $responseMock->expects($this->once())
415 ->method(
'setStatusCode')
417 $eventMock->expects($this->once())
418 ->method(
'stopPropagation');
421 $this->listener->authPreDispatch($eventMock),
428 $eventMock = $this->getMockBuilder(\
Zend\Mvc\MvcEvent::class)
429 ->disableOriginalConstructor()
431 $routeMatchMock = $this->getMockBuilder(\
Zend\Mvc\Router\Http\RouteMatch::class)
432 ->disableOriginalConstructor()
434 $deploymentConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\DeploymentConfig::class)
435 ->disableOriginalConstructor()
438 $deploymentConfigMock->expects($this->never())
439 ->method(
'isAvailable');
440 $routeMatchMock->expects($this->exactly(2))
443 [
'controller',
null, \
Magento\Setup\Controller\Session::class],
444 [
'action',
null,
'unlogin']
446 $eventMock->expects($this->once())
447 ->method(
'getRouteMatch')
448 ->willReturn($routeMatchMock);
449 $eventMock->expects($this->never())
450 ->method(
'getApplication');
453 $this->listener->authPreDispatch($eventMock),
testAuthPreDispatchSkip()
createServiceDataProvider()
testCreateDirectoryListException()
testCreateDirectoryList()