|
| 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