mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
added it_get_private_user_file, guest_try_to_get_private_user_file, logged_user_try_to_get_another_private_user_file test
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use App\Services\SetupService;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
@@ -59,4 +61,87 @@ class FileAccessTest extends TestCase
|
||||
|
||||
Storage::assertExists('system/fake-logo.jpg');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_private_user_file()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$this->setup->create_directories();
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create(Str::random() . '-fake-file.pdf', 1200, 'application/pdf');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson('/api/upload', [
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'is_last' => true,
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->get("file/$file->name")
|
||||
->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function guest_try_to_get_private_user_file()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$this->setup->create_directories();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create(Str::random() . '-fake-file.pdf', 1200, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $file, $file->name);
|
||||
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'basename' => $file->name,
|
||||
'name' => 'fake-file.pdf',
|
||||
]);
|
||||
|
||||
$this->get("file/$file->name")
|
||||
->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function logged_user_try_to_get_another_private_user_file()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$this->setup->create_directories();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create(Str::random() . '-fake-file.pdf', 1200, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $file, $file->name);
|
||||
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'basename' => $file->name,
|
||||
'name' => 'fake-file.pdf',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->get("file/$file->name")
|
||||
->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user