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.

51 lines
2.1 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\FileImageTrait;
  10. use Tests\Feature\Traits\FileShowTrait;
  11. use Tests\TestCase;
  12. class FileShowTest extends TestCase
  13. {
  14. use FileShowTrait, FileImageTrait;
  15. public function test_user_can_resize_image_with_width_and_height_fields_ok()
  16. {
  17. $models = $this->createCollectionAndFileModelWithImage();
  18. $w = rand(10, 2000);
  19. $h = rand(10, 2000);
  20. $canv = rand(0, 1);
  21. $response = $this->loginAs()->getJson(route('api.files.show', ['collection_name' => $models['collection']->name, 'uuid' => $models['file']->uuid, 'extention' => $models['collection']->ext, 'w' => $w, 'h' => $h, 'canv' => $canv]));
  22. $response->assertOk()->assertHeader('content-type', $response->headers->get('content-type'));
  23. $this->assertEquals($w, getimagesize($response->getFile()->getPathname())[0]);
  24. $this->assertEquals($h, getimagesize($response->getFile()->getPathname())[1]);
  25. $this->deleteFakeImageForModel($models['file']);
  26. }
  27. /**
  28. * @testWith ["test", 4,'1:fgvjjf']
  29. * ["longer-string", 13,'1:fgvjjf']
  30. */
  31. public function test_user_send_not_currect_value_to_file($w, $h, $r)
  32. {
  33. $models = $this->createCollectionAndFileModelWithImage();
  34. $canv = rand(0, 1);
  35. $response = $this->loginAs()->getJson(route('api.files.show', ['collection_name' => $models['collection']->name, 'uuid' => $models['file']->uuid, 'extention' => $models['collection']->ext, 'w' => $w, 'h' => $h, 'canv' => $canv]));
  36. $response->assertOk()->assertHeader('content-type', $response->headers->get('content-type'));
  37. $this->assertNotEquals($w, getimagesize($response->getFile()->getPathname())[0]);
  38. $this->assertNotEquals($h, getimagesize($response->getFile()->getPathname())[1]);
  39. $this->deleteFakeImageForModel($models['file']);
  40. }
  41. }