Skip to content

Commit e7b1fd4

Browse files
committed
Merge remote-tracking branch 'mainline/2.1-develop' into MAGETWO-60041
2 parents f5c557f + 92d8e3d commit e7b1fd4

File tree

278 files changed

+12823
-2417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+12823
-2417
lines changed

app/code/Magento/Backend/App/Config.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,66 @@
1010

1111
namespace Magento\Backend\App;
1212

13+
use Magento\Config\App\Config\Type\System;
1314
use Magento\Framework\App\Config\ScopeConfigInterface;
1415

1516
/**
16-
* Backend config accessor
17+
* Backend config accessor.
1718
*/
1819
class Config implements ConfigInterface
1920
{
2021
/**
21-
* @var \Magento\Framework\App\Config\ScopePool
22+
* @var \Magento\Framework\App\Config
2223
*/
23-
protected $_scopePool;
24+
protected $appConfig;
2425

2526
/**
26-
* @param \Magento\Framework\App\Config\ScopePool $scopePool
27+
* @var array
2728
*/
28-
public function __construct(\Magento\Framework\App\Config\ScopePool $scopePool)
29+
private $data;
30+
31+
/**
32+
* @param \Magento\Framework\App\Config $appConfig
33+
* @return void
34+
*/
35+
public function __construct(\Magento\Framework\App\Config $appConfig)
2936
{
30-
$this->_scopePool = $scopePool;
37+
$this->appConfig = $appConfig;
3138
}
3239

3340
/**
34-
* Retrieve config value by path and scope
35-
*
36-
* @param string $path
37-
* @return mixed
41+
* @inheritdoc
3842
*/
3943
public function getValue($path)
4044
{
41-
return $this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
45+
if (isset($this->data[$path])) {
46+
return $this->data[$path];
47+
}
48+
49+
$configPath = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
50+
if ($path) {
51+
$configPath .= '/' . $path;
52+
}
53+
return $this->appConfig->get(System::CONFIG_TYPE, $configPath);
4254
}
4355

4456
/**
45-
* Set config value in the corresponding config scope
46-
*
47-
* @param string $path
48-
* @param mixed $value
49-
* @return void
57+
* @inheritdoc
5058
*/
5159
public function setValue($path, $value)
5260
{
53-
$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->setValue($path, $value);
61+
$this->data[$path] = $value;
5462
}
5563

5664
/**
57-
* Retrieve config flag
58-
*
59-
* @param string $path
60-
* @return bool
65+
* @inheritdoc
6166
*/
6267
public function isSetFlag($path)
6368
{
64-
return !!$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
69+
$configPath = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
70+
if ($path) {
71+
$configPath .= '/' . $path;
72+
}
73+
return (bool) $this->appConfig->get(System::CONFIG_TYPE, $configPath);
6574
}
6675
}

app/code/Magento/Backend/App/ConfigInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface ConfigInterface
1515
/**
1616
* Retrieve config value by path
1717
*
18+
* Path should looks like keys imploded by "/". For example scopes/stores/admin
19+
*
1820
* @param string $path
1921
* @return mixed
2022
* @api
@@ -24,6 +26,7 @@ public function getValue($path);
2426
/**
2527
* Set config value
2628
*
29+
* @deprecated
2730
* @param string $path
2831
* @param mixed $value
2932
* @return void
@@ -34,6 +37,8 @@ public function setValue($path, $value);
3437
/**
3538
* Retrieve config flag
3639
*
40+
* Path should looks like keys imploded by "/". For example scopes/stores/admin
41+
*
3742
* @param string $path
3843
* @return bool
3944
* @api

app/code/Magento/Backend/Test/Unit/App/ConfigTest.php

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
use Magento\Backend\App\Config;
99

10+
/**
11+
* Test reading by path and reading flag from config
12+
*
13+
* @see \Magento\Backend\App\Config
14+
* @package Magento\Backend\Test\Unit\App
15+
*/
1016
class ConfigTest extends \PHPUnit_Framework_TestCase
1117
{
1218
/**
13-
* @var \Magento\Framework\App\Config\ScopePool|\PHPUnit_Framework_MockObject_MockObject
19+
* @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject
1420
*/
15-
protected $sectionPool;
21+
protected $appConfig;
1622

1723
/**
1824
* @var Config
@@ -21,102 +27,64 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
2127

2228
protected function setUp()
2329
{
24-
$this->sectionPool = $this->getMock(
25-
'Magento\Framework\App\Config\ScopePool',
26-
['getScope', 'clean'],
30+
$this->appConfig = $this->getMock(
31+
'Magento\Framework\App\Config',
32+
['get'],
2733
[],
2834
'',
2935
false
3036
);
31-
$this->model = new \Magento\Backend\App\Config($this->sectionPool);
37+
$this->model = new \Magento\Backend\App\Config($this->appConfig);
3238
}
3339

3440
public function testGetValue()
3541
{
3642
$expectedValue = 'some value';
3743
$path = 'some path';
38-
$configData = $this->getConfigDataMock('getValue');
39-
$configData->expects(
40-
$this->once()
41-
)->method(
42-
'getValue'
43-
)->with(
44-
$this->equalTo($path)
45-
)->will(
46-
$this->returnValue($expectedValue)
47-
);
48-
$this->sectionPool->expects(
44+
$this->appConfig->expects(
4945
$this->once()
5046
)->method(
51-
'getScope'
47+
'get'
5248
)->with(
53-
$this->equalTo('default'),
49+
$this->equalTo('system'),
50+
$this->equalTo('default/' . $path),
5451
$this->isNull()
5552
)->will(
56-
$this->returnValue($configData)
53+
$this->returnValue($expectedValue)
5754
);
5855
$this->assertEquals($expectedValue, $this->model->getValue($path));
5956
}
6057

61-
public function testSetValue()
62-
{
63-
$value = 'some value';
64-
$path = 'some path';
65-
$configData = $this->getConfigDataMock('setValue');
66-
$configData->expects($this->once())->method('setValue')->with($this->equalTo($path), $this->equalTo($value));
67-
$this->sectionPool->expects(
68-
$this->once()
69-
)->method(
70-
'getScope'
71-
)->with(
72-
$this->equalTo('default'),
73-
$this->isNull()
74-
)->will(
75-
$this->returnValue($configData)
76-
);
77-
$this->model->setValue($path, $value);
78-
}
79-
8058
/**
59+
* @param string $configPath
8160
* @param mixed $configValue
8261
* @param bool $expectedResult
8362
* @dataProvider isSetFlagDataProvider
8463
*/
85-
public function testIsSetFlag($configValue, $expectedResult)
64+
public function testIsSetFlag($configPath, $configValue, $expectedResult)
8665
{
87-
$path = 'some path';
88-
$configData = $this->getConfigDataMock('getValue');
89-
$configData->expects(
90-
$this->once()
66+
$this->appConfig->expects(
67+
$this->any()
9168
)->method(
92-
'getValue'
69+
'get'
9370
)->with(
94-
$this->equalTo($path)
71+
$this->equalTo('system'),
72+
$this->equalTo('default/' . $configPath)
9573
)->will(
9674
$this->returnValue($configValue)
9775
);
98-
$this->sectionPool->expects(
99-
$this->once()
100-
)->method(
101-
'getScope'
102-
)->with(
103-
$this->equalTo('default'),
104-
$this->isNull()
105-
)->will(
106-
$this->returnValue($configData)
107-
);
108-
$this->assertEquals($expectedResult, $this->model->isSetFlag($path));
76+
$this->assertEquals($expectedResult, $this->model->isSetFlag($configPath));
10977
}
11078

11179
public function isSetFlagDataProvider()
11280
{
11381
return [
114-
[0, false],
115-
[true, true],
116-
['0', false],
117-
['', false],
118-
['some string', true],
119-
[1, true]
82+
['a', 0, false],
83+
['b', true, true],
84+
['c', '0', false],
85+
['d', '', false],
86+
['e', 'some string', true],
87+
['f', 1, true]
12088
];
12189
}
12290

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Stock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function beforeSave($object)
5959
if (isset($stockData['qty']) && $stockData['qty'] === '') {
6060
$stockData['qty'] = null;
6161
}
62-
if ($object->getStockData() !== null || $stockData !== null) {
62+
if ($object->getStockData() !== null && $stockData !== null) {
6363
$object->setStockData(array_replace((array)$object->getStockData(), (array)$stockData));
6464
}
6565
$object->unsetData($this->getAttribute()->getAttributeCode());
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel\Product;
7+
8+
use Magento\Framework\DB\Select;
9+
10+
/**
11+
* Interface BaseSelectProcessorInterface
12+
* @api
13+
*/
14+
interface BaseSelectProcessorInterface
15+
{
16+
/**
17+
* Product table alias
18+
*/
19+
const PRODUCT_TABLE_ALIAS = 'child';
20+
21+
/**
22+
* @param Select $select
23+
* @return Select
24+
*/
25+
public function process(Select $select);
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel\Product;
7+
8+
use Magento\Framework\DB\Select;
9+
use Magento\Framework\Exception\InputException;
10+
11+
/**
12+
* Class CompositeBaseSelectProcessor
13+
*/
14+
class CompositeBaseSelectProcessor implements BaseSelectProcessorInterface
15+
{
16+
/**
17+
* @var BaseSelectProcessorInterface[]
18+
*/
19+
private $baseSelectProcessors;
20+
21+
/**
22+
* @param BaseSelectProcessorInterface[] $baseSelectProcessors
23+
* @throws InputException
24+
*/
25+
public function __construct(
26+
array $baseSelectProcessors
27+
) {
28+
foreach ($baseSelectProcessors as $baseSelectProcessor) {
29+
if (!$baseSelectProcessor instanceof BaseSelectProcessorInterface) {
30+
throw new InputException(
31+
__('Processor %1 doesn\'t implement BaseSelectProcessorInterface', get_class($baseSelectProcessor))
32+
);
33+
}
34+
}
35+
$this->baseSelectProcessors = $baseSelectProcessors;
36+
}
37+
38+
/**
39+
* @param Select $select
40+
* @return Select
41+
*/
42+
public function process(Select $select)
43+
{
44+
foreach ($this->baseSelectProcessors as $baseSelectProcessor) {
45+
$select = $baseSelectProcessor->process($select);
46+
}
47+
return $select;
48+
}
49+
}

0 commit comments

Comments
 (0)