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.

82 lines
3.0 KiB

  1. <?php
  2. namespace Tests\Feature;
  3. use App\Image\ImageProcessor;
  4. use App\Models\Collection;
  5. use App\Models\File;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Foundation\Testing\WithFaker;
  8. use Illuminate\Support\Facades\Storage;
  9. use Tests\Feature\Traits\FileTraits;
  10. use Tests\TestCase;
  11. class FileUpdateTest extends TestCase
  12. {
  13. use FileTraits;
  14. public function test_user_can_not_access_update_without_permission()
  15. {
  16. $this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy");
  17. }
  18. public function test_user_update_not_exits_files_not_found()
  19. {
  20. $data = [
  21. "original_name" => 'original name is very bad',
  22. "description" => 'this is a description for file and has beed updated',
  23. ];
  24. $response = $this->loginAs()->putJson(route('api.files.update', ['collection_name' => 'not_exits', 'uuid' => app()->uuid, 'extention' => 'jpg']), $data);
  25. $response->assertNotFound();
  26. }
  27. // /**
  28. // * @dataProvider updateValidationTestProvider
  29. // */
  30. // public function test_user_send_unproccable_fileds($collectionFields, $dataFields)
  31. // {
  32. // $collection = Collection::factory()->create($collectionFields);
  33. // $uuid = app()->uuid;
  34. // $file = File::factory()->createQuietly([
  35. // 'uuid' => $uuid,
  36. // 'server_path' => '/' . date('y') . '/' . date('m') . '/',
  37. // 'user_id' => auth()->id(),
  38. // 'collection_id' => $collection->id
  39. // ]);
  40. // $response = $this->loginAs()->postJson(route('api.files.update', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'ext' => $collection->ext]), $dataFields);
  41. // $response->assertUnprocessable();
  42. // }
  43. public function test_user_can_update_file()
  44. {
  45. $collection = Collection::factory()->createQuietly([
  46. 'alt_required' => false,
  47. 'description_required' => false,
  48. 'tmp_support' => true,
  49. 'max_width' => 2000,
  50. 'max_height' => 2000,
  51. 'min_width' => 1,
  52. 'min_height' => 1,
  53. 'min_file_size' => 0
  54. ]);
  55. $uuid = app()->uuid;
  56. $file = File::factory()->createQuietly([
  57. 'uuid' => $uuid,
  58. 'server_path' => '/' . date('y') . '/' . date('m') . '/',
  59. 'user_id' => auth()->id(),
  60. 'collection_id' => $collection->id
  61. ]);
  62. $imageProcessor = new ImageProcessor;
  63. $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $uuid . '.' . $collection->ext));
  64. $data = [
  65. "original_name" => 'original name is very bad',
  66. "description" => 'this is a description for file and has beed updated',
  67. ];
  68. $response = $this->loginAs()->putJson(route('api.files.update', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext]), $data);
  69. $response->assertok()->assertJson(['data' => $data]);
  70. }
  71. }