Compare commits
No commits in common. "820a7255176a2ffdfed011877cebce3644688d35" and "cfb38ed792b37a8193f1ce5773b67c5ebb001a9b" have entirely different histories.
820a725517
...
cfb38ed792
|
@ -35,12 +35,5 @@
|
|||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Zoomyboy\\MedialibraryHelper\\ServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,7 +48,7 @@ class MediaController
|
|||
$medias = collect($content)->map(function ($c) use ($collection, $model) {
|
||||
$pathinfo = pathinfo($c['name']);
|
||||
$basename = $collection->runCallback('forceFileName', $model, $pathinfo['filename']);
|
||||
$path = $basename . '.' . $pathinfo['extension'];
|
||||
$path = $basename.'.'.$pathinfo['extension'];
|
||||
|
||||
$adder = $this->fileAdderFromData($model, $c['content'], $collection)
|
||||
->usingName($basename)
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\MedialibraryHelper\Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Zoomyboy\MedialibraryHelper\Tests\TestCase;
|
||||
|
||||
class MiddlewareTest extends TestCase
|
||||
{
|
||||
|
||||
use RefreshDatabase;
|
||||
|
||||
public function testItReturns401WhenNotLoggedIn(): void
|
||||
{
|
||||
$this->registerModel();
|
||||
$post = $this->newPost();
|
||||
|
||||
$response = $this->postJson('/mediaupload', [
|
||||
'model' => 'post',
|
||||
'id' => $post->id,
|
||||
'collection' => 'defaultSingleFile',
|
||||
'content' => base64_encode($this->pdfFile()->getContent()),
|
||||
'name' => 'beispiel bild.jpg',
|
||||
]);
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
public function testItReturns401WhenDestroying(): void
|
||||
{
|
||||
$this->registerModel();
|
||||
$post = $this->newPost();
|
||||
$media = $post->addMedia($this->pdfFile()->getPathname())->toMediaCollection('defaultSingleFile');
|
||||
|
||||
$response = $this->deleteJson("/mediaupload/{$media->id}");
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
protected function defineEnvironment($app)
|
||||
{
|
||||
$app['config']->set('media-library.middleware', ['web', 'auth:web']);
|
||||
}
|
||||
}
|
|
@ -233,14 +233,14 @@ test('it returns 403 when not authorized', function () {
|
|||
$post = $this->newPost();
|
||||
|
||||
$response = $this->postJson('/mediaupload', [
|
||||
'model' => 'post',
|
||||
'id' => $post->id,
|
||||
'collection' => 'defaultSingleFile',
|
||||
'payload' => [
|
||||
'content' => base64_encode($this->pdfFile()->getContent()),
|
||||
'name' => 'beispiel bild.jpg',
|
||||
],
|
||||
]);
|
||||
'model' => 'post',
|
||||
'id' => $post->id,
|
||||
'collection' => 'defaultSingleFile',
|
||||
'payload' => [
|
||||
'content' => base64_encode($this->pdfFile()->getContent()),
|
||||
'name' => 'beispiel bild.jpg',
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(403);
|
||||
});
|
||||
|
|
|
@ -23,20 +23,20 @@ class Post extends Model implements HasMedia
|
|||
$this->addMediaCollection('defaultSingleFile')->maxWidth(fn () => 250)->singleFile();
|
||||
|
||||
$this->addMediaCollection('conversionsWithDefault')
|
||||
->singleFile()
|
||||
->withFallback(fn ($parent) => ['default.jpg', 'public'])
|
||||
->registerMediaConversions(function () {
|
||||
$this->addMediaConversion('tiny')->width(200)->height(200);
|
||||
});
|
||||
->singleFile()
|
||||
->withFallback(fn ($parent) => ['default.jpg', 'public'])
|
||||
->registerMediaConversions(function () {
|
||||
$this->addMediaConversion('tiny')->width(200)->height(200);
|
||||
});
|
||||
|
||||
$this->addMediaCollection('images')->after(fn ($model) => Event::dispatch(new MediaChange($model)));
|
||||
|
||||
$this->addMediaCollection('singleForced')->singleFile()->forceFileName(function ($model, $name) {
|
||||
return $name . ' ' . now()->format('Y-m-d');
|
||||
return $name.' '.now()->format('Y-m-d');
|
||||
});
|
||||
|
||||
$this->addMediaCollection('multipleForced')->forceFileName(function ($model, $name) {
|
||||
return $name . ' ' . now()->format('Y-m-d');
|
||||
return $name.' '.now()->format('Y-m-d');
|
||||
});
|
||||
|
||||
$this->addMediaCollection('singleStoringHook')->singleFile()->storing(function ($adder, $fileName) {
|
||||
|
@ -49,8 +49,8 @@ class Post extends Model implements HasMedia
|
|||
$this->addMediaCollection('singleWithEvent')->singleFile()->stored(function (Media $media) {
|
||||
Event::dispatch(new MediaStored($media));
|
||||
})
|
||||
->destroyed(fn ($model) => Event::dispatch(new MediaDestroyed($model)))
|
||||
->after(fn ($model) => Event::dispatch(new MediaChange($model)));
|
||||
->destroyed(fn ($model) => Event::dispatch(new MediaDestroyed($model)))
|
||||
->after(fn ($model) => Event::dispatch(new MediaChange($model)));
|
||||
|
||||
$this->addMediaCollection('multipleFilesWithEvent')->stored(function (Media $media) {
|
||||
Event::dispatch(new MediaStored($media));
|
||||
|
@ -61,6 +61,6 @@ class Post extends Model implements HasMedia
|
|||
])->withPropertyValidation(fn ($path) => [
|
||||
'test' => 'string|max:10',
|
||||
])
|
||||
->after(fn ($model) => Event::dispatch(new MediaChange($model)));
|
||||
->after(fn ($model) => Event::dispatch(new MediaChange($model)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestCase extends BaseTestCase
|
|||
*/
|
||||
protected function defineDatabaseMigrations(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(__DIR__ . '/migrations');
|
||||
$this->loadMigrationsFrom(__DIR__.'/migrations');
|
||||
}
|
||||
|
||||
protected function getPackageProviders($app): array
|
||||
|
@ -44,8 +44,8 @@ class TestCase extends BaseTestCase
|
|||
|
||||
protected function getFile(string $location, string $as): File
|
||||
{
|
||||
$path = __DIR__ . '/stubs/' . $location;
|
||||
$to = sys_get_temp_dir() . '/' . $as;
|
||||
$path = __DIR__.'/stubs/'.$location;
|
||||
$to = sys_get_temp_dir().'/'.$as;
|
||||
copy($path, $to);
|
||||
|
||||
return new File($to);
|
||||
|
|
Loading…
Reference in New Issue