Skip to content

Commit

Permalink
Added Content Type for Image Variation
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Aug 30, 2023
1 parent 8383147 commit fd50113
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/Server/Output/ValueObjectVisitor/ImageVariation.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ protected function visitImageVariationAttributes(Visitor $visitor, Generator $ge
$generator->startValueElement('fileSize', $data->fileSize);
$generator->endValueElement('fileSize');
}

$visitor->setHeader('Content-Type', $generator->getMediaType('ContentImageVariation'));
}
}
143 changes: 143 additions & 0 deletions tests/bundle/Functional/ImageVariationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformRestBundle\Tests\Functional;

use EzSystems\EzPlatformRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase;
use Symfony\Component\HttpFoundation\Response;

final class ImageVariationTest extends RESTFunctionalTestCase
{
public function testCreateContent()

Check failure on line 16 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testCreateContent() has no return type specified.

Check failure on line 16 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testCreateContent() has no return type specified.

Check failure on line 16 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testCreateContent() has no return type specified.

Check failure on line 16 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testCreateContent() has no return type specified.
{
$string = $this->addTestSuffix(__FUNCTION__);
$pathToFile = __DIR__ . '/_fixtures/files/ibexa.png';
$fileName = pathinfo($pathToFile, PATHINFO_BASENAME);
$fileSize = filesize($pathToFile);
$fileData = base64_encode(file_get_contents($pathToFile));

Check failure on line 22 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Parameter #1 $str of function base64_encode expects string, string|false given.

Check failure on line 22 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Parameter #1 $str of function base64_encode expects string, string|false given.

Check failure on line 22 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Parameter #1 $string of function base64_encode expects string, string|false given.

Check failure on line 22 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Parameter #1 $string of function base64_encode expects string, string|false given.

$body = <<< XML
<?xml version="1.0" encoding="UTF-8"?>
<ContentCreate>
<ContentType href="/api/ezp/v2/content/types/5" />
<mainLanguageCode>eng-GB</mainLanguageCode>
<LocationCreate>
<ParentLocation href="/api/ezp/v2/content/locations/1/2" />
<priority>0</priority>
<hidden>false</hidden>
<sortField>PATH</sortField>
<sortOrder>ASC</sortOrder>
</LocationCreate>
<Section href="/api/ezp/v2/content/sections/3" />
<alwaysAvailable>true</alwaysAvailable>
<remoteId>{$string}</remoteId>
<User href="/api/ezp/v2/user/users/14" />
<modificationDate>2012-09-30T12:30:00</modificationDate>
<fields>
<field>
<fieldDefinitionIdentifier>name</fieldDefinitionIdentifier>
<languageCode>eng-GB</languageCode>
<fieldValue>{$string}</fieldValue>
</field>
<field>
<fieldDefinitionIdentifier>image</fieldDefinitionIdentifier>
<languageCode>eng-GB</languageCode>
<fieldValue>
<value key="fileName">{$fileName}</value>
<value key="fileSize">{$fileSize}</value>
<value key="data">{$fileData}</value>
</fieldValue>
</field>
</fields>
</ContentCreate>
XML;
$request = $this->createHttpRequest(
'POST',
'/api/ezp/v2/content/objects',
'ContentCreate+xml',
'ContentInfo+json',
$body
);

$response = $this->sendHttpRequest($request);

self::assertEquals('201', $response->getStatusCode());
self::assertHttpResponseHasHeader($response, 'Location');
self::assertHttpResponseHasHeader($response, 'content-type', 'application/vnd.ez.api.ContentInfo+json');

$href = $response->getHeader('Location')[0];
$this->addCreatedElement($href);

return $href;
}

/**
* @depends testCreateContent
* Covers PUBLISH /content/objects/<contentId>/versions/<versionNumber>
*
* @return string REST content ID
*/
public function testPublishContent($restContentHref)

Check failure on line 85 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testPublishContent() has parameter $restContentHref with no type specified.

Check failure on line 85 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testPublishContent() has parameter $restContentHref with no type specified.

Check failure on line 85 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testPublishContent() has parameter $restContentHref with no type specified.

Check failure on line 85 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testPublishContent() has parameter $restContentHref with no type specified.
{
$response = $this->sendHttpRequest(
$this->createHttpRequest('PUBLISH', sprintf('%s/versions/1', $restContentHref))
);
self::assertHttpResponseCodeEquals($response, 204);

return $restContentHref;
}

/**
* @depends testCreateContent
*/
public function testLoadContent($restContentHref)

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has no return type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has parameter $restContentHref with no type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has no return type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has parameter $restContentHref with no type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has no return type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has parameter $restContentHref with no type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has no return type specified.

Check failure on line 98 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testLoadContent() has parameter $restContentHref with no type specified.
{
$response = $this->sendHttpRequest(
$this->createHttpRequest('GET', $restContentHref,'',
'Version+json')
);

self::assertHttpResponseCodeEquals($response, 200);
self::assertArrayHasKey('content-type', $response->getHeaders());
self::assertHttpResponseHasHeader($response, 'content-type', 'application/vnd.ez.api.ContentInfo+json');
}

/**
* @depends testPublishContent
*/
public function testGetImageVariation(string $hrefToImage)

Check failure on line 113 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testGetImageVariation() has no return type specified.

Check failure on line 113 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testGetImageVariation() has no return type specified.

Check failure on line 113 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testGetImageVariation() has no return type specified.

Check failure on line 113 in tests/bundle/Functional/ImageVariationTest.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Method EzSystems\EzPlatformRestBundle\Tests\Functional\ImageVariationTest::testGetImageVariation() has no return type specified.
{
$restContentHref = $hrefToImage;
$imageResponse = $this->sendHttpRequest(
$this->createHttpRequest(
'GET',
$restContentHref . '/versions/1',
'',
'Version+json'
)
);

$jsonResponse = json_decode((string)$imageResponse->getBody());
$imageField = $jsonResponse->Version->Fields->field[2];

self::assertObjectHasAttribute('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');
}
}

0 comments on commit fd50113

Please sign in to comment.