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) 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) { diff --git a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php index 10ecaa270..d128f1e0f 100644 --- a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php +++ b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php @@ -594,8 +594,9 @@ public function testDestroyFailed(): void { * @todo Avoid business code in controller * @param mixed $setSize * @param mixed $size + * @param mixed $sizeToQuery */ - public function testImage($setSize, $size): void { + public function testImage($setSize, $size, $sizeToQuery): void { $this->ensureCacheCheckTriggered(); if ($setSize) { @@ -605,7 +606,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 +636,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'], ]; }