40 lines
1.5 KiB
PHP
40 lines
1.5 KiB
PHP
<?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',
|
|
'missing' => 'value',
|
|
],
|
|
]);
|
|
|
|
$response->assertStatus(200);
|
|
$this->assertEquals('new', $media->fresh()->getCustomProperty('test'));
|
|
$this->assertEquals(null, $media->fresh()->getCustomProperty('missing'));
|
|
$response->assertJsonPath('properties.test', 'new');
|
|
$response->assertJsonMissingPath('properties.missing');
|
|
});
|
|
|
|
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');
|
|
});
|