Skip to content

Commit 3d1abb1

Browse files
committed
BUGFIX: Type issues with tagging assets
1 parent 43f547d commit 3d1abb1

File tree

5 files changed

+57
-19
lines changed

5 files changed

+57
-19
lines changed

Classes/GraphQL/Mutator/AssetMutator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,15 @@ public function setAssetTags(
198198
Types\AssetSourceId $assetSourceId,
199199
Types\TagIds $tagIds
200200
): ?Types\Asset {
201-
$asset = $this->assetSourceContext->getAssetProxy($id, $assetSourceId);
201+
$asset = $this->assetSourceContext->getAsset($id, $assetSourceId);
202202
if (!$asset) {
203203
throw new MediaUiException('Cannot tag asset that was never imported', 1594621322);
204204
}
205205
if (!$asset instanceof Asset) {
206-
throw new MediaUiException('Asset type does not support tagging', 1619081714);
206+
throw new MediaUiException(
207+
sprintf('Asset type %s does not support tagging', $asset::class),
208+
1619081714
209+
);
207210
}
208211

209212
$tags = new ArrayCollection();
@@ -233,7 +236,7 @@ public function setAssetCollections(
233236
Types\AssetSourceId $assetSourceId,
234237
Types\AssetCollectionIds $assetCollectionIds
235238
): MutationResult {
236-
$asset = $this->assetSourceContext->getAssetProxy($id, $assetSourceId);
239+
$asset = $this->assetSourceContext->getAsset($id, $assetSourceId);
237240
if (!$asset) {
238241
throw new MediaUiException('Cannot assign collections to asset that was never imported', 1594621322);
239242
}
@@ -265,7 +268,7 @@ public function setAssetCollections(
265268
*/
266269
public function untagAsset(Types\AssetId $id, Types\AssetSourceId $assetSourceId, Types\TagId $tagId): ?Types\Asset
267270
{
268-
$asset = $this->assetSourceContext->getAssetProxy($id, $assetSourceId);
271+
$asset = $this->assetSourceContext->getAsset($id, $assetSourceId);
269272
if (!$asset) {
270273
throw new MediaUiException('Cannot untag asset that was never imported', 1591561930);
271274
}

Tests/Functional/AbstractMediaTestCase.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
* source code.
1212
*/
1313

14+
use Flowpack\Media\Ui\GraphQL\Types;
1415
use Neos\Flow\Persistence\PersistenceManagerInterface;
1516
use Neos\Flow\ResourceManagement\PersistentResource;
1617
use Neos\Flow\ResourceManagement\ResourceManager;
1718
use Neos\Flow\Tests\FunctionalTestCase;
1819
use Neos\Utility\Files;
1920

21+
use function Wwwision\Types\instantiate;
22+
2023
/**
2124
* Abstract Functional Test template
2225
*/
@@ -89,10 +92,21 @@ protected function prepareTemporaryDirectory()
8992

9093
/**
9194
* Initializes the resource manager and modifies the persistent resource storage location.
92-
* @return void
9395
*/
94-
protected function prepareResourceManager()
96+
protected function prepareResourceManager(): void
9597
{
9698
$this->resourceManager = $this->objectManager->get(ResourceManager::class);
9799
}
100+
101+
protected static function createFile(): Types\UploadedFile
102+
{
103+
$fileContent = Files::getFileContents(__DIR__ . '/Fixtures/norman.svg');
104+
return instantiate(Types\UploadedFile::class, [
105+
'streamOrFile' => $fileContent,
106+
'size' => strlen($fileContent),
107+
'clientMediaType' => 'image/svg+xml',
108+
'clientFilename' => 'test.svg',
109+
'errorStatus' => 0,
110+
]);
111+
}
98112
}

Tests/Functional/GraphQL/AssetApiTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Flowpack\Media\Ui\Tests\Functional\AbstractMediaTestCase;
2121
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
2222
use Neos\Flow\Tests\Behavior\Features\Bootstrap\SecurityOperationsTrait;
23-
use Neos\Utility\Files;
2423

2524
use function Wwwision\Types\instantiate;
2625

@@ -50,18 +49,6 @@ public function setUp(): void
5049
$this->iAmAuthenticatedWithRole('Neos.Neos:Editor');
5150
}
5251

53-
protected static function createFile(): Types\UploadedFile
54-
{
55-
$fileContent = Files::getFileContents(__DIR__ . '/Fixtures/norman.svg');
56-
return instantiate(Types\UploadedFile::class, [
57-
'streamOrFile' => $fileContent,
58-
'size' => strlen($fileContent),
59-
'clientMediaType' => 'image/svg+xml',
60-
'clientFilename' => 'test.svg',
61-
'errorStatus' => 0,
62-
]);
63-
}
64-
6552
public function testUploadFile(): void
6653
{
6754
$file = self::createFile();

Tests/Functional/GraphQL/TagApiTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Flowpack\Media\Ui\GraphQL\MediaApi;
1818
use Flowpack\Media\Ui\GraphQL\Resolver\Type\AssetCollectionResolver;
19+
use Flowpack\Media\Ui\GraphQL\Resolver\Type\AssetResolver;
1920
use Flowpack\Media\Ui\GraphQL\Types;
2021
use Flowpack\Media\Ui\Tests\Functional\AbstractMediaTestCase;
2122
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
@@ -39,6 +40,7 @@ public function setUp(): void
3940

4041
$this->mediaApi = $this->objectManager->get(MediaApi::class);
4142
$this->assetCollectionResolver = $this->objectManager->get(AssetCollectionResolver::class);
43+
$this->assetResolver = $this->objectManager->get(AssetResolver::class);
4244
}
4345

4446
public function testCreateTag(): void
@@ -82,4 +84,36 @@ public function testTagAssetCollection(): void
8284
'The tag should be associated with the asset collection'
8385
);
8486
}
87+
88+
public function testTagAsset(): void
89+
{
90+
$file = self::createFile();
91+
$result = $this->mediaApi->uploadFile($file);
92+
$this->assertTrue($result->success);
93+
94+
$this->persistenceManager->persistAll();
95+
$assets = $this->mediaApi->assets();
96+
/** @var Types\Asset $uploadedAsset */
97+
$uploadedAsset = $assets->getIterator()->current();
98+
99+
$tag = $this->mediaApi->createTag(Types\TagLabel::fromString('Test Tag'));
100+
$this->mediaApi->tagAsset(
101+
$uploadedAsset->id,
102+
$uploadedAsset->assetSource->id,
103+
$tag->id
104+
);
105+
106+
$resolvedTags = $this->assetResolver->tags($uploadedAsset);
107+
$this->assertCount(1, $resolvedTags->tags);
108+
$this->assertEquals('Test Tag', $resolvedTags->tags[0]->label);
109+
110+
$this->mediaApi->untagAsset(
111+
$uploadedAsset->id,
112+
$uploadedAsset->assetSource->id,
113+
$tag->id
114+
);
115+
116+
$resolvedTags = $this->assetResolver->tags($uploadedAsset);
117+
$this->assertCount(0, $resolvedTags->tags);
118+
}
85119
}

0 commit comments

Comments
 (0)