mirror of
https://github.com/10h30/Test-Laravel-File-Upload.git
synced 2026-07-11 18:56:13 +09:00
Upload file to public disk
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\House;
|
||||
use App\Models\Office;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FileUploadTest extends TestCase
|
||||
@@ -74,4 +76,21 @@ class FileUploadTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
$response->assertDownload(str_replace('houses/', '', $house->photo));
|
||||
}
|
||||
|
||||
public function test_public_file_show()
|
||||
{
|
||||
$filename = Str::random(8) . '.jpg';
|
||||
|
||||
$this->post('offices', [
|
||||
'name' => 'Some name',
|
||||
'photo' => UploadedFile::fake()->image($filename)
|
||||
]);
|
||||
$office = Office::first();
|
||||
|
||||
$this->assertTrue(Storage::disk('public')->exists('offices/' . $filename));
|
||||
|
||||
$response = $this->get('offices/' . $office->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee(public_path('offices/' . $filename));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user