Allow to directly use IRIs for attachmennts without the need to rely on _type

This commit is contained in:
Jan Böhmer 2026-05-25 22:22:55 +02:00
parent 87874230ef
commit 0da5befd7b
2 changed files with 63 additions and 6 deletions

View file

@ -69,4 +69,28 @@ final class PartEndpointTest extends CrudEndpointTestCase
{
$this->_testDeleteItem(1);
}
}
public function testAttachmentPatchWithIRI(): void
{
$client = static::createAuthenticatedClient();
// Create a new attachment with a picture URL for Part 1
$response = $client->request('POST', '/api/attachments', ['json' => [
'name' => 'Test Picture',
'url' => 'http://example.com/test.jpg',
'_type' => 'Part',
'element' => '/api/parts/1',
'attachment_type' => '/api/attachment_types/1',
]]);
self::assertResponseIsSuccessful();
$attachmentIri = $response->toArray()['@id'];
// Now PATCH Part 1 to set master_picture_attachment
$client->request('PATCH', '/api/parts/1', [
'json' => ['master_picture_attachment' => $attachmentIri],
'headers' => ['Content-Type' => 'application/merge-patch+json'],
]);
self::assertResponseIsSuccessful();
self::assertJsonContains(['master_picture_attachment' => ['@id' => $attachmentIri]]);
}
}