Upload file to public disk

This commit is contained in:
PovilasKorop
2021-12-06 11:07:06 +02:00
parent eb7cf686ea
commit 7233196e0c
7 changed files with 110 additions and 0 deletions
+19
View File
@@ -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));
}
}