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 f3fef9c
Show file tree
Hide file tree
Showing 2 changed files with 79 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 @@ -25,6 +25,8 @@ public function visit(Visitor $visitor, Generator $generator, $data)

protected function visitImageVariationAttributes(Visitor $visitor, Generator $generator, ImageVariationValue $data)
{
$visitor->setHeader('Content-Type', $generator->getMediaType('ContentImageVariation'));

$generator->startAttribute(
'href',
$this->router->generate(
Expand Down
77 changes: 77 additions & 0 deletions tests/bundle/Functional/ImageVariationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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;

final class ImageVariationTest extends RESTFunctionalTestCase
{
public function testCreateContent(): void
{
// Targets
$contentTypeId = 5; // "Image"
$parentLocationPath = '1/43/51'; // "Media > Images"
$sectionId = 3; // "Media"

$fileName = basename('1px image.png');
$fileContent = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wAAAZABAcM/pFYAAAAASUVORK5CYII=';
$fileSize = 1;
$name = $fileName;

$api = '/api/ezp/v2';
$body = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<ContentCreate>
<ContentType href="{$api}/content/types/{$contentTypeId}" />
<mainLanguageCode>eng-GB</mainLanguageCode>
<LocationCreate>
<ParentLocation href="{$api}/content/locations/{$parentLocationPath}" />
<sortField>PATH</sortField>
<sortOrder>ASC</sortOrder>
</LocationCreate>
<Section href="{$api}/content/sections/{$sectionId}" />
<fields>
<field>
<fieldDefinitionIdentifier>name</fieldDefinitionIdentifier>
<fieldValue>{$name}</fieldValue>
</field>
<field>
<fieldDefinitionIdentifier>caption</fieldDefinitionIdentifier>
<fieldValue>
<value key="xml"><![CDATA[<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit"><h1>{$name}</h1></section>]]></value>
</fieldValue>
</field>
<field>
<fieldDefinitionIdentifier>image</fieldDefinitionIdentifier>
<fieldValue>
<value key="fileName">{$fileName}</value>
<value key="fileSize">{$fileSize}</value>
<value key="data"><![CDATA[{$fileContent}]]></value>
</fieldValue>
</field>
</fields>
</ContentCreate>
XML;

$request = $this->createHttpRequest(
'POST',
'/api/ezp/v2/content/objects',
'ContentCreate+xml',
'ContentInfo+xml',
$body
);

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

self::assertEquals('201', $response->getStatusCode());

$href = $response->getHeader('Location')[0];
var_dump($href, (string)$response->getBody());d
}

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

View workflow job for this annotation

GitHub Actions / Unit tests (7.3)

Syntax error, unexpected '}' on line 76

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

View workflow job for this annotation

GitHub Actions / Unit tests (7.4)

Syntax error, unexpected '}' on line 76

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

View workflow job for this annotation

GitHub Actions / Unit tests (8.0)

Syntax error, unexpected '}' on line 76

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

View workflow job for this annotation

GitHub Actions / Unit tests (8.2)

Syntax error, unexpected '}' on line 76
}

0 comments on commit f3fef9c

Please sign in to comment.