You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. <?php
  2. namespace Tests\Feature\Traits;
  3. use App\Models\Collection;
  4. use App\Models\File;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Validation\Rule;
  7. trait FileShowTrait
  8. {
  9. use FileImageTrait;
  10. public function dimensions(\Illuminate\Http\File $image, $minWidth, $minHeight, $maxWidth, $maxHeight, $maxSize, $minSize) : bool
  11. {
  12. $data = [
  13. 'image' => $image
  14. ];
  15. $validator = Validator::make($data, [
  16. 'avatar' => [
  17. Rule::dimensions()->minWidth($minWidth)->minHeight($minHeight)->maxWidth($maxWidth)->maxHeight($maxHeight),
  18. 'max:' . $maxSize,
  19. 'min:' . $minSize
  20. ],
  21. ]);
  22. return !$validator->fails();
  23. }
  24. public function createCollectionAndFileModelWithImage()
  25. {
  26. $collection = Collection::factory()->createQuietly([
  27. 'alt_required' => false,
  28. 'description_required' => false,
  29. 'tmp_support' => true,
  30. 'max_width' => 2000,
  31. 'max_height' => 2000,
  32. 'min_width' => 1,
  33. 'min_height' => 1,
  34. 'min_file_size' => 0
  35. ]);
  36. $uuid = app()->uuid;
  37. $file = File::factory()->createQuietly([
  38. 'uuid' => $uuid,
  39. 'server_path' => '/' . date('y') . '/' . date('m') . '/',
  40. 'user_id' => auth()->id(),
  41. 'collection_id' => $collection->id
  42. ]);
  43. $this->createImageForModel($collection,$file);
  44. return ['file' => $file ,'collection' => $collection];
  45. }
  46. }