Skip to content

Commit 35b0b31

Browse files
authored
IBX-5076: Fixed disabling ability to copy subtree (#2091)
* Fixed SubtreeOperations Config Parser to accept 0 copy subtree limit * [Tests] Added test coverage for the bug
1 parent d7cc8ca commit 35b0b31

File tree

3 files changed

+93
-23
lines changed

3 files changed

+93
-23
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
}
1212
},
1313
"autoload-dev": {
14-
"psr-4": { "EzSystems\\EzPlatformAdminUi\\Tests\\": "src/lib/Tests" }
14+
"psr-4": {
15+
"EzSystems\\EzPlatformAdminUi\\Tests\\": "src/lib/Tests",
16+
"Ibexa\\Tests\\Bundle\\AdminUi\\": "tests/bundle/"
17+
}
1518
},
1619
"require": {
1720
"php": "^7.3 || ^8.0",

src/bundle/DependencyInjection/Configuration/Parser/SubtreeOperations.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,20 @@ class SubtreeOperations extends AbstractParser
3030
/**
3131
* @inheritdoc
3232
*/
33-
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
33+
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
3434
{
35-
if (empty($scopeSettings['subtree_operations'])) {
35+
if (!isset($scopeSettings['subtree_operations']['copy_subtree']['limit'])) {
3636
return;
3737
}
3838

39-
$settings = $scopeSettings['subtree_operations'];
40-
$nodes = ['copy_subtree' => ['limit']];
41-
42-
foreach ($nodes as $node => $keys) {
43-
foreach ($keys as $key) {
44-
if (!isset($settings[$node][$key]) || empty($settings[$node][$key])) {
45-
continue;
46-
}
47-
48-
$contextualizer->setContextualParameter(
49-
sprintf('subtree_operations.%s.%s', $node, $key),
50-
$currentScope,
51-
$settings[$node][$key]
52-
);
53-
}
54-
}
39+
$contextualizer->setContextualParameter(
40+
'subtree_operations.copy_subtree.limit',
41+
$currentScope,
42+
$scopeSettings['subtree_operations']['copy_subtree']['limit']
43+
);
5544
}
5645

57-
/**
58-
* @inheritdoc
59-
*/
60-
public function addSemanticConfig(NodeBuilder $nodeBuilder)
46+
public function addSemanticConfig(NodeBuilder $nodeBuilder): void
6147
{
6248
$nodeBuilder
6349
->arrayNode('subtree_operations')
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Bundle\AdminUi\DependencyInjection\Configuration\Parser;
10+
11+
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
12+
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreeOperations;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* @covers \EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreeOperations
17+
*/
18+
final class SubtreeOperationsTest extends TestCase
19+
{
20+
/** @var \EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreeOperations */
21+
private $parser;
22+
23+
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface&\PHPUnit\Framework\MockObject\MockObject */
24+
private $contextualizer;
25+
26+
/**
27+
* @return array<string, array{int}>
28+
*/
29+
public function getExpectedCopySubtreeLimit(): iterable
30+
{
31+
yield 'default = 100' => [100];
32+
yield 'no limit = -1' => [-1];
33+
yield 'disabled = 0' => [0];
34+
}
35+
36+
protected function setUp(): void
37+
{
38+
$this->parser = new SubtreeOperations();
39+
$this->contextualizer = $this->createMock(ContextualizerInterface::class);
40+
}
41+
42+
/**
43+
* @dataProvider getExpectedCopySubtreeLimit
44+
*/
45+
public function testCopySubtreeLimit(int $expectedCopySubtreeLimit): void
46+
{
47+
$scopeSettings = [
48+
'subtree_operations' => [
49+
'copy_subtree' => [
50+
'limit' => $expectedCopySubtreeLimit,
51+
],
52+
],
53+
];
54+
$currentScope = 'admin_group';
55+
56+
$this->contextualizer
57+
->expects(self::once())
58+
->method('setContextualParameter')
59+
->with(
60+
'subtree_operations.copy_subtree.limit',
61+
$currentScope,
62+
$expectedCopySubtreeLimit
63+
);
64+
65+
$this->parser->mapConfig($scopeSettings, $currentScope, $this->contextualizer);
66+
}
67+
68+
public function testCopySubtreeLimitNotSet(): void
69+
{
70+
$scopeSettings = [
71+
'subtree_operations' => null,
72+
];
73+
$currentScope = 'admin_group';
74+
75+
$this->contextualizer
76+
->expects(self::never())
77+
->method('setContextualParameter');
78+
79+
$this->parser->mapConfig($scopeSettings, $currentScope, $this->contextualizer);
80+
}
81+
}

0 commit comments

Comments
 (0)