54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?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');
|
|
}
|
|
}
|
|
|