Skip to content

Commit

Permalink
Merged branch '2.3' of ezsystems/ezplatform-admin-ui into 4.4 (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou authored Mar 29, 2023
2 parents 257d972 + 2d96229 commit 7e60577
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Example configuration:
* ```yaml
* ezpublish:
* ibexa:
* system:
* default: # configuration per siteaccess or siteaccess group
* subtree_operations:
Expand All @@ -27,37 +27,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,80 @@
<?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 Ibexa\Bundle\AdminUi\DependencyInjection\Configuration\Parser\SubtreeOperations;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \Ibexa\Bundle\AdminUi\DependencyInjection\Configuration\Parser\SubtreeOperations
*/
final class SubtreeOperationsTest extends TestCase
{
private SubtreeOperations $parser;

/** @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface */
private ContextualizerInterface $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 7e60577

Please sign in to comment.