From 948bd5e0d47d9c2a6bc7b6ad6ace81d5f808f98a Mon Sep 17 00:00:00 2001 From: David Maicher Date: Mon, 29 Aug 2022 11:03:18 +0200 Subject: [PATCH] fix issue with overwriting default config on default profile --- .../ExerciseHTMLPurifierExtension.php | 5 +++- .../ExerciseHTMLPurifierExtensionTest.php | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php index 3383d1c2..f6a5686f 100644 --- a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php +++ b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php @@ -27,7 +27,10 @@ public function load(array $configs, ContainerBuilder $container): void // Set default serializer cache path, while ensuring a default profile is defined $configs['html_profiles']['default']['config']['Cache.SerializerPath'] = $configs['default_cache_serializer_path']; - $configs['html_profiles']['default']['config']['Cache.SerializerPermissions'] = $configs['default_cache_serializer_permissions']; + + if (!isset($configs['html_profiles']['default']['config']['Cache.SerializerPermissions'])) { + $configs['html_profiles']['default']['config']['Cache.SerializerPermissions'] = $configs['default_cache_serializer_permissions']; + } $serializerPaths = []; // Drop when require Symfony > 3.4 diff --git a/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php b/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php index 8a5937f3..fde6d8f8 100644 --- a/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php +++ b/tests/DependencyInjection/ExerciseHTMLPurifierExtensionTest.php @@ -153,6 +153,30 @@ public function testShouldAllowOverridingDefaultConfigurationCacheSerializerPerm $this->assertRegistryHasProfiles(['default']); } + public function testShouldAllowOverridingDefaultConfigurationCacheSerializerPermissionsOnDefaultProfile(): void + { + $config = [ + 'default_cache_serializer_path' => null, + 'html_profiles' => [ + 'default' => [ + 'config' => [ + 'AutoFormat.AutoParagraph' => true, + 'Cache.SerializerPermissions' => 511, + ], + ], + ], + ]; + + $this->extension->load([$config], $this->container); + + $this->assertDefaultConfigDefinition(array_merge($config['html_profiles']['default']['config'], [ + 'Cache.SerializerPath' => null, + 'Cache.SerializerPermissions' => 511, + ])); + $this->assertCacheWarmerSerializerArgs([], ['default']); + $this->assertRegistryHasProfiles(['default']); + } + public function testShouldNotDeepMergeOptions(): void { $configs = [