Skip to content

Commit 64ce1bf

Browse files
committed
Merge remote-tracking branch 'tango/MC-36785' into PR-10-14
2 parents 14a84d4 + 080044a commit 64ce1bf

File tree

7 files changed

+232
-2
lines changed

7 files changed

+232
-2
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
<integration_name>Magento Analytics user</integration_name>
2121
<general>
2222
<collection_time>02,00,00</collection_time>
23+
<token/>
2324
</general>
2425
</analytics>
2526
</default>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\App\Config\Source;
9+
10+
use Magento\Config\Model\Config\Structure;
11+
use Magento\Framework\App\Config\ConfigSourceInterface;
12+
use Magento\Framework\DataObject;
13+
14+
/**
15+
* Class for retrieving configuration structure
16+
*/
17+
class ConfigStructureSource implements ConfigSourceInterface
18+
{
19+
/**
20+
* @var Structure
21+
*/
22+
private $structure;
23+
24+
/**
25+
* @param Structure $structure
26+
*/
27+
public function __construct(Structure $structure)
28+
{
29+
$this->structure = $structure;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function get($path = '')
36+
{
37+
$fieldPaths = array_keys($this->structure->getFieldPaths());
38+
$defaultConfig = [];
39+
foreach ($fieldPaths as $fieldPath) {
40+
$defaultConfig = $this->addPathToConfig($defaultConfig, $fieldPath);
41+
}
42+
$data = new DataObject(['default' => $defaultConfig]);
43+
44+
return $data->getData($path);
45+
}
46+
47+
/**
48+
* Add config path to config structure
49+
*
50+
* @param array $config
51+
* @param string $path
52+
* @return array
53+
*/
54+
private function addPathToConfig(array $config, string $path): array
55+
{
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;
64+
}
65+
66+
return $config;
67+
}
68+
}
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@
207207
<virtualType name="appDumpSystemSource" type="Magento\Config\App\Config\Source\DumpConfigSourceAggregated">
208208
<arguments>
209209
<argument name="sources" xsi:type="array">
210+
<item name="structure" xsi:type="array">
211+
<item name="source" xsi:type="object">Magento\Config\App\Config\Source\ConfigStructureSource</item>
212+
<item name="sortOrder" xsi:type="string">1</item>
213+
</item>
210214
<item name="modular" xsi:type="array">
211215
<item name="source" xsi:type="object">Magento\Config\App\Config\Source\ModularConfigSource</item>
212216
<item name="sortOrder" xsi:type="string">10</item>
@@ -346,4 +350,19 @@
346350
<argument name="excludeList" xsi:type="object">Magento\Config\Model\Config\Export\ExcludeList</argument>
347351
</arguments>
348352
</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>
349368
</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)