mirror of
https://github.com/10h30/Test-Laravel-File-Upload.git
synced 2026-06-05 15:07:47 +09:00
Last tasks
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\House;
|
||||
use App\Models\Office;
|
||||
use App\Models\Project;
|
||||
@@ -9,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FileUploadTest extends TestCase
|
||||
@@ -93,4 +95,35 @@ class FileUploadTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee(public_path('offices/' . $filename));
|
||||
}
|
||||
|
||||
public function test_upload_resize()
|
||||
{
|
||||
$filename = Str::random(8) . '.jpg';
|
||||
|
||||
$response = $this->post('shops', [
|
||||
'name' => 'Some name',
|
||||
'photo' => UploadedFile::fake()->image($filename, 1000, 1000)
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
|
||||
$image = Image::make(storage_path('app/shops/resized-' . $filename));
|
||||
$this->assertEquals(500, $image->width());
|
||||
$this->assertEquals(500, $image->height());
|
||||
}
|
||||
|
||||
public function test_spatie_media_library()
|
||||
{
|
||||
$filename = Str::random(8) . '.jpg';
|
||||
|
||||
$response = $this->post('companies', [
|
||||
'name' => 'Some name',
|
||||
'photo' => UploadedFile::fake()->image($filename)
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
|
||||
$company = Company::first();
|
||||
$response = $this->get('companies/' . $company->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('storage/' . $company->id . '/' . $filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user