Skip to content

Commit

Permalink
IBX-5076: Fixed disabling ability to copy subtree (#2091)
Browse files Browse the repository at this point in the history
* Fixed SubtreeOperations Config Parser to accept 0 copy subtree limit

* [Tests] Added test coverage for the bug
  • Loading branch information
alongosz authored Mar 28, 2023
1 parent d7cc8ca commit 35b0b31
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 23 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
}
},
"autoload-dev": {
"psr-4": { "EzSystems\\EzPlatformAdminUi\\Tests\\": "src/lib/Tests" }
"psr-4": {
"EzSystems\\EzPlatformAdminUi\\Tests\\": "src/lib/Tests",
"Ibexa\\Tests\\Bundle\\AdminUi\\": "tests/bundle/"
}
},
"require": {
"php": "^7.3 || ^8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,20 @@ class SubtreeOperations extends AbstractParser
/**
* @inheritdoc
*/
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
if (empty($scopeSettings['subtree_operations'])) {
if (!isset($scopeSettings['subtree_operations']['copy_subtree']['limit'])) {
return;
}

$settings = $scopeSettings['subtree_operations'];
$nodes = ['copy_subtree' => ['limit']];

foreach ($nodes as $node => $keys) {
foreach ($keys as $key) {
if (!isset($settings[$node][$key]) || empty($settings[$node][$key])) {
continue;
}

$contextualizer->setContextualParameter(
sprintf('subtree_operations.%s.%s', $node, $key),
$currentScope,
$settings[$node][$key]
);
}
}
$contextualizer->setContextualParameter(
'subtree_operations.copy_subtree.limit',
$currentScope,
$scopeSettings['subtree_operations']['copy_subtree']['limit']
);
}

/**
* @inheritdoc
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
public function addSemanticConfig(NodeBuilder $nodeBuilder): void
{
$nodeBuilder
->arrayNode('subtree_operations')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\AdminUi\DependencyInjection\Configuration\Parser;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreeOperations;
use PHPUnit\Framework\TestCase;

/**
* @covers \EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreeOperations
*/
final class SubtreeOperationsTest extends TestCase
{
/** @var \EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreeOperations */
private $parser;

/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface&\PHPUnit\Framework\MockObject\MockObject */
private $contextualizer;

/**
* @return array<string, array{int}>
*/
public function getExpectedCopySubtreeLimit(): iterable
{
yield 'default = 100' => [100];
yield 'no limit = -1' => [-1];
yield 'disabled = 0' => [0];
}

protected function setUp(): void
{
$this->parser = new SubtreeOperations();
$this->contextualizer = $this->createMock(ContextualizerInterface::class);
}

/**
* @dataProvider getExpectedCopySubtreeLimit
*/
public function testCopySubtreeLimit(int $expectedCopySubtreeLimit): void
{
$scopeSettings = [
'subtree_operations' => [
'copy_subtree' => [
'limit' => $expectedCopySubtreeLimit,
],
],
];
$currentScope = 'admin_group';

$this->contextualizer
->expects(self::once())
->method('setContextualParameter')
->with(
'subtree_operations.copy_subtree.limit',
$currentScope,
$expectedCopySubtreeLimit
);

$this->parser->mapConfig($scopeSettings, $currentScope, $this->contextualizer);
}

public function testCopySubtreeLimitNotSet(): void
{
$scopeSettings = [
'subtree_operations' => null,
];
$currentScope = 'admin_group';

$this->contextualizer
->expects(self::never())
->method('setContextualParameter');

$this->parser->mapConfig($scopeSettings, $currentScope, $this->contextualizer);
}
}

0 comments on commit 35b0b31

Please sign in to comment.