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.

89 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace Tests\Feature\Traits;
  3. use Illuminate\Http\UploadedFile;
  4. trait FileTraits
  5. {
  6. private function defaultArray()
  7. {
  8. return [
  9. [
  10. 'alt_required' => false,
  11. 'description_required' => false,
  12. 'tmp_support' => true,
  13. 'max_width' => 2000,
  14. 'max_height' => 2000,
  15. 'min_width' => 1,
  16. 'min_height' => 1,
  17. 'min_file_size' => 0
  18. ],
  19. [
  20. "file" => UploadedFile::fake()->image('test.png', 400, 400),
  21. "public" => 1
  22. ]
  23. ];
  24. }
  25. private function defaultArrayForUpdate()
  26. {
  27. return [
  28. [
  29. 'alt_required' => false,
  30. 'description_required' => false,
  31. 'tmp_support' => true,
  32. 'max_width' => 2000,
  33. 'max_height' => 2000,
  34. 'min_width' => 1,
  35. 'min_height' => 1,
  36. 'min_file_size' => 0
  37. ]
  38. ];
  39. }
  40. private function changeDefaultArrayAndReturn($defaultArray, $key, $value): array
  41. {
  42. $defaultArray[$key[0]][$key[1]] = $value;
  43. return $defaultArray;
  44. }
  45. public function storeValidationTestProvider()
  46. {
  47. $data = [
  48. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'alt_required'], true),
  49. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'description_required'], true),
  50. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'max_width'], 2),
  51. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'max_height'], 2),
  52. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'min_width'], 1500),
  53. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'min_height'], 1500),
  54. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'min_file_size'], 1000),
  55. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'max_file_size'], 0),
  56. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'exts'], ['jpg']),
  57. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'mimetypes'], ['image/jpg']),
  58. ];
  59. return $data;
  60. }
  61. public function storeValidationWithUuidTestProvider()
  62. {
  63. $data = [
  64. $this->changeDefaultArrayAndReturn($this->defaultArray(), [0, 'alt_required'], true),
  65. ];
  66. return $data;
  67. }
  68. public function updateValidationTestProvider()
  69. {
  70. $data = [
  71. $this->changeDefaultArrayAndReturn($this->defaultArrayForUpdate(), [0, 'alt_required'], true),
  72. $this->changeDefaultArrayAndReturn($this->defaultArrayForUpdate(), [0, 'description_required'], true),
  73. ];
  74. return $data;
  75. }
  76. }