From d3d6b30b7f214b6aa69a9b0e16c65ff6610b3418 Mon Sep 17 00:00:00 2001 From: Kyle Jones Date: Tue, 18 Feb 2025 12:32:07 -0800 Subject: [PATCH 1/4] Fix default recipe image fallback to be a valid value: "full" Signed-off-by: Christian Wolf --- lib/Controller/Implementation/RecipeImplementation.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Controller/Implementation/RecipeImplementation.php b/lib/Controller/Implementation/RecipeImplementation.php index c8c5871b6..b2e0416f3 100644 --- a/lib/Controller/Implementation/RecipeImplementation.php +++ b/lib/Controller/Implementation/RecipeImplementation.php @@ -247,10 +247,8 @@ public function image($id) { $acceptHeader = $this->request->getHeader('Accept'); $acceptedExtensions = $this->acceptHeaderParser->parseHeader($acceptHeader); - $size = isset($_GET['size']) ? $_GET['size'] : null; - try { - $file = $this->service->getRecipeImageFileByFolderId($id, $size); + $file = $this->service->getRecipeImageFileByFolderId($id, $_GET['size'] ?? 'full'); return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/jpeg', 'Cache-Control' => 'public, max-age=604800']); } catch (\Exception $e) { From 752bb6806aa33e759b6af3e482885ebefc396786 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Thu, 6 Mar 2025 16:52:38 +0100 Subject: [PATCH 2/4] Update Changelog Signed-off-by: Christian Wolf --- .changelog/current/2661-fix-api-behavior.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/current/2661-fix-api-behavior.md diff --git a/.changelog/current/2661-fix-api-behavior.md b/.changelog/current/2661-fix-api-behavior.md new file mode 100644 index 000000000..9f44be33d --- /dev/null +++ b/.changelog/current/2661-fix-api-behavior.md @@ -0,0 +1,3 @@ +# Fixed + +- Default to full image size if no size is explicitly requestes (as specified in API spec) From 7c3fb234dc8fdd67dbbac4ee9a5977618e2da9d3 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Thu, 6 Mar 2025 20:22:23 +0100 Subject: [PATCH 3/4] Fix tests Signed-off-by: Christian Wolf --- .../Implementation/RecipeImplementationTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php index 10ecaa270..eb8bdcf35 100644 --- a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php +++ b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php @@ -595,7 +595,7 @@ public function testDestroyFailed(): void { * @param mixed $setSize * @param mixed $size */ - public function testImage($setSize, $size): void { + public function testImage($setSize, $size, $sizeToQuery): void { $this->ensureCacheCheckTriggered(); if ($setSize) { @@ -605,7 +605,7 @@ public function testImage($setSize, $size): void { /** @var File|Stub */ $file = $this->createStub(File::class); $id = 123; - $this->recipeService->method('getRecipeImageFileByFolderId')->with($id, $size)->willReturn($file); + $this->recipeService->method('getRecipeImageFileByFolderId')->with($id, $sizeToQuery)->willReturn($file); // Make the tests stable against PHP deprecation warnings $file->method('getMTime')->willReturn(100); @@ -635,9 +635,10 @@ public function testImage($setSize, $size): void { public function dataProviderImage(): array { return [ - [false, null], - [true, null], - [true, 'full'], + [false, null, 'full'], + [true, null, 'full'], + [true, 'full', 'full'], + [true, 'small', 'small'], ]; } From b9d25abd4e606f9e5fe3b0e1d6dff47e94dc17bd Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Thu, 6 Mar 2025 20:41:40 +0100 Subject: [PATCH 4/4] Make code styler happy Signed-off-by: Christian Wolf --- .../Unit/Controller/Implementation/RecipeImplementationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php index eb8bdcf35..d128f1e0f 100644 --- a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php +++ b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php @@ -594,6 +594,7 @@ public function testDestroyFailed(): void { * @todo Avoid business code in controller * @param mixed $setSize * @param mixed $size + * @param mixed $sizeToQuery */ public function testImage($setSize, $size, $sizeToQuery): void { $this->ensureCacheCheckTriggered();