Skip to content

Commit 5d8e3f3

Browse files
committed
MAGETWO-51929: Web Setup Wizard does not work when Magento is installed in pub
- CR comments
1 parent 95ce85b commit 5d8e3f3

File tree

4 files changed

+93
-14
lines changed

4 files changed

+93
-14
lines changed

app/code/Magento/Backend/Model/Setup/MenuBuilder.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,26 @@
77

88
use Magento\Backend\Model\Menu;
99
use Magento\Backend\Model\Menu\Builder;
10-
use Magento\Framework\App\DocRoot;
10+
use Magento\Framework\App\DocRootLocator;
1111

1212
/**
1313
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
1414
*/
1515
class MenuBuilder
1616
{
17-
1817
/**
19-
* @var DocRoot
18+
* @var DocRootLocator
2019
*/
21-
protected $docRoot;
20+
protected $docRootLocator;
2221

2322
/**
2423
* MenuBuilder constructor.
2524
*
26-
* @param DocRoot $docRoot
25+
* @param DocRootLocator $docRootLocator
2726
*/
28-
public function __construct(DocRoot $docRoot)
27+
public function __construct(DocRootLocator $docRootLocator)
2928
{
30-
$this->docRoot = $docRoot;
29+
$this->docRootLocator = $docRootLocator;
3130
}
3231

3332
/**
@@ -40,7 +39,7 @@ public function __construct(DocRoot $docRoot)
4039
*/
4140
public function afterGetResult(Builder $subject, Menu $menu)
4241
{
43-
if ($this->docRoot->hasThisSubDir('pub', 'setup')) {
42+
if ($this->docRootLocator->isPub()) {
4443
$menu->remove('Magento_Backend::setup_wizard');
4544
}
4645
return $menu;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Model;
8+
9+
use Magento\Backend\Model\Setup\MenuBuilder;
10+
11+
class MenuBuilderTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @dataProvider afterGetResultDataProvider
15+
*
16+
* @param string $isPub
17+
* @param int $times
18+
* @param bool $result
19+
*/
20+
public function testAfterGetResult($isPub, $times)
21+
{
22+
$docRootLocator = $this->getMock('\Magento\Framework\App\DocRootLocator', [], [], '', false);
23+
$docRootLocator->expects($this->once())->method('isPub')->willReturn($isPub);
24+
$model = new MenuBuilder($docRootLocator);
25+
/** @var \Magento\Backend\Model\Menu $menu */
26+
$menu = $this->getMock('\Magento\Backend\Model\Menu', [], [], '', false);
27+
$menu->expects($this->exactly($times))->method('remove')->willReturn(true);
28+
29+
/** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */
30+
$menuBuilder = $this->getMock('\Magento\Backend\Model\Menu\Builder', [], [], '', false);
31+
32+
$this->assertInstanceOf(
33+
'\Magento\Backend\Model\Menu',
34+
$model->afterGetResult($menuBuilder, $menu)
35+
);
36+
}
37+
38+
public function afterGetResultDataProvider()
39+
{
40+
return [[true, 1], [false, 0],];
41+
}
42+
}

lib/internal/Magento/Framework/App/DocRoot.php renamed to lib/internal/Magento/Framework/App/DocRootLocator.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* This class calculates if document root is set to pub
1414
*/
15-
class DocRoot
15+
class DocRootLocator
1616
{
1717
/**
1818
* @var RequestInterface
@@ -37,15 +37,12 @@ public function __construct(RequestInterface $request, ReadFactory $readFactory)
3737
/**
3838
* Returns true if doc root is pub/ and not BP
3939
*
40-
* @param string $dirToCheck
41-
* @param string $missingDir
42-
*
4340
* @return bool
4441
*/
45-
public function hasThisSubDir($dirToCheck, $missingDir)
42+
public function isPub()
4643
{
4744
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
4845
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
49-
return strpos($rootBasePath, $dirToCheck) && !$readDirectory->isExist($rootBasePath + $missingDir);
46+
return strpos($rootBasePath, 'pub') && !$readDirectory->isExist($rootBasePath . 'setup');
5047
}
5148
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\Test\Unit;
8+
9+
use Magento\Framework\App\DocRootLocator;
10+
11+
class DocRootLocatorTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @dataProvider isPubDataProvider
15+
*
16+
* @param string $path
17+
* @param bool $isExist
18+
* @param bool $result
19+
*/
20+
public function testIsPub($path, $isExist, $result)
21+
{
22+
$request = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', false);
23+
$request->expects($this->once())->method('getServer')->willReturn($path);
24+
$reader = $this->getMock('\Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
25+
$reader->expects($this->any())->method('isExist')->willReturn($isExist);
26+
$readFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadFactory', [], [], '', false);
27+
$readFactory->expects($this->once())->method('create')->willReturn($reader);
28+
$model = new DocRootLocator($request, $readFactory);
29+
$this->assertSame($result, $model->isPub());
30+
}
31+
32+
public function isPubDataProvider()
33+
{
34+
return [
35+
['/some/path/to/root', false, false],
36+
['/some/path/to/root', true, false],
37+
['/some/path/to/pub', false, true],
38+
['/some/path/to/pub', true, false],
39+
];
40+
}
41+
}

0 commit comments

Comments
 (0)