Skip to content

Fix default recipe image fallback to be a valid value: "full" #2661

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/current/2661-fix-api-behavior.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fixed

- Default to full image size if no size is explicitly requestes (as specified in API spec)
4 changes: 1 addition & 3 deletions lib/Controller/Implementation/RecipeImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
*
* @param $id The id of the recipe in question
* @return JSONResponse
* @todo Parameter id is never used. Fix that

Check warning on line 122 in lib/Controller/Implementation/RecipeImplementation.php

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found @todo Parameter id is never used. Fix that
*/
public function update($id) {
$this->dbCacheService->triggerCheck();
Expand Down Expand Up @@ -247,10 +247,8 @@
$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@

/**
* @dataProvider dpSearch
* @todo no implementation in controller

Check warning on line 338 in tests/Unit/Controller/Implementation/RecipeImplementationTest.php

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found @todo no implementation in controller
* @param mixed $query
* @param mixed $recipes
*/
Expand Down Expand Up @@ -590,12 +590,13 @@

/**
* @dataProvider dataProviderImage
* @todo Assert on image data/file name

Check warning on line 593 in tests/Unit/Controller/Implementation/RecipeImplementationTest.php

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found @todo Assert on image data/file name
* @todo Avoid business code in controller

Check warning on line 594 in tests/Unit/Controller/Implementation/RecipeImplementationTest.php

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found @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) {
Expand All @@ -605,7 +606,7 @@
/** @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);
Expand Down Expand Up @@ -635,9 +636,10 @@

public function dataProviderImage(): array {
return [
[false, null],
[true, null],
[true, 'full'],
[false, null, 'full'],
[true, null, 'full'],
[true, 'full', 'full'],
[true, 'small', 'small'],
];
}

Expand Down Expand Up @@ -670,7 +672,7 @@

/**
* @dataProvider dataProviderIndex
* @todo no work on controller

Check warning on line 675 in tests/Unit/Controller/Implementation/RecipeImplementationTest.php

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found @todo no work on controller
* @param mixed $recipes
* @param mixed $setKeywords
* @param mixed $keywords
Expand Down
Loading