add temporary file manager

This commit is contained in:
2026-02-19 19:47:42 +03:00
parent cf635f81dd
commit ad4a3367c3
9 changed files with 256 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
<?php
namespace Tests\Feature;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class FileLinkControllerTest extends TestCase
{
public function test_upload_is_unavailable_when_feature_is_disabled(): void
{
Config::set('file_links.enabled', false);
$response = $this->postJson('/api/files/upload', [
'file' => UploadedFile::fake()->create('sample.txt', 1),
]);
$response->assertNotFound();
}
public function test_it_uploads_file_and_downloads_it_via_temporary_signed_link(): void
{
Storage::fake('local');
Config::set('file_links.enabled', true);
Config::set('file_links.disk', 'local');
Config::set('file_links.directory', 'temporary-links');
$response = $this->postJson('/api/files/upload', [
'file' => UploadedFile::fake()->create('sample.txt', 1),
]);
$response->assertOk();
$response->assertJsonStructure(['path', 'expiresAt', 'url']);
$path = $response->json('path');
Storage::disk('local')->assertExists($path);
$url = $response->json('url');
$parts = parse_url($url);
$routePath = $parts['path'];
if (isset($parts['query'])) {
$routePath .= '?' . $parts['query'];
}
$downloadResponse = $this->get($routePath);
$downloadResponse->assertOk();
$downloadResponse->assertHeader('content-disposition');
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Feature;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class FileLinkWebTest extends TestCase
{
public function test_files_page_shows_disabled_state(): void
{
Config::set('file_links.enabled', false);
$response = $this->get('/files');
$response->assertOk();
$response->assertSee('Функция отключена конфигом');
}
public function test_it_uploads_file_from_web_form_and_returns_temporary_link(): void
{
Storage::fake('local');
Config::set('file_links.enabled', true);
Config::set('file_links.disk', 'local');
Config::set('file_links.directory', 'temporary-links');
$response = $this->post('/files', [
'file' => UploadedFile::fake()->create('web-sample.txt', 1),
]);
$response->assertRedirect('/files');
$response->assertSessionHas('file_link');
$response->assertSessionHas('file_expires_at');
}
}