Skip to content

Commit 4c7e58c

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-51929-setup-wizard-from-pub' into PR_Branch
2 parents 430ce9c + 5d8e3f3 commit 4c7e58c

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Model\Setup;
7+
8+
use Magento\Backend\Model\Menu;
9+
use Magento\Backend\Model\Menu\Builder;
10+
use Magento\Framework\App\DocRootLocator;
11+
12+
/**
13+
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
14+
*/
15+
class MenuBuilder
16+
{
17+
/**
18+
* @var DocRootLocator
19+
*/
20+
protected $docRootLocator;
21+
22+
/**
23+
* MenuBuilder constructor.
24+
*
25+
* @param DocRootLocator $docRootLocator
26+
*/
27+
public function __construct(DocRootLocator $docRootLocator)
28+
{
29+
$this->docRootLocator = $docRootLocator;
30+
}
31+
32+
/**
33+
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
34+
*
35+
* @param Builder $subject
36+
* @param Menu $menu
37+
* @return Menu
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function afterGetResult(Builder $subject, Menu $menu)
41+
{
42+
if ($this->docRootLocator->isPub()) {
43+
$menu->remove('Magento_Backend::setup_wizard');
44+
}
45+
return $menu;
46+
}
47+
}
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+
}

app/code/Magento/Backend/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,7 @@
214214
</argument>
215215
</arguments>
216216
</type>
217+
<type name="Magento\Backend\Model\Menu\Builder">
218+
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
219+
</type>
217220
</config>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem\Directory\ReadFactory;
11+
12+
/**
13+
* This class calculates if document root is set to pub
14+
*/
15+
class DocRootLocator
16+
{
17+
/**
18+
* @var RequestInterface
19+
*/
20+
private $request;
21+
22+
/**
23+
* @var ReadFactory
24+
*/
25+
private $readFactory;
26+
27+
/**
28+
* @param RequestInterface $request
29+
* @param ReadFactory $readFactory
30+
*/
31+
public function __construct(RequestInterface $request, ReadFactory $readFactory)
32+
{
33+
$this->request = $request;
34+
$this->readFactory = $readFactory;
35+
}
36+
37+
/**
38+
* Returns true if doc root is pub/ and not BP
39+
*
40+
* @return bool
41+
*/
42+
public function isPub()
43+
{
44+
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
45+
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
46+
return strpos($rootBasePath, 'pub') && !$readDirectory->isExist($rootBasePath . 'setup');
47+
}
48+
}
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)