Skip to content

Commit 5ad7f7a

Browse files
author
Alexander Akimov
authored
Merge pull request #3858 from magento-tsg/2.2.8-develop-pr82
[TSG] Backporting for 2.2 (pr82) (2.2.8-develop)
2 parents 82de11c + 9f25ff5 commit 5ad7f7a

File tree

12 files changed

+229
-93
lines changed

12 files changed

+229
-93
lines changed

app/code/Magento/Config/Model/Config.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,24 +520,29 @@ public function setDataByPath($path, $value)
520520
if ($path === '') {
521521
throw new \UnexpectedValueException('Path must not be empty');
522522
}
523+
523524
$pathParts = explode('/', $path);
524525
$keyDepth = count($pathParts);
525-
if ($keyDepth !== 3) {
526+
if ($keyDepth < 3) {
526527
throw new \UnexpectedValueException(
527-
"Allowed depth of configuration is 3 (<section>/<group>/<field>). Your configuration depth is "
528-
. $keyDepth . " for path '$path'"
528+
'Minimal depth of configuration is 3. Your configuration depth is ' . $keyDepth
529529
);
530530
}
531+
532+
$section = array_shift($pathParts);
531533
$data = [
532-
'section' => $pathParts[0],
533-
'groups' => [
534-
$pathParts[1] => [
535-
'fields' => [
536-
$pathParts[2] => ['value' => $value],
537-
],
538-
],
534+
'fields' => [
535+
array_pop($pathParts) => ['value' => $value],
539536
],
540537
];
538+
while ($pathParts) {
539+
$data = [
540+
'groups' => [
541+
array_pop($pathParts) => $data,
542+
],
543+
];
544+
}
545+
$data['section'] = $section;
541546
$this->addData($data);
542547
}
543548

app/code/Magento/Config/Test/Unit/Model/ConfigTest.php

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -355,22 +355,60 @@ public function testSaveToCheckScopeDataSet()
355355
$this->model->save();
356356
}
357357

358-
public function testSetDataByPath()
358+
/**
359+
* @param string $path
360+
* @param string $value
361+
* @param string $section
362+
* @param array $groups
363+
* @return void
364+
* @dataProvider setDataByPathDataProvider
365+
*/
366+
public function testSetDataByPath(string $path, string $value, string $section, array $groups)
359367
{
360-
$value = 'value';
361-
$path = '<section>/<group>/<field>';
362368
$this->model->setDataByPath($path, $value);
363-
$expected = [
364-
'section' => '<section>',
365-
'groups' => [
366-
'<group>' => [
367-
'fields' => [
368-
'<field>' => ['value' => $value],
369+
$this->assertEquals($section, $this->model->getData('section'));
370+
$this->assertEquals($groups, $this->model->getData('groups'));
371+
}
372+
373+
/**
374+
* @return array
375+
*/
376+
public function setDataByPathDataProvider(): array
377+
{
378+
return [
379+
'depth 3' => [
380+
'a/b/c',
381+
'value1',
382+
'a',
383+
[
384+
'b' => [
385+
'fields' => [
386+
'c' => ['value' => 'value1'],
387+
],
388+
],
389+
],
390+
],
391+
'depth 5' => [
392+
'a/b/c/d/e',
393+
'value1',
394+
'a',
395+
[
396+
'b' => [
397+
'groups' => [
398+
'c' => [
399+
'groups' => [
400+
'd' => [
401+
'fields' => [
402+
'e' => ['value' => 'value1'],
403+
],
404+
],
405+
],
406+
],
407+
],
369408
],
370409
],
371410
],
372411
];
373-
$this->assertSame($expected, $this->model->getData());
374412
}
375413

376414
/**
@@ -384,14 +422,14 @@ public function testSetDataByPathEmpty()
384422

385423
/**
386424
* @param string $path
387-
* @param string $expectedException
388-
*
425+
* @return void
389426
* @dataProvider setDataByPathWrongDepthDataProvider
390427
*/
391-
public function testSetDataByPathWrongDepth($path, $expectedException)
428+
public function testSetDataByPathWrongDepth(string $path)
392429
{
393-
$expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
394-
$this->expectException('\UnexpectedValueException');
430+
$currentDepth = count(explode('/', $path));
431+
$expectedException = 'Minimal depth of configuration is 3. Your configuration depth is ' . $currentDepth;
432+
$this->expectException(\UnexpectedValueException::class);
395433
$this->expectExceptionMessage($expectedException);
396434
$value = 'value';
397435
$this->model->setDataByPath($path, $value);
@@ -400,13 +438,11 @@ public function testSetDataByPathWrongDepth($path, $expectedException)
400438
/**
401439
* @return array
402440
*/
403-
public function setDataByPathWrongDepthDataProvider()
441+
public function setDataByPathWrongDepthDataProvider(): array
404442
{
405443
return [
406-
'depth 2' => ['section/group', "Your configuration depth is 2 for path 'section/group'"],
407-
'depth 1' => ['section', "Your configuration depth is 1 for path 'section'"],
408-
'depth 4' => ['section/group/field/sub-field', "Your configuration depth is 4 for path"
409-
. " 'section/group/field/sub-field'", ],
444+
'depth 2' => ['section/group'],
445+
'depth 1' => ['section'],
410446
];
411447
}
412448
}

app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
namespace Magento\Newsletter\Model\Plugin;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
9-
use Magento\Customer\Api\Data\CustomerExtensionInterface;
109
use Magento\Customer\Api\Data\CustomerInterface;
10+
use Magento\Newsletter\Model\SubscriberFactory;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Newsletter\Model\ResourceModel\Subscriber;
14-
use Magento\Newsletter\Model\SubscriberFactory;
15-
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Customer\Api\Data\CustomerExtensionInterface;
14+
use Magento\Framework\App\ObjectManager;
1615

1716
class CustomerPlugin
1817
{
@@ -38,30 +37,22 @@ class CustomerPlugin
3837
*/
3938
private $customerSubscriptionStatus = [];
4039

41-
/**
42-
* @var StoreManagerInterface
43-
*/
44-
private $storeManager;
45-
4640
/**
4741
* Initialize dependencies.
4842
*
4943
* @param SubscriberFactory $subscriberFactory
5044
* @param ExtensionAttributesFactory|null $extensionFactory
5145
* @param Subscriber|null $subscriberResource
52-
* @param StoreManagerInterface|null $storeManager
5346
*/
5447
public function __construct(
5548
SubscriberFactory $subscriberFactory,
5649
ExtensionAttributesFactory $extensionFactory = null,
57-
Subscriber $subscriberResource = null,
58-
StoreManagerInterface $storeManager = null
50+
Subscriber $subscriberResource = null
5951
) {
6052
$this->subscriberFactory = $subscriberFactory;
6153
$this->extensionFactory = $extensionFactory
6254
?: ObjectManager::getInstance()->get(ExtensionAttributesFactory::class);
6355
$this->subscriberResource = $subscriberResource ?: ObjectManager::getInstance()->get(Subscriber::class);
64-
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6556
}
6657

6758
/**
@@ -158,8 +149,6 @@ public function afterDelete(CustomerRepository $subject, $result, CustomerInterf
158149
public function afterGetById(CustomerRepository $subject, CustomerInterface $customer)
159150
{
160151
$extensionAttributes = $customer->getExtensionAttributes();
161-
$storeId = $this->storeManager->getStore()->getId();
162-
$customer->setStoreId($storeId);
163152
if ($extensionAttributes === null) {
164153
/** @var CustomerExtensionInterface $extensionAttributes */
165154
$extensionAttributes = $this->extensionFactory->create(CustomerInterface::class);

app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
1212
use Magento\Newsletter\Model\ResourceModel\Subscriber;
13-
use Magento\Store\Model\Store;
14-
use Magento\Store\Model\StoreManagerInterface;
1513

1614
class CustomerPluginTest extends \PHPUnit\Framework\TestCase
1715
{
@@ -55,11 +53,6 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
5553
*/
5654
private $customerMock;
5755

58-
/**
59-
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60-
*/
61-
private $storeManagerMock;
62-
6356
protected function setUp()
6457
{
6558
$this->subscriberFactory = $this->getMockBuilder(\Magento\Newsletter\Model\SubscriberFactory::class)
@@ -94,17 +87,14 @@ protected function setUp()
9487
->setMethods(["getExtensionAttributes"])
9588
->disableOriginalConstructor()
9689
->getMockForAbstractClass();
97-
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
98-
9990
$this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
10091
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
10192
$this->plugin = $this->objectManager->getObject(
10293
\Magento\Newsletter\Model\Plugin\CustomerPlugin::class,
10394
[
10495
'subscriberFactory' => $this->subscriberFactory,
10596
'extensionFactory' => $this->extensionFactoryMock,
106-
'subscriberResource' => $this->subscriberResourceMock,
107-
'storeManager' => $this->storeManagerMock,
97+
'subscriberResource' => $this->subscriberResourceMock
10898
]
10999
);
110100
}
@@ -208,7 +198,6 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
208198
) {
209199
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
210200
$subscriber = [$subscriberStatusKey => $subscriberStatusValue];
211-
$this->prepareStoreData();
212201
$this->extensionFactoryMock->expects($this->any())
213202
->method('create')
214203
->willReturn($this->customerExtensionMock);
@@ -234,7 +223,6 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
234223
{
235224
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
236225
$subscriber = ['subscriber_id' => 1, 'subscriber_status' => 1];
237-
$this->prepareStoreData();
238226
$this->customerMock->expects($this->any())
239227
->method('getExtensionAttributes')
240228
->willReturn($this->customerExtensionMock);
@@ -267,17 +255,4 @@ public function afterGetByIdDataProvider()
267255
[null, null, false]
268256
];
269257
}
270-
271-
/**
272-
* Prepare store information
273-
*
274-
* @return void
275-
*/
276-
private function prepareStoreData()
277-
{
278-
$storeId = 1;
279-
$storeMock = $this->createMock(Store::class);
280-
$storeMock->expects($this->any())->method('getId')->willReturn($storeId);
281-
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
282-
}
283258
}

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ private function getOptionProductIds(
325325
/**
326326
* Check is valid product.
327327
*
328-
* @param ProductInterface $product
328+
* @param ProductInterface|null $product
329329
* @return bool
330330
*/
331-
private function isValidProduct(ProductInterface $product): bool
331+
private function isValidProduct(ProductInterface $product = null): bool
332332
{
333333
$result = ($product && (int)$product->getStatus() !== ProductStatus::STATUS_DISABLED);
334334

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractForm.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ protected function _prepareLayout()
9696
public function getForm()
9797
{
9898
if ($this->_form === null) {
99+
$storeId = $this->getCreateOrderModel()
100+
->getSession()
101+
->getStoreId();
102+
$this->_storeManager->setCurrentStore($storeId);
103+
99104
$this->_form = $this->_formFactory->create();
100105
$this->_prepareForm();
101106
}

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ public function getAddressCollectionJson()
217217
*/
218218
protected function _prepareForm()
219219
{
220-
$storeId = $this->getCreateOrderModel()
221-
->getSession()
222-
->getStoreId();
223-
$this->_storeManager->setCurrentStore($storeId);
224-
225220
$fieldset = $this->_form->addFieldset('main', ['no_container' => true]);
226221

227222
$addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address');

app/design/adminhtml/Magento/backend/Magento_Backend/web/css/source/module/_menu.less

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,9 @@
271271

272272
&._show {
273273
> .submenu {
274-
display: block;
275-
float: left;
276-
left: 100%;
277-
max-width: 1640px;
278-
min-height: 98.65%;
279-
min-width: 100%;
280-
overflow-x: scroll;
281-
position: absolute;
282274
transform: translateX(0);
283275
visibility: visible;
284-
z-index: 698;
276+
z-index: @submenu__z-index;
285277
}
286278
}
287279
}

dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigSetCommandTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Config\Console\Command;
77

88
use Magento\Config\Model\Config\Backend\Admin\Custom;
9+
use Magento\Config\Model\Config\Structure\Converter;
10+
use Magento\Config\Model\Config\Structure\Data as StructureData;
911
use Magento\Directory\Model\Currency;
1012
use Magento\Framework\App\Config\ConfigPathResolver;
1113
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -90,6 +92,8 @@ protected function setUp()
9092
{
9193
Bootstrap::getInstance()->reinitialize();
9294
$this->objectManager = Bootstrap::getObjectManager();
95+
$this->extendSystemStructure();
96+
9397
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
9498
$this->reader = $this->objectManager->get(FileReader::class);
9599
$this->filesystem = $this->objectManager->get(Filesystem::class);
@@ -122,6 +126,21 @@ protected function tearDown()
122126
$this->appConfig->reinit();
123127
}
124128

129+
/**
130+
* Add test system structure to main system structure
131+
*
132+
* @return void
133+
*/
134+
private function extendSystemStructure()
135+
{
136+
$document = new \DOMDocument();
137+
$document->load(__DIR__ . '/../../_files/system.xml');
138+
$converter = $this->objectManager->get(Converter::class);
139+
$systemConfig = $converter->convert($document);
140+
$structureData = $this->objectManager->get(StructureData::class);
141+
$structureData->merge($systemConfig);
142+
}
143+
125144
/**
126145
* @return array
127146
*/
@@ -190,6 +209,8 @@ public function runLockDataProvider()
190209
['general/region/display_all', '1'],
191210
['general/region/state_required', 'BR,FR', ScopeInterface::SCOPE_WEBSITE, 'base'],
192211
['admin/security/use_form_key', '0'],
212+
['general/group/subgroup/field', 'default_value'],
213+
['general/group/subgroup/field', 'website_value', ScopeInterface::SCOPE_WEBSITE, 'base'],
193214
];
194215
}
195216

0 commit comments

Comments
 (0)