-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
168 additions
and
14 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
55 changes: 55 additions & 0 deletions
55
app/code/Magento/Config/Model/Config/Reader/Source/Deployed/DocumentRoot.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,55 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Config\Model\Config\Reader\Source\Deployed; | ||
|
||
use Magento\Framework\Config\ConfigOptionsListConstants; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\App\DeploymentConfig; | ||
|
||
/** | ||
* Class DocumentRoot | ||
* @package Magento\Config\Model\Config\Reader\Source\Deployed | ||
*/ | ||
class DocumentRoot | ||
{ | ||
/** | ||
* @var DeploymentConfig | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* DocumentRoot constructor. | ||
* @param DeploymentConfig $config | ||
*/ | ||
public function __construct(DeploymentConfig $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* A shortcut to load the document root path from the DirectoryList based on the | ||
* deployment configuration. | ||
* | ||
* @return string | ||
*/ | ||
public function getPath() | ||
{ | ||
return $this->isPub() ? DirectoryList::PUB : DirectoryList::ROOT; | ||
} | ||
|
||
/** | ||
* Returns whether the deployment configuration specifies that the document root is | ||
* in the pub/ folder. This affects ares such as sitemaps and robots.txt (and will | ||
* likely be extended to control other areas). | ||
* | ||
* @return bool | ||
*/ | ||
public function isPub() | ||
{ | ||
return (bool)$this->config->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/DocumentRootTest.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,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Config\Test\Unit\Model\Config\Reader\Source\Deployed; | ||
|
||
use Magento\Config\Model\Config\Reader; | ||
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker; | ||
use Magento\Framework\App\Config; | ||
use Magento\Framework\App\DeploymentConfig; | ||
use Magento\Config\Model\Placeholder\PlaceholderInterface; | ||
use Magento\Config\Model\Placeholder\PlaceholderFactory; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Config\ConfigOptionsListConstants; | ||
|
||
/** | ||
* Test class for checking settings that defined in config file | ||
*/ | ||
class DocumentRootTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Config|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $configMock; | ||
|
||
/** | ||
* @var Reader\Source\Deployed\DocumentRoot | ||
*/ | ||
private $documentRoot; | ||
|
||
public function setUp() | ||
{ | ||
$this->configMock = $this->getMockBuilder(DeploymentConfig::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->documentRoot = new Reader\Source\Deployed\DocumentRoot($this->configMock); | ||
} | ||
|
||
/** | ||
* Ensures that the path returned matches the pub/ path. | ||
*/ | ||
public function testGetPath() | ||
{ | ||
$this->configMockSetForDocumentRootIsPub(); | ||
|
||
$this->assertSame(DirectoryList::PUB, $this->documentRoot->getPath()); | ||
} | ||
|
||
/** | ||
* Ensures that the deployment configuration returns the mocked value for | ||
* the pub/ folder. | ||
*/ | ||
public function testIsPub() | ||
{ | ||
$this->configMockSetForDocumentRootIsPub(); | ||
|
||
$this->assertSame(true, $this->documentRoot->isPub()); | ||
} | ||
|
||
private function configMockSetForDocumentRootIsPub() | ||
{ | ||
$this->configMock->expects($this->any()) | ||
->method('get') | ||
->willReturnMap([ | ||
[ | ||
ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, | ||
null, | ||
true | ||
], | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Order deny,allow | ||
Order allow,deny | ||
Deny from all |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Order allow,deny | ||
Deny from all | ||
Deny from all |