mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
- gate implementation
- protected shared view fix
This commit is contained in:
@@ -92,7 +92,7 @@ class PersonalAccessTokenTest extends TestCase
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
|
||||
$token = $user->createToken('token')->plainTextToken;
|
||||
|
||||
@@ -33,7 +33,7 @@ class UserAccountTest extends TestCase
|
||||
->assertExists('files/' . User::first()->id);
|
||||
}
|
||||
/**
|
||||
* @test
|
||||
* todo: finish test
|
||||
*/
|
||||
public function it_test_user_timezone()
|
||||
{
|
||||
|
||||
@@ -277,7 +277,7 @@ class AdminTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
@@ -60,8 +60,9 @@ class BrowseTest extends TestCase
|
||||
->assertStatus(200)
|
||||
->assertExactJson([
|
||||
[
|
||||
'name' => 'Files',
|
||||
'folders' => [
|
||||
'location' => 'files',
|
||||
'name' => 'Files',
|
||||
'folders' => [
|
||||
[
|
||||
'id' => $folder_level_1->id,
|
||||
'parent_id' => null,
|
||||
@@ -108,10 +109,13 @@ class BrowseTest extends TestCase
|
||||
],
|
||||
],
|
||||
],
|
||||
'isMovable' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'Team Folders',
|
||||
'folders' => [],
|
||||
'location' => 'team-folders',
|
||||
'name' => 'Team Folders',
|
||||
'folders' => [],
|
||||
'isMovable' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -140,7 +144,7 @@ class BrowseTest extends TestCase
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $root->id,
|
||||
'parent_id' => $root->id,
|
||||
'name' => 'Document',
|
||||
'basename' => 'document.pdf',
|
||||
'mimetype' => 'application/pdf',
|
||||
@@ -180,7 +184,7 @@ class BrowseTest extends TestCase
|
||||
|
||||
$file_1 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $root->id,
|
||||
'parent_id' => $root->id,
|
||||
'name' => 'Document 1',
|
||||
'basename' => 'document-1.pdf',
|
||||
'mimetype' => 'application/pdf',
|
||||
@@ -194,7 +198,7 @@ class BrowseTest extends TestCase
|
||||
|
||||
$file_2 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $root->id,
|
||||
'parent_id' => $root->id,
|
||||
'name' => 'Document 2',
|
||||
'basename' => 'document-2.pdf',
|
||||
'mimetype' => 'application/pdf',
|
||||
@@ -235,7 +239,7 @@ class BrowseTest extends TestCase
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'name' => 'Document',
|
||||
'basename' => 'document.pdf',
|
||||
'mimetype' => 'application/pdf',
|
||||
@@ -247,7 +251,7 @@ class BrowseTest extends TestCase
|
||||
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
'deleted_at' => now(),
|
||||
]);
|
||||
|
||||
@@ -41,7 +41,7 @@ class FileTest extends TestCase
|
||||
->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
@@ -76,7 +76,7 @@ class FileTest extends TestCase
|
||||
->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
@@ -122,7 +122,7 @@ class FileTest extends TestCase
|
||||
->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(423);
|
||||
|
||||
@@ -151,7 +151,7 @@ class FileTest extends TestCase
|
||||
->actingAs($user)
|
||||
->postJson('/api/upload', [
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(422);
|
||||
|
||||
@@ -164,12 +164,14 @@ class FileTest extends TestCase
|
||||
*/
|
||||
public function it_rename_file()
|
||||
{
|
||||
$file = File::factory(File::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/rename/{$file->id}", [
|
||||
@@ -191,15 +193,19 @@ class FileTest extends TestCase
|
||||
*/
|
||||
public function it_move_file_to_another_folder()
|
||||
{
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/move', [
|
||||
@@ -214,7 +220,7 @@ class FileTest extends TestCase
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'id' => $file->id,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -228,7 +234,9 @@ class FileTest extends TestCase
|
||||
|
||||
$files = File::factory(File::class)
|
||||
->count(2)
|
||||
->create();
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
@@ -273,7 +281,7 @@ class FileTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ class FavouriteFolderTest extends TestCase
|
||||
|
||||
$this->assertDatabaseHas('favourite_folder', [
|
||||
'user_id' => $user->id,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class FavouriteFolderTest extends TestCase
|
||||
|
||||
$this->assertDatabaseMissing('favourite_folder', [
|
||||
'user_id' => $user->id,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,12 +53,14 @@ class FolderTest extends TestCase
|
||||
*/
|
||||
public function it_rename_folder()
|
||||
{
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/rename/{$folder->id}", [
|
||||
@@ -80,12 +82,14 @@ class FolderTest extends TestCase
|
||||
*/
|
||||
public function it_set_folder_emoji()
|
||||
{
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$emoji_fragment = [
|
||||
'category' => 'Smileys & Emotion (face-smiling)',
|
||||
'char' => '😁',
|
||||
@@ -116,12 +120,14 @@ class FolderTest extends TestCase
|
||||
*/
|
||||
public function it_set_folder_color()
|
||||
{
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/rename/{$folder->id}", [
|
||||
@@ -147,15 +153,19 @@ class FolderTest extends TestCase
|
||||
*/
|
||||
public function it_move_folder_to_another_folder()
|
||||
{
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/move', [
|
||||
@@ -183,10 +193,14 @@ class FolderTest extends TestCase
|
||||
->create();
|
||||
|
||||
$folder_1 = Folder::factory(Folder::class)
|
||||
->create();
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder_2 = Folder::factory(Folder::class)
|
||||
->create();
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$user->favouriteFolders()->attach($folder_1->id);
|
||||
$user->favouriteFolders()->attach($folder_2->id);
|
||||
@@ -215,7 +229,7 @@ class FolderTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('favourite_folder', [
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
@@ -229,10 +243,14 @@ class FolderTest extends TestCase
|
||||
->create();
|
||||
|
||||
$folder_1 = Folder::factory(Folder::class)
|
||||
->create();
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder_2 = Folder::factory(Folder::class)
|
||||
->create();
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
@@ -281,13 +299,13 @@ class FolderTest extends TestCase
|
||||
|
||||
$file_1 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder_root->id,
|
||||
'parent_id' => $folder_root->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file_2 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder_children->id,
|
||||
'parent_id' => $folder_children->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
@@ -347,7 +365,7 @@ class FolderTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Domain\Sharing;
|
||||
|
||||
use Storage;
|
||||
@@ -53,7 +54,7 @@ class VisitorAccessToItemsTest extends TestCase
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
if (! $is_protected) {
|
||||
if (!$is_protected) {
|
||||
// Get shared file
|
||||
$this->get("/file/$document->name/$share->token")
|
||||
->assertStatus(200);
|
||||
@@ -66,10 +67,21 @@ class VisitorAccessToItemsTest extends TestCase
|
||||
*/
|
||||
public function it_try_to_get_protected_file_record()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'name' => 'fake-thumbnail.jpg',
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'type' => 'file',
|
||||
'is_protected' => true,
|
||||
'user_id' => $user->id,
|
||||
'item_id' => $file->id,
|
||||
]);
|
||||
|
||||
// Get share record
|
||||
@@ -123,7 +135,7 @@ class VisitorAccessToItemsTest extends TestCase
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
if (! $is_protected) {
|
||||
if (!$is_protected) {
|
||||
$this->get("/share/$share->token")
|
||||
->assertStatus(200);
|
||||
}
|
||||
@@ -174,7 +186,7 @@ class VisitorAccessToItemsTest extends TestCase
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
if (! $is_protected) {
|
||||
if (!$is_protected) {
|
||||
$this->get("/thumbnail/$thumbnail->name/$share->token")
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Domain\Sharing;
|
||||
|
||||
use Tests\TestCase;
|
||||
@@ -160,7 +159,7 @@ class VisitorBrowseTest extends TestCase
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $root->id,
|
||||
'parent_id' => $root->id,
|
||||
'name' => 'Document',
|
||||
'basename' => 'document.pdf',
|
||||
'mimetype' => 'application/pdf',
|
||||
@@ -189,7 +188,7 @@ class VisitorBrowseTest extends TestCase
|
||||
}
|
||||
|
||||
// Check public shared item
|
||||
if (!$is_protected) {
|
||||
if (! $is_protected) {
|
||||
$this->getJson("/api/browse/folders/$root->id/$share->token")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
@@ -304,7 +303,7 @@ class VisitorBrowseTest extends TestCase
|
||||
}
|
||||
|
||||
// Check public shared item
|
||||
if (!$is_protected) {
|
||||
if (! $is_protected) {
|
||||
$this->getJson("/api/browse/navigation/$share->token")
|
||||
->assertStatus(200)
|
||||
->assertExactJson($tree);
|
||||
@@ -336,7 +335,7 @@ class VisitorBrowseTest extends TestCase
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'name' => 'Document',
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $folder->user_id,
|
||||
]);
|
||||
|
||||
@@ -356,7 +355,7 @@ class VisitorBrowseTest extends TestCase
|
||||
}
|
||||
|
||||
// Check public shared item
|
||||
if (!$is_protected) {
|
||||
if (! $is_protected) {
|
||||
$this->getJson("/api/browse/search/$share->token?query=doc")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
@@ -407,7 +406,7 @@ class VisitorBrowseTest extends TestCase
|
||||
}
|
||||
|
||||
// Check public shared item
|
||||
if (!$is_protected) {
|
||||
if (! $is_protected) {
|
||||
$this->getJson("/api/browse/search/$share->token?query=doc")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([]);
|
||||
@@ -454,7 +453,7 @@ class VisitorBrowseTest extends TestCase
|
||||
}
|
||||
|
||||
// Check public shared item
|
||||
if (!$is_protected) {
|
||||
if (! $is_protected) {
|
||||
$this->getJson("/api/browse/file/$share->token")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
|
||||
@@ -29,7 +29,8 @@ class VisitorManipulatingTest extends TestCase
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
@@ -240,7 +241,8 @@ class VisitorManipulatingTest extends TestCase
|
||||
$files = File::factory(File::class)
|
||||
->count(2)
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
@@ -327,7 +329,7 @@ class VisitorManipulatingTest extends TestCase
|
||||
->post("/api/editor/upload/$share->token", [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
}
|
||||
@@ -337,7 +339,7 @@ class VisitorManipulatingTest extends TestCase
|
||||
$this->postJson("/api/editor/upload/$share->token", [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
}
|
||||
@@ -378,7 +380,7 @@ class VisitorManipulatingTest extends TestCase
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'folder_id' => $root->id,
|
||||
'parent_id' => $root->id,
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
@@ -421,7 +423,7 @@ class VisitorManipulatingTest extends TestCase
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'id' => $file->id,
|
||||
'folder_id' => $children->id,
|
||||
'parent_id' => $children->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Domain\Spotlight;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SearchTest extends TestCase
|
||||
{
|
||||
@@ -36,14 +35,15 @@ class SearchTest extends TestCase
|
||||
]);
|
||||
|
||||
collect([$english, $russian, $turkish])
|
||||
->each(fn($file) => $this
|
||||
->actingAs($user)
|
||||
->getJson('/api/browse/search?query=' . mb_strtolower(mb_substr($file->name, 0, 3)))
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'id' => $file->id,
|
||||
'name' => $file->name,
|
||||
])
|
||||
->each(
|
||||
fn ($file) => $this
|
||||
->actingAs($user)
|
||||
->getJson('/api/browse/search?query=' . mb_strtolower(mb_substr($file->name, 0, 3)))
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'id' => $file->id,
|
||||
'name' => $file->name,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,4 +69,4 @@ class SearchTest extends TestCase
|
||||
'id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class TeamsTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_find_team_folder_id_from_children()
|
||||
public function it_find_team_parent_id_from_children()
|
||||
{
|
||||
$teamFolder = Folder::factory()
|
||||
->create([
|
||||
@@ -140,7 +140,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'email' => $member->email,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
@@ -153,11 +153,11 @@ class TeamsTest extends TestCase
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'accepted',
|
||||
])
|
||||
->assertDatabaseHas('team_folder_members', [
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
@@ -178,7 +178,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'email' => $member->email,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
@@ -191,11 +191,11 @@ class TeamsTest extends TestCase
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'rejected',
|
||||
])
|
||||
->assertDatabaseMissing('team_folder_members', [
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
]);
|
||||
}
|
||||
@@ -220,7 +220,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
'email' => 'existing@member.com',
|
||||
@@ -229,12 +229,12 @@ class TeamsTest extends TestCase
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[0]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[1]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
@@ -299,7 +299,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
'email' => 'deleted@member.com',
|
||||
@@ -307,7 +307,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
'email' => 'existing@member.com',
|
||||
@@ -316,12 +316,12 @@ class TeamsTest extends TestCase
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[0]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[1]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
@@ -379,12 +379,12 @@ class TeamsTest extends TestCase
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[0]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[1]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
@@ -426,7 +426,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-view',
|
||||
'email' => 'existing@member.com',
|
||||
@@ -478,12 +478,12 @@ class TeamsTest extends TestCase
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[0]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[1]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
@@ -532,7 +532,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
@@ -540,12 +540,12 @@ class TeamsTest extends TestCase
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[0]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $members[1]->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
@@ -600,7 +600,7 @@ class TeamsTest extends TestCase
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
@@ -634,12 +634,12 @@ class TeamsTest extends TestCase
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'folder_id' => $folders[0]->id,
|
||||
'parent_id' => $folders[0]->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'folder_id' => $folders[1]->id,
|
||||
'parent_id' => $folders[1]->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
|
||||
@@ -36,7 +36,7 @@ class TrafficTest extends TestCase
|
||||
->postJson('/api/upload', [
|
||||
'filename' => $this->file->name,
|
||||
'file' => $this->file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
@@ -56,7 +56,7 @@ class TrafficTest extends TestCase
|
||||
->postJson('/api/upload', [
|
||||
'filename' => $this->file->name,
|
||||
'file' => $this->file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
@@ -76,7 +76,7 @@ class TrafficTest extends TestCase
|
||||
->postJson('/api/upload', [
|
||||
'filename' => $secondFile->name,
|
||||
'file' => $secondFile,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
@@ -113,7 +113,7 @@ class TrafficTest extends TestCase
|
||||
$this->postJson("/api/editor/upload/$share->token", [
|
||||
'filename' => $this->file->name,
|
||||
'file' => $this->file,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class TrashTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $image->name,
|
||||
'file' => $image,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class SharedZippingTest extends TestCase
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'filesize' => $file->getSize(),
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
'basename' => $file->name,
|
||||
'name' => "fake-file-$index.pdf",
|
||||
@@ -61,7 +61,7 @@ class SharedZippingTest extends TestCase
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'filesize' => $file->getSize(),
|
||||
'folder_id' => $sharedFolder->id,
|
||||
'parent_id' => $sharedFolder->id,
|
||||
'user_id' => $user->id,
|
||||
'basename' => $file->name,
|
||||
'name' => "fake-file-$index.pdf",
|
||||
@@ -122,7 +122,7 @@ class SharedZippingTest extends TestCase
|
||||
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
@@ -199,7 +199,7 @@ class SharedZippingTest extends TestCase
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'filesize' => $file->getSize(),
|
||||
'folder_id' => $children->id,
|
||||
'parent_id' => $children->id,
|
||||
'user_id' => $user->id,
|
||||
'basename' => $file->name,
|
||||
'name' => "fake-file-$index.pdf",
|
||||
|
||||
@@ -33,7 +33,7 @@ class UserZippingTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
@@ -46,13 +46,13 @@ class UserZippingTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => null,
|
||||
'parent_id' => null,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
$files = File::all()
|
||||
->where('folder_id', null)
|
||||
->where('parent_id', null)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
@@ -85,7 +85,7 @@ class UserZippingTest extends TestCase
|
||||
$this->postJson('/api/upload', [
|
||||
'filename' => $file->name,
|
||||
'file' => $file,
|
||||
'folder_id' => $folder->id,
|
||||
'parent_id' => $folder->id,
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
259
tests/Support/Gate/GateTest.php
Normal file
259
tests/Support/Gate/GateTest.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
namespace Tests\Support\Gate;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GateTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function owner_rename_folder()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/rename/{$folder->id}", [
|
||||
'name' => 'Renamed Folder',
|
||||
'type' => 'folder',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function guest_rename_folder()
|
||||
{
|
||||
// check private or public share record
|
||||
collect([true, false])
|
||||
->each(function ($is_protected) {
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $root->id,
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'item_id' => $root->id,
|
||||
'user_id' => $user->id,
|
||||
'type' => 'folder',
|
||||
'is_protected' => $is_protected,
|
||||
'permission' => 'editor',
|
||||
]);
|
||||
|
||||
// Check shared item protected by password
|
||||
if ($is_protected) {
|
||||
$cookie = ['share_session' => json_encode([
|
||||
'token' => $share->token,
|
||||
'authenticated' => true,
|
||||
])];
|
||||
|
||||
$this
|
||||
->withUnencryptedCookies($cookie)
|
||||
->patch("/api/editor/rename/{$children->id}/$share->token", [
|
||||
'name' => 'Renamed Folder',
|
||||
'type' => 'folder',
|
||||
])
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
}
|
||||
|
||||
// Check public shared item
|
||||
if (! $is_protected) {
|
||||
$this->patchJson("/api/editor/rename/{$children->id}/$share->token", [
|
||||
'name' => 'Renamed Folder',
|
||||
'type' => 'folder',
|
||||
])
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'name' => 'Renamed Folder',
|
||||
'id' => $children->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function team_member_with_can_edit_privilege_rename_folder()
|
||||
{
|
||||
$owner = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$member = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$teamFolder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'team_folder' => 1,
|
||||
'name' => 'Team Folder',
|
||||
]);
|
||||
|
||||
$parent = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $teamFolder->id,
|
||||
]);
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $parent->id,
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $teamFolder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->patchJson("/api/rename/{$children->id}", [
|
||||
'name' => 'Renamed Folder',
|
||||
'type' => 'folder',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function team_member_with_can_visit_privilege_try_rename_folder()
|
||||
{
|
||||
$owner = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$member = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$teamFolder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'team_folder' => 1,
|
||||
'name' => 'Team Folder',
|
||||
]);
|
||||
|
||||
$parent = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $teamFolder->id,
|
||||
]);
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $parent->id,
|
||||
'name' => 'Captivating',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $teamFolder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->patchJson("/api/rename/{$children->id}", [
|
||||
'name' => 'Renamed Folder',
|
||||
'type' => 'folder',
|
||||
])
|
||||
->assertStatus(403);
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'name' => 'Captivating',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function team_member_rename_file()
|
||||
{
|
||||
$owner = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$member = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$teamFolder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'team_folder' => 1,
|
||||
'name' => 'Team Folder',
|
||||
]);
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $teamFolder->id,
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $teamFolder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->patchJson("/api/rename/{$file->id}", [
|
||||
'name' => 'Renamed File',
|
||||
'type' => 'file',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed File',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user