namespaces refactoring

This commit is contained in:
Peter Papp
2021-07-18 17:21:37 +02:00
parent a1778eab52
commit 8f77a497b5
162 changed files with 1242 additions and 1418 deletions

View File

@@ -1,14 +1,13 @@
<?php
namespace Tests\Domain\Sharing;
use Domain\Settings\Models\File;
use Domain\Settings\Models\Folder;
use Domain\Settings\Models\User;
use App\Notifications\SharedSendViaEmail;
use Illuminate\Support\Facades\Notification;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
use Laravel\Sanctum\Sanctum;
use Domain\Settings\Models\File;
use Domain\Settings\Models\User;
use Domain\Settings\Models\Folder;
use Illuminate\Support\Facades\Notification;
use Domain\Sharing\Notifications\SharedSendViaEmail;
class UserShareTest extends TestCase
{
@@ -26,13 +25,13 @@ class UserShareTest extends TestCase
$this
->actingAs($user)
->postJson("/api/share/$file->id", [
'isPassword' => false,
'permission' => 'editor',
'type' => 'file',
])->assertStatus(201)->assertJsonFragment([
'item_id' => $file->id,
'type' => 'file',
]);
'isPassword' => false,
'permission' => 'editor',
'type' => 'file',
])->assertStatus(201)->assertJsonFragment([
'item_id' => $file->id,
'type' => 'file',
]);
$this->assertDatabaseHas('shares', [
'user_id' => $user->id,
@@ -58,13 +57,13 @@ class UserShareTest extends TestCase
$this
->actingAs($user)
->postJson("/api/share/$folder->id", [
'isPassword' => false,
'permission' => 'editor',
'type' => 'folder',
])->assertStatus(201)->assertJsonFragment([
'item_id' => $folder->id,
'type' => 'folder',
]);
'isPassword' => false,
'permission' => 'editor',
'type' => 'folder',
])->assertStatus(201)->assertJsonFragment([
'item_id' => $folder->id,
'type' => 'folder',
]);
$this->assertDatabaseHas('shares', [
'user_id' => $user->id,
@@ -90,11 +89,11 @@ class UserShareTest extends TestCase
$this
->actingAs($user)
->postJson("/api/share/$folder->id", [
'isPassword' => true,
'password' => 'secret',
'permission' => 'editor',
'type' => 'folder',
])
'isPassword' => true,
'password' => 'secret',
'permission' => 'editor',
'type' => 'folder',
])
->assertStatus(201)
->assertJsonFragment([
'item_id' => $folder->id,
@@ -128,11 +127,11 @@ class UserShareTest extends TestCase
$this
->actingAs($user)
->postJson("/api/share/$folder->id", [
'isPassword' => false,
'permission' => 'editor',
'type' => 'folder',
'expiration' => 12,
])
'isPassword' => false,
'permission' => 'editor',
'type' => 'folder',
'expiration' => 12,
])
->assertStatus(201)
->assertJsonFragment([
'item_id' => $folder->id,
@@ -154,14 +153,14 @@ class UserShareTest extends TestCase
$this
->actingAs($user)
->postJson("/api/share/$folder->id", [
'isPassword' => false,
'permission' => 'editor',
'type' => 'folder',
'emails' => [
'john@doe.com',
'jane@doe.com',
],
])->assertStatus(201);
'isPassword' => false,
'permission' => 'editor',
'type' => 'folder',
'emails' => [
'john@doe.com',
'jane@doe.com',
],
])->assertStatus(201);
Notification::assertTimesSent(2, SharedSendViaEmail::class);
}
@@ -216,14 +215,14 @@ class UserShareTest extends TestCase
'type' => 'folder',
])->assertStatus(201);
$this->deleteJson("/api/share/revoke", [
$this->deleteJson('/api/share/revoke', [
'tokens' => [
$folder->shared->token
$folder->shared->token,
],
])->assertStatus(204);
$this->assertDatabaseMissing('shares', [
'item_id' => $folder->id
'item_id' => $folder->id,
]);
}
}

View File

@@ -1,16 +1,15 @@
<?php
namespace Tests\Domain\Sharing;
use Domain\Settings\Models\File;
use Domain\Settings\Models\Share;
use Domain\Settings\Models\User;
use Domain\Settings\Models\Zip;
use Domain\SetupWizard\Services\SetupService;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Str;
use Storage;
use Tests\TestCase;
use Illuminate\Support\Str;
use Domain\Settings\Models\Zip;
use Domain\Settings\Models\File;
use Domain\Settings\Models\User;
use Domain\Settings\Models\Share;
use Illuminate\Http\UploadedFile;
use Domain\SetupWizard\Services\SetupService;
class VisitorAccessToItemsTest extends TestCase
{
@@ -29,7 +28,6 @@ class VisitorAccessToItemsTest extends TestCase
{
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -55,7 +53,6 @@ class VisitorAccessToItemsTest extends TestCase
]);
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -66,8 +63,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);
@@ -102,7 +98,6 @@ class VisitorAccessToItemsTest extends TestCase
{
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -130,12 +125,11 @@ class VisitorAccessToItemsTest extends TestCase
]);
if ($is_protected) {
$cookie = [
'share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
])
]),
];
$this->withCookies($cookie)
@@ -143,7 +137,7 @@ class VisitorAccessToItemsTest extends TestCase
->assertStatus(200);
}
if (!$is_protected) {
if (! $is_protected) {
$this->get("/share/$share->token")
->assertStatus(200);
}
@@ -157,7 +151,6 @@ class VisitorAccessToItemsTest extends TestCase
{
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -183,12 +176,11 @@ class VisitorAccessToItemsTest extends TestCase
// Get thumbnail file
if ($is_protected) {
$cookie = [
'share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
])
]),
];
$this->withCookies($cookie)
@@ -196,7 +188,7 @@ class VisitorAccessToItemsTest extends TestCase
->assertStatus(200);
}
if (!$is_protected) {
if (! $is_protected) {
$this->get("/thumbnail/$thumbnail->name/$share->token")
->assertStatus(200);
}
@@ -215,7 +207,6 @@ class VisitorAccessToItemsTest extends TestCase
{
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -235,15 +226,14 @@ class VisitorAccessToItemsTest extends TestCase
$file = UploadedFile::fake()
->create($zip->basename, 1000, 'application/zip');
Storage::putFileAs("zip", $file, $file->name);
Storage::putFileAs('zip', $file, $file->name);
if ($is_protected) {
$cookie = [
'share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
])
]),
];
$this->withCookies($cookie)
@@ -251,7 +241,7 @@ class VisitorAccessToItemsTest extends TestCase
->assertStatus(200);
}
if (!$is_protected) {
if (! $is_protected) {
$this->get("/zip/$zip->id/$share->token")
->assertStatus(200);
}

View File

@@ -1,13 +1,12 @@
<?php
namespace Tests\Domain\Sharing;
use Domain\Settings\Models\File;
use Domain\Settings\Models\Folder;
use Domain\Settings\Models\Share;
use Domain\Settings\Models\User;
use Domain\SetupWizard\Services\SetupService;
use Tests\TestCase;
use Domain\Settings\Models\File;
use Domain\Settings\Models\User;
use Domain\Settings\Models\Share;
use Domain\Settings\Models\Folder;
use Domain\SetupWizard\Services\SetupService;
class VisitorBrowseTest extends TestCase
{
@@ -44,7 +43,7 @@ class VisitorBrowseTest extends TestCase
'created_at' => $share->created_at->toJson(),
'updated_at' => $share->updated_at->toJson(),
],
]
],
]);
}
@@ -69,7 +68,7 @@ class VisitorBrowseTest extends TestCase
*/
public function it_try_to_get_deleted_share_record()
{
$this->get("/api/browse/share/19ZMPNiass4ZqWwQ")
$this->get('/api/browse/share/19ZMPNiass4ZqWwQ')
->assertNotFound();
}
@@ -100,7 +99,7 @@ class VisitorBrowseTest extends TestCase
]);
$this->postJson("/api/browse/authenticate/$share->token", [
'password' => 'secret'
'password' => 'secret',
])
->assertStatus(200)
->assertCookie('share_session', json_encode([
@@ -127,7 +126,7 @@ class VisitorBrowseTest extends TestCase
]);
$this->postJson("/api/browse/authenticate/$share->token", [
'password' => 'bad-password'
'password' => 'bad-password',
])
->assertStatus(401)
->assertCookieMissing('share_session');
@@ -141,7 +140,6 @@ class VisitorBrowseTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -164,7 +162,7 @@ class VisitorBrowseTest extends TestCase
->create([
'parent_id' => $root->id,
'name' => 'Documents',
"author" => "user",
'author' => 'user',
'user_id' => $user->id,
]);
@@ -173,50 +171,49 @@ class VisitorBrowseTest extends TestCase
'folder_id' => $root->id,
'name' => 'Document',
'basename' => 'document.pdf',
"mimetype" => "application/pdf",
"author" => "user",
"type" => "file",
'mimetype' => 'application/pdf',
'author' => 'user',
'type' => 'file',
'user_id' => $user->id,
]);
$json = [
[
"id" => $folder->id,
"user_id" => $user->id,
"parent_id" => $root->id,
"name" => "Documents",
"color" => null,
"emoji" => null,
"author" => "user",
"deleted_at" => null,
"created_at" => $folder->created_at,
"updated_at" => $folder->updated_at->toJson(),
"items" => 0,
"trashed_items" => 0,
"type" => "folder",
'id' => $folder->id,
'user_id' => $user->id,
'parent_id' => $root->id,
'name' => 'Documents',
'color' => null,
'emoji' => null,
'author' => 'user',
'deleted_at' => null,
'created_at' => $folder->created_at,
'updated_at' => $folder->updated_at->toJson(),
'items' => 0,
'trashed_items' => 0,
'type' => 'folder',
],
[
"id" => $file->id,
"user_id" => $user->id,
"folder_id" => $root->id,
"thumbnail" => null,
"name" => "Document",
"basename" => "document.pdf",
"mimetype" => "application/pdf",
"filesize" => $file->filesize,
"type" => "file",
"metadata" => null,
"author" => "user",
"deleted_at" => null,
"created_at" => $file->created_at,
"updated_at" => $file->updated_at->toJson(),
"file_url" => "http://localhost/file/document.pdf/$share->token",
]
'id' => $file->id,
'user_id' => $user->id,
'folder_id' => $root->id,
'thumbnail' => null,
'name' => 'Document',
'basename' => 'document.pdf',
'mimetype' => 'application/pdf',
'filesize' => $file->filesize,
'type' => 'file',
'metadata' => null,
'author' => 'user',
'deleted_at' => null,
'created_at' => $file->created_at,
'updated_at' => $file->updated_at->toJson(),
'file_url' => "http://localhost/file/document.pdf/$share->token",
],
];
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -230,7 +227,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)
->assertExactJson($json);
@@ -246,7 +243,6 @@ class VisitorBrowseTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -294,44 +290,43 @@ class VisitorBrowseTest extends TestCase
$tree = [
[
'id' => $share->item_id,
"name" => "Home",
"location" => "public",
"folders" => [
'name' => 'Home',
'location' => 'public',
'folders' => [
[
"id" => $folder_level_2->id,
"parent_id" => $folder_level_1->id,
"name" => "level 2",
"items" => 1,
"trashed_items" => 1,
"type" => "folder",
"folders" => [
'id' => $folder_level_2->id,
'parent_id' => $folder_level_1->id,
'name' => 'level 2',
'items' => 1,
'trashed_items' => 1,
'type' => 'folder',
'folders' => [
[
"id" => $folder_level_3->id,
"parent_id" => $folder_level_2->id,
"name" => "level 3",
"items" => 0,
"trashed_items" => 0,
"type" => "folder",
"folders" => [],
'id' => $folder_level_3->id,
'parent_id' => $folder_level_2->id,
'name' => 'level 3',
'items' => 0,
'trashed_items' => 0,
'type' => 'folder',
'folders' => [],
],
],
],
[
"id" => $folder_level_2_sibling->id,
"parent_id" => $folder_level_1->id,
"name" => "level 2 Sibling",
"items" => 0,
"trashed_items" => 0,
"type" => "folder",
"folders" => []
]
]
]
'id' => $folder_level_2_sibling->id,
'parent_id' => $folder_level_1->id,
'name' => 'level 2 Sibling',
'items' => 0,
'trashed_items' => 0,
'type' => 'folder',
'folders' => [],
],
],
],
];
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -345,8 +340,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);
@@ -362,7 +356,6 @@ class VisitorBrowseTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$folder = Folder::factory(Folder::class)
->create();
@@ -385,7 +378,6 @@ class VisitorBrowseTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -395,17 +387,16 @@ class VisitorBrowseTest extends TestCase
->get("/api/browse/search/$share->token?query=doc")
->assertStatus(200)
->assertJsonFragment([
'id' => $file->id
'id' => $file->id,
]);
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->getJson("/api/browse/search/$share->token?query=doc")
->assertStatus(200)
->assertJsonFragment([
'id' => $file->id
'id' => $file->id,
]);
}
});
@@ -419,7 +410,6 @@ class VisitorBrowseTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$folder = Folder::factory(Folder::class)
->create();
@@ -441,7 +431,6 @@ class VisitorBrowseTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -454,8 +443,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([]);
@@ -471,7 +459,6 @@ class VisitorBrowseTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$file = File::factory(File::class)
->create([
'name' => 'Document',
@@ -489,7 +476,6 @@ class VisitorBrowseTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -499,16 +485,16 @@ class VisitorBrowseTest extends TestCase
->get("/api/browse/file/$share->token")
->assertStatus(200)
->assertJsonFragment([
'name' => 'Document'
'name' => 'Document',
]);
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->getJson("/api/browse/file/$share->token")
->assertStatus(200)
->assertJsonFragment([
'name' => 'Document'
'name' => 'Document',
]);
}
});

View File

@@ -1,15 +1,14 @@
<?php
namespace Tests\Domain\Sharing;
use Domain\Settings\Models\File;
use Domain\Settings\Models\Folder;
use Domain\Settings\Models\Share;
use Domain\Settings\Models\User;
use Domain\SetupWizard\Services\SetupService;
use Illuminate\Http\UploadedFile;
use Storage;
use Tests\TestCase;
use Domain\Settings\Models\File;
use Domain\Settings\Models\User;
use Domain\Settings\Models\Share;
use Illuminate\Http\UploadedFile;
use Domain\Settings\Models\Folder;
use Domain\SetupWizard\Services\SetupService;
class VisitorManipulatingTest extends TestCase
{
@@ -27,18 +26,17 @@ class VisitorManipulatingTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
$folder = Folder::factory(Folder::class)
->create([
'user_id' => $user->id
'user_id' => $user->id,
]);
$file = File::factory(File::class)
->create([
'folder_id' => $folder->id
'folder_id' => $folder->id,
]);
$share = Share::factory(Share::class)
@@ -52,7 +50,6 @@ class VisitorManipulatingTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -71,7 +68,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->patchJson("/api/editor/rename/{$file->id}/$share->token", [
'name' => 'Renamed Item',
'type' => 'file',
@@ -97,19 +94,18 @@ class VisitorManipulatingTest extends TestCase
// 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
'user_id' => $user->id,
]);
$children = Folder::factory(Folder::class)
->create([
'user_id' => $user->id,
'parent_id' => $root->id
'parent_id' => $root->id,
]);
$share = Share::factory(Share::class)
@@ -123,7 +119,6 @@ class VisitorManipulatingTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -142,8 +137,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->patchJson("/api/editor/rename/{$children->id}/$share->token", [
'name' => 'Renamed Folder',
'type' => 'folder',
@@ -156,7 +150,7 @@ class VisitorManipulatingTest extends TestCase
$this->assertDatabaseHas('folders', [
'name' => 'Renamed Folder',
'id' => $children->id
'id' => $children->id,
]);
});
}
@@ -169,7 +163,6 @@ class VisitorManipulatingTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -189,7 +182,6 @@ class VisitorManipulatingTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -208,8 +200,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->postJson("/api/editor/create-folder/$share->token", [
'name' => 'Awesome New Folder',
'parent_id' => $folder->id,
@@ -236,7 +227,6 @@ class VisitorManipulatingTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -257,7 +247,7 @@ class VisitorManipulatingTest extends TestCase
$files = File::factory(File::class)
->count(2)
->create([
'folder_id' => $folder->id
'folder_id' => $folder->id,
]);
$payload = [
@@ -277,7 +267,6 @@ class VisitorManipulatingTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -290,8 +279,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->postJson("/api/editor/remove/$share->token", $payload)
->assertStatus(204);
}
@@ -313,7 +301,6 @@ class VisitorManipulatingTest extends TestCase
// check private or public share record
collect([true, false])
->each(function ($is_protected) {
$user = User::factory(User::class)
->create();
@@ -337,7 +324,6 @@ class VisitorManipulatingTest extends TestCase
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -354,8 +340,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->postJson("/api/editor/upload/$share->token", [
'filename' => $file->name,
'file' => $file,
@@ -387,13 +372,12 @@ class VisitorManipulatingTest extends TestCase
// 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
'user_id' => $user->id,
]);
$children = Folder::factory(Folder::class)
@@ -405,7 +389,7 @@ class VisitorManipulatingTest extends TestCase
$file = File::factory(File::class)
->create([
'user_id' => $user->id,
'folder_id' => $root->id
'folder_id' => $root->id,
]);
$share = Share::factory(Share::class)
@@ -423,13 +407,12 @@ class VisitorManipulatingTest extends TestCase
[
'type' => 'file',
'id' => $file->id,
]
],
],
];
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -442,8 +425,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->postJson("/api/editor/move/$share->token", $payload)
->assertStatus(204);
}
@@ -463,13 +445,12 @@ class VisitorManipulatingTest extends TestCase
// 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
'user_id' => $user->id,
]);
$brother = Folder::factory(Folder::class)
@@ -499,13 +480,12 @@ class VisitorManipulatingTest extends TestCase
[
'type' => 'folder',
'id' => $sister->id,
]
],
],
];
// Check shared item protected by password
if ($is_protected) {
$cookie = ['share_session' => json_encode([
'token' => $share->token,
'authenticated' => true,
@@ -518,8 +498,7 @@ class VisitorManipulatingTest extends TestCase
}
// Check public shared item
if (!$is_protected) {
if (! $is_protected) {
$this->postJson("/api/editor/move/$share->token", $payload)
->assertStatus(204);
}