Skip to content

Commit

Permalink
[Tests] Added test coverage for the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Mar 28, 2023
1 parent 5a9c295 commit 41f49d8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
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
@@ -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 41f49d8

Please # to comment.