From 4c8a173592b600f5d2fc97c10527b5b808cce59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20S=C5=82omka?= Date: Wed, 20 Sep 2023 11:04:20 +0200 Subject: [PATCH 1/2] IBX-6239: Added Content Type for Image Variation --- .../ValueObjectVisitor/ImageVariation.php | 1 + .../bundle/Functional/ImageVariationTest.php | 131 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 tests/bundle/Functional/ImageVariationTest.php diff --git a/src/lib/Server/Output/ValueObjectVisitor/ImageVariation.php b/src/lib/Server/Output/ValueObjectVisitor/ImageVariation.php index 7d1701c1..49ff1a4b 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/ImageVariation.php +++ b/src/lib/Server/Output/ValueObjectVisitor/ImageVariation.php @@ -18,6 +18,7 @@ class ImageVariation extends ValueObjectVisitor */ public function visit(Visitor $visitor, Generator $generator, $data) { + $visitor->setHeader('Content-Type', $generator->getMediaType('ContentImageVariation')); $generator->startObjectElement('ContentImageVariation'); $this->visitImageVariationAttributes($visitor, $generator, $data); $generator->endObjectElement('ContentImageVariation'); diff --git a/tests/bundle/Functional/ImageVariationTest.php b/tests/bundle/Functional/ImageVariationTest.php new file mode 100644 index 00000000..ae3c1db2 --- /dev/null +++ b/tests/bundle/Functional/ImageVariationTest.php @@ -0,0 +1,131 @@ +addTestSuffix(__FUNCTION__); + $fileName = '1px.png'; + $fileSize = 4718; + $fileData = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=='; + $restPrefixPath = '/api/ezp/v2'; + $body = <<< XML + + + + eng-GB + + + 0 + false + PATH + ASC + +
+ true + {$string} + + 2012-09-30T12:30:00 + + + name + eng-GB + {$string} + + + image + eng-GB + + {$fileName} + {$fileSize} + {$fileData} + + + + +XML; + $request = $this->createHttpRequest( + 'POST', + $restPrefixPath . '/content/objects', + 'ContentCreate+xml', + 'ContentInfo+json', + $body + ); + + $response = $this->sendHttpRequest($request); + + $this->assertHttpResponseCodeEquals($response, Response::HTTP_CREATED); + $this->assertHttpResponseHasHeader($response, 'Location'); + $this->assertHttpResponseHasHeader($response, 'content-type', 'application/vnd.ez.api.ContentInfo+json'); + + $href = $response->getHeader('Location')[0]; + $this->addCreatedElement($href); + + $contentInfo = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); + + return sprintf( + '%s/%d', $contentInfo['Content']['Versions']['_href'], $contentInfo['Content']['currentVersionNo'] + ); + } + + /** + * @depends testCreateContent + */ + public function testPublishContent(string $restContentHref): string + { + $response = $this->sendHttpRequest( + $this->createHttpRequest('PUBLISH', $restContentHref) + ); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_NO_CONTENT); + + return $restContentHref; + } + + /** + * @depends testPublishContent + */ + public function testGetImageVariation(string $restVersionHref): void + { + $imageResponse = $this->sendHttpRequest( + $this->createHttpRequest( + 'GET', + $restVersionHref, + '', + 'Version+json' + ) + ); + + $jsonResponse = json_decode((string)$imageResponse->getBody(), true, 512, JSON_THROW_ON_ERROR); + $imageField = $jsonResponse['Version']['Fields']['field'][2]; + + self::assertArrayHasKey('variations', $imageField['fieldValue']); + + $variationUrl = $imageField['fieldValue']['variations']['medium']['href']; + + $variationResponse = $this->sendHttpRequest( + $this->createHttpRequest( + 'GET', + $variationUrl, + '', + 'Version+json' + ) + ); + self::assertHttpResponseCodeEquals($variationResponse, Response::HTTP_OK); + self::assertHttpResponseHasHeader( + $variationResponse, + 'content-type', + 'application/vnd.ez.api.ContentImageVariation+json' + ); + } +} From 094073f7717057a393add8720f793a05ded8e20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20S=C5=82omka?= Date: Wed, 20 Sep 2023 15:26:12 +0200 Subject: [PATCH 2/2] [Tests] Fixed test after merge-up from 3.3 (#74) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed test failing in https://github.com/ibexa/rest/pull/73 Co-authored-by: Krzysztof SÅ‚omka --- tests/bundle/Functional/ImageVariationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bundle/Functional/ImageVariationTest.php b/tests/bundle/Functional/ImageVariationTest.php index 49e2e9c0..fb84c043 100644 --- a/tests/bundle/Functional/ImageVariationTest.php +++ b/tests/bundle/Functional/ImageVariationTest.php @@ -127,7 +127,7 @@ public function testGetImageVariation(string $restVersionHref): void self::assertHttpResponseHasHeader( $variationResponse, 'content-type', - 'application/vnd.ez.api.ContentImageVariation+json' + 'application/vnd.ibexa.api.ContentImageVariation+json' ); } }