Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-3823: Fixed appending limitations, when there are no initial values #335

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function addConfig(array $config)
foreach ($config as $module => $functionArray) {
foreach ($functionArray as $function => $limitationCollection) {
if (null !== $limitationCollection && $this->policyExists($previousPolicyMap, $module, $function)) {
$limitations = array_merge_recursive($previousPolicyMap[$module][$function], array_fill_keys((array)$limitationCollection, true));
$limitations = array_merge_recursive($previousPolicyMap[$module][$function] ?? [], array_fill_keys((array)$limitationCollection, true));
} else {
$limitations = array_fill_keys((array)$limitationCollection, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,46 @@

class PoliciesConfigBuilderTest extends TestCase
{
public function testAddConfig()
/**
* @dataProvider policiesConfigProvider
*/
public function testAddConfig(array $configOne, array $configTwo, array $expectedConfig): void
{
$containerBuilder = new ContainerBuilder();
$configBuilder = new PoliciesConfigBuilder($containerBuilder);
$config1 = ['foo' => ['bar' => null]];
$config2 = ['some' => ['thing' => ['limitation']]];
$expected = [
'foo' => ['bar' => []],
'some' => ['thing' => ['limitation' => true]],
];
$configBuilder->addConfig($config1);
$configBuilder->addConfig($config2);

self::assertSame($expected, $containerBuilder->getParameter('ezpublish.api.role.policy_map'));
$configBuilder->addConfig($configOne);
$configBuilder->addConfig($configTwo);

self::assertSame($expectedConfig, $containerBuilder->getParameter('ezpublish.api.role.policy_map'));
}

public function policiesConfigProvider(): array
{
return [
'add' => [
['foo' => ['bar' => null]],
['some' => ['thing' => ['limitation']]],
[
'foo' => ['bar' => []],
'some' => ['thing' => ['limitation' => true]],
],
],
'append' => [
['foo' => ['bar' => ['limitation']]],
['foo' => ['bar' => ['new_limitation']]],
[
'foo' => ['bar' => ['limitation' => true, 'new_limitation' => true]],
],
],
'append_to_empty' => [
['foo' => ['bar' => null]],
['foo' => ['bar' => ['new_limitation']]],
[
'foo' => ['bar' => ['new_limitation' => true]],
],
],
];
}

public function testAddResource()
Expand Down