Skip to content

Commit 4d4ed87

Browse files
committed
MC-36785: Unable to set YouTube API key by CLI
1 parent fab6a16 commit 4d4ed87

File tree

7 files changed

+182
-24
lines changed

7 files changed

+182
-24
lines changed

app/code/Magento/Analytics/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<general>
2121
<collection_time>02,00,00</collection_time>
2222
</general>
23+
<token/>
2324
</analytics>
2425
</default>
2526
</config>

app/code/Magento/Config/App/Config/Source/ConfigStructureSource.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
namespace Magento\Config\App\Config\Source;
99

10-
use Magento\Config\Model\Config\Structure\Reader;
11-
use Magento\Framework\App\Area;
10+
use Magento\Config\Model\Config\Structure;
1211
use Magento\Framework\App\Config\ConfigSourceInterface;
1312
use Magento\Framework\DataObject;
1413

@@ -18,49 +17,50 @@
1817
class ConfigStructureSource implements ConfigSourceInterface
1918
{
2019
/**
21-
* @var Reader
20+
* @var Structure
2221
*/
23-
private $reader;
22+
private $structure;
2423

2524
/**
26-
* @param Reader $reader
25+
* @param Structure $structure
2726
*/
28-
public function __construct(Reader $reader)
27+
public function __construct(Structure $structure)
2928
{
30-
$this->reader = $reader;
29+
$this->structure = $structure;
3130
}
3231

3332
/**
3433
* @inheritdoc
3534
*/
3635
public function get($path = '')
3736
{
38-
$configStructure = $this->reader->read(Area::AREA_ADMINHTML);
39-
$sections = $configStructure['config']['system']['sections'] ?? [];
40-
$defaultConfig = $this->merge([], $sections);
37+
$fieldPaths = array_keys($this->structure->getFieldPaths());
38+
$defaultConfig = [];
39+
foreach ($fieldPaths as $fieldPath) {
40+
$defaultConfig = $this->addPathToConfig($defaultConfig, $fieldPath);
41+
}
4142
$data = new DataObject(['default' => $defaultConfig]);
4243

4344
return $data->getData($path);
4445
}
4546

4647
/**
47-
* Merge existed config with config structure
48+
* Add config path to config structure
4849
*
4950
* @param array $config
50-
* @param array $sections
51+
* @param string $path
5152
* @return array
5253
*/
53-
private function merge(array $config, array $sections): array
54+
private function addPathToConfig(array $config, string $path): array
5455
{
55-
foreach ($sections as $section) {
56-
if (isset($section['children'])) {
57-
$config[$section['id']] = $this->merge(
58-
$config[$section['id']] ?? [],
59-
$section['children']
60-
);
61-
} elseif ($section['_elementType'] === 'field') {
62-
$config += [$section['id'] => null];
63-
}
56+
if (strpos($path, '/') !== false) {
57+
list ($key, $subPath) = explode('/', $path, 2);
58+
$config[$key] = $this->addPathToConfig(
59+
$config[$key] ?? [],
60+
$subPath
61+
);
62+
} else {
63+
$config[$path] = null;
6464
}
6565

6666
return $config;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Test\Unit\App\Config\Source;
9+
10+
use Magento\Config\App\Config\Source\ConfigStructureSource;
11+
use Magento\Config\Model\Config\Structure;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ConfigStructureSourceTest extends TestCase
16+
{
17+
/**
18+
* @var Structure|MockObject
19+
*/
20+
private $structure;
21+
22+
/**
23+
* @var ConfigStructureSource
24+
*/
25+
private $source;
26+
27+
protected function setUp(): void
28+
{
29+
$this->structure = $this->createMock(Structure::class);
30+
$this->source = new ConfigStructureSource($this->structure);
31+
}
32+
33+
/**
34+
* @dataProvider getDataProvider
35+
* @param array $fieldPaths
36+
* @param array $expectedConfig
37+
*/
38+
public function testGet(array $fieldPaths, array $expectedConfig)
39+
{
40+
$this->structure->expects($this->once())
41+
->method('getFieldPaths')
42+
->willReturn($fieldPaths);
43+
$this->assertEquals($expectedConfig, $this->source->get('default'));
44+
}
45+
46+
/**
47+
* @return array
48+
*/
49+
public function getDataProvider(): array
50+
{
51+
return [
52+
[
53+
[
54+
'general/single_store_mode/enabled' => [],
55+
'general/locale/timezone' => [],
56+
'general/locale/code' => [],
57+
],
58+
[
59+
'general' => [
60+
'single_store_mode' => [
61+
'enabled' => null,
62+
],
63+
'locale' => [
64+
'timezone' => null,
65+
'code' => null,
66+
],
67+
],
68+
],
69+
],
70+
];
71+
}
72+
}

app/code/Magento/Config/etc/di.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,19 @@
350350
<argument name="excludeList" xsi:type="object">Magento\Config\Model\Config\Export\ExcludeList</argument>
351351
</arguments>
352352
</type>
353+
<virtualType name="adminhtmlConfigStructureData" type="\Magento\Config\Model\Config\Structure\Data">
354+
<arguments>
355+
<argument name="configScope" xsi:type="object">adminhtmlConfigScope</argument>
356+
</arguments>
357+
</virtualType>
358+
<virtualType name="adminhtmlConfigStructure" type="Magento\Config\Model\Config\Structure">
359+
<arguments>
360+
<argument name="structureData" xsi:type="object">adminhtmlConfigStructureData</argument>
361+
</arguments>
362+
</virtualType>
363+
<type name="Magento\Config\App\Config\Source\ConfigStructureSource">
364+
<arguments>
365+
<argument name="structure" xsi:type="object">adminhtmlConfigStructure</argument>
366+
</arguments>
367+
</type>
353368
</config>

app/code/Magento/ReleaseNotification/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<type name="Magento\Config\Model\Config\TypePool">
1111
<arguments>
1212
<argument name="sensitive" xsi:type="array">
13-
<item name="releaseNotification/content_url" xsi:type="string">1</item>
14-
<item name="releaseNotification/use_https" xsi:type="string">1</item>
13+
<item name="system/release_notification/content_url" xsi:type="string">1</item>
14+
<item name="system/release_notification/use_https" xsi:type="string">1</item>
1515
</argument>
1616
</arguments>
1717
</type>

app/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@
320320
<argument name="defaultScope" xsi:type="string">global</argument>
321321
</arguments>
322322
</virtualType>
323+
<virtualType name="adminhtmlConfigScope" type="Magento\Framework\Config\Scope">
324+
<arguments>
325+
<argument name="defaultScope" xsi:type="string">adminhtml</argument>
326+
</arguments>
327+
</virtualType>
323328
<type name="Magento\Framework\App\State">
324329
<arguments>
325330
<argument name="mode" xsi:type="init_parameter">Magento\Framework\App\State::PARAM_MODE</argument>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Config\Export;
9+
10+
use Magento\Config\Model\Config\TypePool;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class CommentTest extends TestCase
15+
{
16+
/**
17+
* @var Comment
18+
*/
19+
private $comment;
20+
21+
protected function setUp(): void
22+
{
23+
$this->comment = Bootstrap::getObjectManager()->create(Comment::class);
24+
}
25+
26+
public function testGet()
27+
{
28+
$sensitivePaths = $this->getSensitivePaths();
29+
$comments = $this->comment->get();
30+
31+
$missedPaths = [];
32+
foreach ($sensitivePaths as $sensitivePath) {
33+
if (stripos($comments, $sensitivePath) === false) {
34+
$missedPaths[] = $sensitivePath;
35+
}
36+
}
37+
38+
$this->assertEmpty(
39+
$missedPaths,
40+
'Sensitive paths are missed: ' . implode(', ', $missedPaths)
41+
);
42+
}
43+
44+
/**
45+
* Retrieve sensitive paths from class that is used to check is path sensitive.
46+
*
47+
* There is no public method to get this data.
48+
* It's why they are read using private method.
49+
*
50+
* @return array
51+
*/
52+
private function getSensitivePaths(): array
53+
{
54+
$typePool = Bootstrap::getObjectManager()->get(TypePool::class);
55+
$sensitivePathsReader = \Closure::bind(
56+
function () {
57+
return $this->getPathsByType(TypePool::TYPE_SENSITIVE);
58+
},
59+
$typePool,
60+
$typePool
61+
);
62+
63+
return $sensitivePathsReader();
64+
}
65+
}

0 commit comments

Comments
 (0)