Skip to content

Commit

Permalink
Merge branch 'develop' into MAGETWO-52577
Browse files Browse the repository at this point in the history
  • Loading branch information
miakusha committed Jan 17, 2017
2 parents c4ffb86 + 3140ec6 commit 4147d9d
Show file tree
Hide file tree
Showing 78 changed files with 2,892 additions and 522 deletions.
11 changes: 3 additions & 8 deletions app/code/Magento/Backend/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,12 @@ public function getFormKey()
*
* @param string $moduleName Full module name
* @return boolean
* @deprecated
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function isOutputEnabled($moduleName = null)
{
if ($moduleName === null) {
$moduleName = $this->getModuleName();
}

return !$this->_scopeConfig->isSetFlag(
'advanced/modules_disable_output/' . $moduleName,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<tab id="advanced" translate="label" sortOrder="999999">
<label>Advanced</label>
</tab>
<section id="advanced" translate="label" type="text" sortOrder="910" showInDefault="1" showInWebsite="1" showInStore="1">
<section id="advanced" translate="label" type="text" sortOrder="910" showInDefault="0" showInWebsite="0" showInStore="0">
<label>Advanced</label>
<tab>advanced</tab>
<resource>Magento_Backend::advanced</resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ public function testToHtml()
->getMock();
$eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true));

$scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class)
->setMethods(['getValue'])
->disableOriginalConstructor()->getMock();
$scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
->will($this->returnValue(false));

$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()
->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep'])
->getMock();
Expand Down Expand Up @@ -93,8 +87,6 @@ public function testToHtml()

$this->context->expects($this->once())->method('getEventManager')
->will($this->returnValue($eventManager));
$this->context->expects($this->once())->method('getScopeConfig')
->will($this->returnValue($scopeConfig));
$this->context->expects($this->once())->method('getLayout')
->will($this->returnValue($layout));
$this->context->expects($this->once())->method('getRequest')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function setUp()
false,
false
);
$this->scopeConfig = $this->getMock(\Magento\Framework\App\Config::class, ['getValue'], [], '', false, false);
$this->scopeConfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '', false, false);
$this->cacheState = $this->getMock(
\Magento\Framework\App\Cache\State::class,
['isEnabled'],
Expand Down Expand Up @@ -188,8 +188,6 @@ protected function generalGetProductCollection()
{
$this->eventManager->expects($this->exactly(2))->method('dispatch')
->will($this->returnValue(true));
$this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
->willReturn(false);
$this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters()
->willReturn(false);
$this->catalogConfig->expects($this->once())->method('getProductAttributes')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public function testToHtml()
$childNameTwo = 'child.2';
$childNames = [$childNameOne, $childNameTwo];

$this->scopeConfigMock->expects($this->once())
->method('getValue')
->willReturn(false);

/**
* @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
namespace Magento\Config\Block\System\Config\Form\Fieldset\Modules;

/**
* @deprecated
*/
class DisableOutput extends \Magento\Config\Block\System\Config\Form\Fieldset
{
/**
Expand Down
80 changes: 80 additions & 0 deletions app/code/Magento/Config/Model/Config/Parser/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Model\Config\Parser;

use Magento\Config\Model\Placeholder\Environment;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Framework\App\Config\CommentParserInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem;

/**
* Class Comment. It is used to parse config paths from comment section.
*/
class Comment implements CommentParserInterface
{
/**
* @var Filesystem
*/
private $filesystem;

/**
* @var PlaceholderInterface
*/
private $placeholder;

/**
* @param Filesystem $filesystem
* @param PlaceholderInterface $placeholder
*/
public function __construct(
Filesystem $filesystem,
PlaceholderInterface $placeholder
) {
$this->filesystem = $filesystem;
$this->placeholder = $placeholder;
}

/**
* Retrieves config paths from comment section of the file.
* Example of comment:
* * CONFIG__DEFAULT__SOME__CONF__PATH_ONE
* * CONFIG__DEFAULT__SOME__CONF__PATH_TWO
* This method will return:
* array(
* 'CONFIG__DEFAULT__SOME__CONF__PATH_ONE' => 'some/conf/path_one',
* 'CONFIG__DEFAULT__SOME__CONF__PATH_TWO' => 'some/conf/path_two'
* );
*
* @param string $fileName
* @return array
* @throws FileSystemException
*/
public function execute($fileName)
{
$fileContent = $this->filesystem
->getDirectoryRead(DirectoryList::CONFIG)
->readFile($fileName);

$pattern = sprintf('/\s+\*\s+(?P<placeholder>%s.*?)\s/', preg_quote(Environment::PREFIX));
preg_match_all($pattern, $fileContent, $matches);

if (!isset($matches['placeholder'])) {
return [];
}

$configs = [];
foreach ($matches['placeholder'] as $placeholder) {
$path = $this->placeholder->restore($placeholder);
$path = preg_replace('/^' . ScopeConfigInterface::SCOPE_TYPE_DEFAULT . '\//', '', $path);
$configs[$placeholder] = $path;
}

return $configs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @deprecated
*/
class DisableOutputTest extends \PHPUnit_Framework_TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Test\Unit\Model\Config\Parser;

use Magento\Config\Model\Config\Parser\Comment;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

class CommentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PlaceholderInterface|MockObject
*/
private $placeholderMock;

/**
* @var Filesystem|MockObject
*/
private $fileSystemMock;

/**
* @var Comment
*/
private $model;

protected function setUp()
{
$this->placeholderMock = $this->getMockBuilder(PlaceholderInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->fileSystemMock = $this->getMockBuilder(Filesystem::class)
->disableOriginalConstructor()
->getMock();

$this->model = new Comment(
$this->fileSystemMock,
$this->placeholderMock
);
}

public function testExecute()
{
$fileName = 'config.local.php';
$directoryReadMock = $this->getMockBuilder(ReadInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$directoryReadMock->expects($this->once())
->method('readFile')
->with($fileName)
->willReturn(file_get_contents(__DIR__ . '/../_files/' . $fileName));
$this->fileSystemMock->expects($this->once())
->method('getDirectoryRead')
->with(DirectoryList::CONFIG)
->willReturn($directoryReadMock);
$this->placeholderMock->expects($this->any())
->method('restore')
->withConsecutive(
['CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD'],
['CONFIG__DEFAULT__SOME__PAYMENT__TOKEN']
)
->willReturnOnConsecutiveCalls(
'some/payment/password',
'some/payment/token'
);

$this->assertEquals(
$this->model->execute($fileName),
[
'CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD' => 'some/payment/password',
'CONFIG__DEFAULT__SOME__PAYMENT__TOKEN' => 'some/payment/token'
]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
return [
'scopes' => [
'websites' => [
'admin' => [
'website_id' => '0'
],
],
],
/**
* The configuration file doesn't contain sensitive data for security reasons.
* Sensitive data can be stored in the following environment variables:
* CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD for some/payment/password
*/
'system' => []
/**
* CONFIG__DEFAULT__SOME__PAYMENT__TOKEN for some/payment/token
* test phrase CONFIG__DEFAULT__SOME__PAYMENT__TOKEN for some/payment/token
*/
];
6 changes: 6 additions & 0 deletions app/code/Magento/Config/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<preference for="Magento\Config\Model\Config\Structure\SearchInterface" type="Magento\Config\Model\Config\Structure" />
<preference for="Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface" type="Magento\Config\Model\Config\Backend\File\RequestData" />
<preference for="Magento\Framework\App\Config\ConfigResource\ConfigInterface" type="Magento\Config\Model\ResourceModel\Config" />
<preference for="Magento\Framework\App\Config\CommentParserInterface" type="Magento\Config\Model\Config\Parser\Comment" />
<virtualType name="Magento\Framework\View\TemplateEngine\Xhtml\ConfigCompiler" type="Magento\Framework\View\TemplateEngine\Xhtml\Compiler" shared="false">
<arguments>
<argument name="compilerText" xsi:type="object">Magento\Framework\View\TemplateEngine\Xhtml\Compiler\Text</argument>
Expand Down Expand Up @@ -184,4 +185,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\Parser\Comment">
<arguments>
<argument name="placeholder" xsi:type="object">Magento\Config\Model\Placeholder\Environment</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\ObjectManagerInterface;

/**
* Class CollectorFactory creates instance of CollectorInterface.
*/
class CollectorFactory
{
/**#@+
* Constant for collector types.
*/
const TYPE_INTERACTIVE = 'interactive';
const TYPE_SIMPLE = 'simple';
/**#@-*/

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var array
*/
private $types;

/**
* @param ObjectManagerInterface $objectManager
* @param array $types
*/
public function __construct(
ObjectManagerInterface $objectManager,
array $types = []
) {
$this->objectManager = $objectManager;
$this->types = $types;
}

/**
* Create instance of CollectorInterface by given type.
*
* @param string $type
* @return CollectorInterface
* @throws LocalizedException If collector type not exist in registered types array.
*/
public function create($type)
{
if (!isset($this->types[$type])) {
throw new LocalizedException(__('Class for type "%1" was not declared', $type));
}

$object = $this->objectManager->create($this->types[$type]);

if (!$object instanceof CollectorInterface) {
throw new LocalizedException(
__('%1 does not implement %2', get_class($object), CollectorInterface::class)
);
}

return $object;
}
}
Loading

0 comments on commit 4147d9d

Please sign in to comment.