medialibrary-helper/tests/Feature/UpdateTest.php

40 lines
1.5 KiB
PHP
Raw Normal View History

2023-03-07 23:11:35 +01:00
<?php
namespace Zoomyboy\MedialibraryHelper\Tests\Feature;
test('it updates a single files properties', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('multipleProperties');
$media = $post->getFirstMedia('multipleProperties');
$response = $this->patchJson("/mediaupload/{$media->id}", [
'properties' => [
'test' => 'new',
2023-03-07 23:14:11 +01:00
'missing' => 'value',
2023-03-07 23:11:35 +01:00
],
]);
$response->assertStatus(200);
$this->assertEquals('new', $media->fresh()->getCustomProperty('test'));
2023-03-07 23:14:11 +01:00
$this->assertEquals(null, $media->fresh()->getCustomProperty('missing'));
2023-03-07 23:11:35 +01:00
$response->assertJsonPath('properties.test', 'new');
2023-03-07 23:14:11 +01:00
$response->assertJsonMissingPath('properties.missing');
2023-03-07 23:11:35 +01:00
});
test('it validates a single files properties', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('multipleProperties');
$media = $post->getFirstMedia('multipleProperties');
$response = $this->patchJson("/mediaupload/{$media->id}", [
'properties' => [
'test' => 'new feswfewfwewefew wewe ew ewewf wefwfwefwefwefwewefewwedw sad fd',
],
]);
$response->assertStatus(422);
$response->assertJsonValidationErrors('properties.test');
});