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.

47 lines
1.6 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\TestCase;
  10. class FileRestoreTest extends TestCase
  11. {
  12. public function test_user_with_permission_can_not_restore_file()
  13. {
  14. $this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy");
  15. }
  16. public function test_user_with_permission_can_restore_file()
  17. {
  18. $collection = Collection::factory()->createQuietly([
  19. 'alt_required' => false,
  20. 'description_required' => false,
  21. 'tmp_support' => true,
  22. 'max_width' => 2000,
  23. 'max_height' => 2000,
  24. 'min_width' => 1,
  25. 'min_height' => 1,
  26. 'min_file_size' => 0
  27. ]);
  28. $uuid = app()->uuid;
  29. $file = File::factory()->createQuietly([
  30. 'uuid' => $uuid,
  31. 'server_path' => '/' . date('y') . '/' . date('m') . '/',
  32. 'user_id' => auth()->id(),
  33. 'collection_id' => $collection->id
  34. ]);
  35. $imageProcessor = new ImageProcessor;
  36. $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $uuid . '.' . $collection->ext));
  37. $file->delete();
  38. $response = $this->loginAs()->deleteJson(route('api.files.destroy', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext]));
  39. $response->assertok();
  40. }
  41. }