From 6c8b5d591ec3f758222bba500f89f2aa88b490f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20=C4=8Cupi=C4=87?= Date: Tue, 10 Oct 2023 08:13:55 +0200 Subject: [PATCH] Fix issue with resolving context --- .../Provider/Cloudinary/Factory/RemoteResource.php | 12 +++++++++--- .../Cloudinary/Factory/RemoteResourceTest.php | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php b/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php index 18dbdb42..20f03499 100644 --- a/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php +++ b/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php @@ -12,6 +12,8 @@ use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType as VisibilityTypeConverter; use Netgen\RemoteMedia\Exception\Factory\InvalidDataException; +use function array_key_exists; +use function array_merge; use function cloudinary_url_internal; use function in_array; use function pathinfo; @@ -24,8 +26,7 @@ public function __construct( private ResourceTypeConverter $resourceTypeConverter, private VisibilityTypeConverter $visibilityTypeConverter, private FileHashFactoryInterface $fileHashFactory - ) { - } + ) {} public function create($data): RemoteResourceValue { @@ -154,7 +155,12 @@ private function resolveMetaData(array $data): array private function resolveContext(array $data): array { $context = $data['context'] ?? []; - $context = $context['custom'] ?? []; + + if (array_key_exists('custom', $context)) { + $context = array_merge($context, $context['custom']); + + unset($context['custom']); + } unset($context['alt'], $context['caption']); diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php index 268e7633..bfc44ecf 100644 --- a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php +++ b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php @@ -305,6 +305,12 @@ public static function createDataProvider(): array 'type' => 'test', 'secure_url' => 'https://res.cloudinary.com/myCloud/v1371995958/raw/media/raw/new/c87hg9xfxrd4itiim3t0', 'etag' => 'e522f43cf89aa0afd03387c38e2b6e29', + 'context' => [ + 'test' => 'test', + 'custom' => [ + 'test2' => 'test2', + ], + ], ], new RemoteResource( remoteId: 'test|raw|media/raw/new/c87hg9xfxrd4itiim3t0', @@ -322,6 +328,10 @@ public static function createDataProvider(): array 'format' => 'zip', 'created_at' => '2011-06-23T13:59:18Z', ], + context: [ + 'test' => 'test', + 'test2' => 'test2', + ], ), ], ];