mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
added it_delete_folder_with_their_content_within_softly and it_delete_folder_with_their_content_within_hardly test
This commit is contained in:
@@ -302,10 +302,14 @@ class Editor
|
||||
foreach ($files as $file) {
|
||||
|
||||
// Delete file
|
||||
Storage::delete('/files/' . $file->basename);
|
||||
Storage::delete("/files/$file->user_id/$file->basename");
|
||||
|
||||
// Delete thumbnail if exist
|
||||
if (!is_null($file->thumbnail)) Storage::delete('/files/' . $file->getRawOriginal('thumbnail'));
|
||||
if ($file->thumbnail) {
|
||||
Storage::delete(
|
||||
"/files/$file->user_id/{$file->getRawOriginal('thumbnail')}"
|
||||
);
|
||||
}
|
||||
|
||||
// Delete file permanently
|
||||
$file->forceDelete();
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Folder;
|
||||
use App\Models\User;
|
||||
use App\Services\SetupService;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
// TODO: pridat foldre do api skupiny
|
||||
@@ -14,6 +18,12 @@ class FolderTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setup = app()->make(SetupService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
@@ -261,21 +271,17 @@ class FolderTest extends TestCase
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertSoftDeleted('folders', [
|
||||
'id' => $folder_1->id,
|
||||
]);
|
||||
collect([$folder_1, $folder_2])
|
||||
->each(function ($folder) {
|
||||
|
||||
$this->assertSoftDeleted('folders', [
|
||||
'id' => $folder_2->id,
|
||||
]);
|
||||
$this->assertSoftDeleted('folders', [
|
||||
'id' => $folder->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('favourite_folder', [
|
||||
'folder_id' => $folder_1->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('favourite_folder', [
|
||||
'folder_id' => $folder_2->id,
|
||||
]);
|
||||
$this->assertDatabaseMissing('favourite_folder', [
|
||||
'folder_id' => $folder->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,14 +324,136 @@ class FolderTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_folder_with_their_content_within_softly()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$folder_root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
|
||||
$folder_children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $folder_root->id,
|
||||
]);
|
||||
|
||||
$file_1 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder_root->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file_2 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder_children->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this->postJson("/api/remove", [
|
||||
'items' => [
|
||||
[
|
||||
'id' => $folder_root->id,
|
||||
'type' => 'folder',
|
||||
'force_delete' => false,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
collect([$file_1, $file_2])
|
||||
->each(function ($file) {
|
||||
$this->assertSoftDeleted('files', [
|
||||
'id' => $file->id,
|
||||
]);
|
||||
});
|
||||
|
||||
collect([$folder_root, $folder_children])
|
||||
->each(function ($file) {
|
||||
$this->assertSoftDeleted('folders', [
|
||||
'id' => $file->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_folder_with_their_content_within_hardly()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$this->setup->create_directories();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$folder_root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
|
||||
$folder_children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $folder_root->id,
|
||||
]);
|
||||
|
||||
collect([$folder_root, $folder_children])
|
||||
->each(function ($folder, $index) {
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create("fake-file-$index.pdf", 1200, 'application/pdf');
|
||||
|
||||
$this->postJson('/api/upload', [
|
||||
'file' => $file,
|
||||
'folder_id' => $folder->id,
|
||||
'is_last' => true,
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
$uploaded_files = File::all();
|
||||
|
||||
collect([0, 1])
|
||||
->each(function ($index) use ($folder_root) {
|
||||
$this->postJson("/api/remove", [
|
||||
'items' => [
|
||||
[
|
||||
'id' => $folder_root->id,
|
||||
'type' => 'folder',
|
||||
'force_delete' => $index,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
});
|
||||
|
||||
$uploaded_files
|
||||
->each(function ($file, $index) use ($user) {
|
||||
|
||||
$this->assertDatabaseMissing('files', [
|
||||
'id' => $file->id,
|
||||
]);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertMissing(
|
||||
"files/$user->id/fake-file-$index.pdf"
|
||||
);
|
||||
});
|
||||
|
||||
collect([$folder_root, $folder_children])
|
||||
->each(function ($id) {
|
||||
$this->assertDatabaseMissing('folders', [
|
||||
'id' => $id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function it_zip_and_download_folder_with_content_within()
|
||||
|
||||
Reference in New Issue
Block a user