-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'ogre/PR_Branch' into develop
- Loading branch information
Showing
13 changed files
with
260 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Backend\Model\Setup; | ||
|
||
use Magento\Backend\Model\Menu; | ||
use Magento\Backend\Model\Menu\Builder; | ||
use Magento\Framework\App\DocRootLocator; | ||
|
||
/** | ||
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified. | ||
*/ | ||
class MenuBuilder | ||
{ | ||
/** | ||
* @var DocRootLocator | ||
*/ | ||
protected $docRootLocator; | ||
|
||
/** | ||
* MenuBuilder constructor. | ||
* | ||
* @param DocRootLocator $docRootLocator | ||
*/ | ||
public function __construct(DocRootLocator $docRootLocator) | ||
{ | ||
$this->docRootLocator = $docRootLocator; | ||
} | ||
|
||
/** | ||
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified. | ||
* | ||
* @param Builder $subject | ||
* @param Menu $menu | ||
* @return Menu | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterGetResult(Builder $subject, Menu $menu) | ||
{ | ||
if ($this->docRootLocator->isPub()) { | ||
$menu->remove('Magento_Backend::setup_wizard'); | ||
} | ||
return $menu; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/code/Magento/Backend/Test/Unit/Model/MenuBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Backend\Test\Unit\Model; | ||
|
||
use Magento\Backend\Model\Setup\MenuBuilder; | ||
|
||
class MenuBuilderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider afterGetResultDataProvider | ||
* | ||
* @param string $isPub | ||
* @param int $times | ||
* @param bool $result | ||
*/ | ||
public function testAfterGetResult($isPub, $times) | ||
{ | ||
$docRootLocator = $this->getMock('\Magento\Framework\App\DocRootLocator', [], [], '', false); | ||
$docRootLocator->expects($this->once())->method('isPub')->willReturn($isPub); | ||
$model = new MenuBuilder($docRootLocator); | ||
/** @var \Magento\Backend\Model\Menu $menu */ | ||
$menu = $this->getMock('\Magento\Backend\Model\Menu', [], [], '', false); | ||
$menu->expects($this->exactly($times))->method('remove')->willReturn(true); | ||
|
||
/** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */ | ||
$menuBuilder = $this->getMock('\Magento\Backend\Model\Menu\Builder', [], [], '', false); | ||
|
||
$this->assertInstanceOf( | ||
'\Magento\Backend\Model\Menu', | ||
$model->afterGetResult($menuBuilder, $menu) | ||
); | ||
} | ||
|
||
public function afterGetResultDataProvider() | ||
{ | ||
return [[true, 1], [false, 0],]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\App; | ||
|
||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Filesystem\Directory\ReadFactory; | ||
|
||
/** | ||
* This class calculates if document root is set to pub | ||
*/ | ||
class DocRootLocator | ||
{ | ||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var ReadFactory | ||
*/ | ||
private $readFactory; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param ReadFactory $readFactory | ||
*/ | ||
public function __construct(RequestInterface $request, ReadFactory $readFactory) | ||
{ | ||
$this->request = $request; | ||
$this->readFactory = $readFactory; | ||
} | ||
|
||
/** | ||
* Returns true if doc root is pub/ and not BP | ||
* | ||
* @return bool | ||
*/ | ||
public function isPub() | ||
{ | ||
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT'); | ||
$readDirectory = $this->readFactory->create(DirectoryList::ROOT); | ||
return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup'); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
lib/internal/Magento/Framework/App/Test/Unit/DocRootLocatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\App\Test\Unit; | ||
|
||
use Magento\Framework\App\DocRootLocator; | ||
|
||
class DocRootLocatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider isPubDataProvider | ||
* | ||
* @param string $path | ||
* @param bool $isExist | ||
* @param bool $result | ||
*/ | ||
public function testIsPub($path, $isExist, $result) | ||
{ | ||
$request = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', false); | ||
$request->expects($this->once())->method('getServer')->willReturn($path); | ||
$reader = $this->getMock('\Magento\Framework\Filesystem\Directory\Read', [], [], '', false); | ||
$reader->expects($this->any())->method('isExist')->willReturn($isExist); | ||
$readFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadFactory', [], [], '', false); | ||
$readFactory->expects($this->once())->method('create')->willReturn($reader); | ||
$model = new DocRootLocator($request, $readFactory); | ||
$this->assertSame($result, $model->isPub()); | ||
} | ||
|
||
public function isPubDataProvider() | ||
{ | ||
return [ | ||
['/some/path/to/root', false, false], | ||
['/some/path/to/root', true, false], | ||
['/some/path/to/pub', false, true], | ||
['/some/path/to/pub', true, false], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.