Mohammad Khazaee
2 years ago
3 changed files with 110 additions and 5 deletions
-
41tests/Feature/FileShowTest.php
-
22tests/Feature/Traits/FileImageTrait.php
-
52tests/Feature/Traits/FileShowTrait.php
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Traits; |
||||
|
|
||||
|
use App\Image\ImageProcessor; |
||||
|
use Illuminate\Support\Facades\Storage; |
||||
|
|
||||
|
trait FileImageTrait |
||||
|
{ |
||||
|
|
||||
|
public function createImageForModel(\App\Models\Collection $collection, \App\Models\File $file): void |
||||
|
{ |
||||
|
$imageProcessor = new ImageProcessor; |
||||
|
$imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $file->uuid . '.' . $collection->ext)); |
||||
|
} |
||||
|
|
||||
|
public function deleteFakeImageForModel(\App\Models\File $file): void |
||||
|
{ |
||||
|
unlink($file->getPath()); |
||||
|
unlink($file->getModifiedPath()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Traits; |
||||
|
|
||||
|
use App\Models\Collection; |
||||
|
use App\Models\File; |
||||
|
use Illuminate\Support\Facades\Validator; |
||||
|
use Illuminate\Validation\Rule; |
||||
|
|
||||
|
trait FileShowTrait |
||||
|
{ |
||||
|
use FileImageTrait; |
||||
|
public function dimensions(\Illuminate\Http\File $image, $minWidth, $minHeight, $maxWidth, $maxHeight, $maxSize, $minSize) : bool |
||||
|
{ |
||||
|
$data = [ |
||||
|
'image' => $image |
||||
|
]; |
||||
|
$validator = Validator::make($data, [ |
||||
|
'avatar' => [ |
||||
|
Rule::dimensions()->minWidth($minWidth)->minHeight($minHeight)->maxWidth($maxWidth)->maxHeight($maxHeight), |
||||
|
'max:' . $maxSize, |
||||
|
'min:' . $minSize |
||||
|
], |
||||
|
]); |
||||
|
|
||||
|
return !$validator->fails(); |
||||
|
} |
||||
|
|
||||
|
public function createCollectionAndFileModelWithImage() |
||||
|
{ |
||||
|
$collection = Collection::factory()->createQuietly([ |
||||
|
'alt_required' => false, |
||||
|
'description_required' => false, |
||||
|
'tmp_support' => true, |
||||
|
'max_width' => 2000, |
||||
|
'max_height' => 2000, |
||||
|
'min_width' => 1, |
||||
|
'min_height' => 1, |
||||
|
'min_file_size' => 0 |
||||
|
]); |
||||
|
$uuid = app()->uuid; |
||||
|
$file = File::factory()->createQuietly([ |
||||
|
'uuid' => $uuid, |
||||
|
'server_path' => '/' . date('y') . '/' . date('m') . '/', |
||||
|
'user_id' => auth()->id(), |
||||
|
'collection_id' => $collection->id |
||||
|
]); |
||||
|
$this->createImageForModel($collection,$file); |
||||
|
|
||||
|
return ['file' => $file ,'collection' => $collection]; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue