Skip to content

Commit

Permalink
Merge branch 'MAGETWO-59376' of https://github.com/magento-falcons/ma…
Browse files Browse the repository at this point in the history
…gento2ce into MAGETWO-59376
  • Loading branch information
shiftedreality committed Nov 2, 2016
2 parents f33dd60 + 69fe8b8 commit f535fe1
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 100 deletions.
99 changes: 99 additions & 0 deletions app/code/Magento/Theme/Model/Design/Config/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
*/
namespace Magento\Theme\Model\Design\Config;

use Magento\Framework\App\Config\ScopeCodeResolver;
use Magento\Framework\App\ObjectManager;
use Magento\Theme\Model\ResourceModel\Design\Config\Collection;
use Magento\Theme\Model\ResourceModel\Design\Config\CollectionFactory;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
use Magento\Framework\App\RequestInterface;

class DataProvider extends AbstractDataProvider
{
Expand All @@ -31,6 +35,21 @@ class DataProvider extends AbstractDataProvider
*/
private $metadataLoader;

/**
* @var SettingChecker
*/
private $settingChecker;

/**
* @var RequestInterface
*/
private $request;

/**
* @var ScopeCodeResolver
*/
private $scopeCodeResolver;

/**
* @param string $name
* @param string $primaryFieldName
Expand Down Expand Up @@ -78,4 +97,84 @@ public function getData()
$this->loadedData = $this->dataLoader->getData();
return $this->loadedData;
}

/**
* {@inheritdoc}
*/
public function getMeta()
{
$meta = parent::getMeta();
if (!isset($meta['other_settings']['children'])) {
return $meta;
}

$request = $this->getRequest()->getParams();
if (!isset($request['scope'])) {
return $meta;
}

$scope = $request['scope'];
$scopeCode = $this->getScopeCodeResolver()->resolve(
$scope,
isset($request['scope_id']) ? $request['scope_id'] : null
);

foreach ($meta['other_settings']['children'] as $settingGroupName => &$settingGroup) {
foreach ($settingGroup['children'] as $fieldName => &$field) {
$path = sprintf(
'design/%s/%s',
$settingGroupName,
preg_replace('/^' . $settingGroupName . '_/', '', $fieldName)
);
$isReadOnly = $this->getSettingChecker()->isReadOnly(
$path,
$scope,
$scopeCode
);

if ($isReadOnly) {
$field['arguments']['data']['config']['disabled'] = true;
$field['arguments']['data']['config']['is_disable_inheritance'] = true;
}
}
}

return $meta;
}

/**
* @deprecated
* @return ScopeCodeResolver
*/
private function getScopeCodeResolver()
{
if ($this->scopeCodeResolver === null) {
$this->scopeCodeResolver = ObjectManager::getInstance()->get(ScopeCodeResolver::class);
}
return $this->scopeCodeResolver;
}

/**
* @deprecated
* @return SettingChecker
*/
private function getSettingChecker()
{
if ($this->settingChecker === null) {
$this->settingChecker = ObjectManager::getInstance()->get(SettingChecker::class);
}
return $this->settingChecker;
}

/**
* @deprecated
* @return RequestInterface
*/
private function getRequest()
{
if ($this->request === null) {
$this->request = ObjectManager::getInstance()->get(RequestInterface::class);
}
return $this->request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
namespace Magento\Theme\Test\Unit\Model\Design\Config;

use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
use Magento\Framework\App\Config\ScopeCodeResolver;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Theme\Model\Design\Config\DataLoader;
use Magento\Theme\Model\Design\Config\DataProvider;
use Magento\Theme\Model\Design\Config\MetadataLoader;
Expand Down Expand Up @@ -32,8 +36,29 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase
*/
protected $collection;

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

/**
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $requestMock;

/**
* @var ScopeCodeResolver|\PHPUnit_Framework_MockObject_MockObject
*/
private $scopeCodeResolverMock;

/**
* @var SettingChecker|\PHPUnit_Framework_MockObject_MockObject
*/
private $settingCheckerMock;

protected function setUp()
{
$this->objectManager = new ObjectManager($this);
$this->dataLoader = $this->getMockBuilder('Magento\Theme\Model\Design\Config\DataProvider\DataLoader')
->disableOriginalConstructor()
->getMock();
Expand All @@ -57,6 +82,16 @@ protected function setUp()
->method('create')
->willReturn($this->collection);

$this->requestMock = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
$this->scopeCodeResolverMock = $this->getMockBuilder(ScopeCodeResolver::class)
->disableOriginalConstructor()
->getMock();
$this->settingCheckerMock = $this->getMockBuilder(SettingChecker::class)
->disableOriginalConstructor()
->getMock();

$this->model = new DataProvider(
'scope',
'scope',
Expand All @@ -65,6 +100,21 @@ protected function setUp()
$this->metadataLoader,
$collectionFactory
);
$this->objectManager->setBackwardCompatibleProperty(
$this->model,
'request',
$this->requestMock
);
$this->objectManager->setBackwardCompatibleProperty(
$this->model,
'scopeCodeResolver',
$this->scopeCodeResolverMock
);
$this->objectManager->setBackwardCompatibleProperty(
$this->model,
'settingChecker',
$this->settingCheckerMock
);
}

public function testGetData()
Expand All @@ -79,4 +129,119 @@ public function testGetData()

$this->assertEquals($data, $this->model->getData());
}

/**
* @param array $inputMeta
* @param array $expectedMeta
* @param array $request
* @dataProvider getMetaDataProvider
*/
public function testGetMeta(array $inputMeta, array $expectedMeta, array $request)
{
$this->requestMock->expects($this->any())
->method('getParams')
->willReturn($request);
$this->scopeCodeResolverMock->expects($this->any())
->method('resolve')
->with('stores', 1)
->willReturn('default');
$this->settingCheckerMock->expects($this->any())
->method('isReadOnly')
->withConsecutive(
['design/head/welcome', 'stores', 'default'],
['design/head/logo', 'stores', 'default'],
['design/head/head', 'stores', 'default']
)
->willReturnOnConsecutiveCalls(
true,
false,
true
);

$this->objectManager->setBackwardCompatibleProperty(
$this->model,
'meta',
$inputMeta
);

$this->assertSame($expectedMeta, $this->model->getMeta());
}

/**
* @return array
*/
public function getMetaDataProvider()
{
return [
[
[
'option1'
],
[
'option1'
],
[
'scope' => 'default'
]
],
[
[
'other_settings' => [
'children' => [
'head' => [
'children' => [
'head_welcome' => [

],
'head_logo' => [

],
'head_head' => [

]
]
]
]
]
],
[
'other_settings' => [
'children' => [
'head' => [
'children' => [
'head_welcome' => [
'arguments' => [
'data' => [
'config' => [
'disabled' => true,
'is_disable_inheritance' => true,
]
]
]
],
'head_logo' => [

],
'head_head' => [
'arguments' => [
'data' => [
'config' => [
'disabled' => true,
'is_disable_inheritance' => true,
]
]
]
]
]
]
]
]
],
[
'scope' => 'stores',
'scope_id' => 1
]
]
];
}
}
12 changes: 3 additions & 9 deletions lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,9 @@ public function getPreference($type)
*/
public function extend(array $configuration)
{
$this->arguments = isset($configuration['arguments'])
? array_replace($this->arguments, $configuration['arguments'])
: $this->arguments;
$this->virtualTypes = isset($configuration['instanceTypes'])
? array_replace($this->virtualTypes, $configuration['instanceTypes'])
: $this->virtualTypes;
$this->preferences = isset($configuration['preferences'])
? array_replace($this->preferences, $configuration['preferences'])
: $this->preferences;
$this->arguments = $configuration['arguments'];
$this->virtualTypes = $configuration['instanceTypes'];
$this->preferences = $configuration['preferences'];
}

/**
Expand Down
Loading

0 comments on commit f535fe1

Please sign in to comment.