From 41f49d8026f4d22106f91197b5d76376101280fd Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Mon, 13 Feb 2023 14:42:38 +0100 Subject: [PATCH] [Tests] Added test coverage for the bug --- composer.json | 5 +- .../Parser/SubtreeOperationsTest.php | 81 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/bundle/DependencyInjection/Configuration/Parser/SubtreeOperationsTest.php diff --git a/composer.json b/composer.json index 43f3426788..689760682a 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/tests/bundle/DependencyInjection/Configuration/Parser/SubtreeOperationsTest.php b/tests/bundle/DependencyInjection/Configuration/Parser/SubtreeOperationsTest.php new file mode 100644 index 0000000000..8494c9b38e --- /dev/null +++ b/tests/bundle/DependencyInjection/Configuration/Parser/SubtreeOperationsTest.php @@ -0,0 +1,81 @@ + + */ + 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); + } +}