mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 16:22:14 +00:00
added it_get_public_file_record_and_download_them, it_try_to_get_protected_file_record, it_get_shared_record, it_get_deleted_shared_record, it_get_shared_page, it_get_deleted_shared_page test
This commit is contained in:
@@ -15,7 +15,7 @@ use Laravel\Sanctum\Sanctum;
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FileAccessTest extends TestCase
|
||||
class ContentAccessTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
93
tests/Feature/ShareContentAccessTest.php
Normal file
93
tests/Feature/ShareContentAccessTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Share;
|
||||
use App\Models\Traffic;
|
||||
use App\Models\User;
|
||||
use App\Services\SetupService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ShareContentAccessTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setup = app()->make(SetupService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_public_file_record_and_download_them()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$this->setup->create_directories();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$document = UploadedFile::fake()
|
||||
->create(Str::random() . '-fake-file.pdf', 1000, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $document, $document->name);
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'filesize' => $document->getSize(),
|
||||
'user_id' => $user->id,
|
||||
'basename' => $document->name,
|
||||
'name' => 'fake-file.pdf',
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'item_id' => $file->id,
|
||||
'user_id' => $user->id,
|
||||
'type' => 'file',
|
||||
'is_protected' => false,
|
||||
]);
|
||||
|
||||
// Get share record
|
||||
$this->get("/api/files/$share->token/public")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'basename' => $document->name
|
||||
]);
|
||||
|
||||
// Get shared file
|
||||
$this->get("/file/$document->name/public/$share->token")
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertDatabaseHas('traffic', [
|
||||
'user_id' => $user->id,
|
||||
'download' => '1024000',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_to_get_protected_file_record()
|
||||
{
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'type' => 'file',
|
||||
'is_protected' => true,
|
||||
]);
|
||||
|
||||
// Get share record
|
||||
$this->get("/api/files/$share->token/public")
|
||||
->assertStatus(403);
|
||||
}
|
||||
}
|
||||
@@ -237,5 +237,68 @@ class ShareTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO: napisat testy pre FileSharingController
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_shared_record()
|
||||
{
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'is_protected' => 0,
|
||||
]);
|
||||
|
||||
$this->get("/api/shared/$share->token")
|
||||
->assertStatus(200)
|
||||
->assertExactJson([
|
||||
'data' => [
|
||||
'id' => $share->id,
|
||||
'type' => 'shares',
|
||||
'attributes' => [
|
||||
'permission' => $share->permission,
|
||||
'is_protected' => '0',
|
||||
'item_id' => $share->item_id,
|
||||
'expire_in' => $share->expire_in,
|
||||
'token' => $share->token,
|
||||
'link' => $share->link,
|
||||
'type' => $share->type,
|
||||
'created_at' => $share->created_at->toJson(),
|
||||
'updated_at' => $share->updated_at->toJson(),
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_deleted_shared_record()
|
||||
{
|
||||
$this->get("/api/shared/19ZMPNiass4ZqWwQ")
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_shared_page()
|
||||
{
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'type' => 'file',
|
||||
'is_protected' => false,
|
||||
]);
|
||||
|
||||
$this->get("/shared/$share->token")
|
||||
->assertViewIs('index')
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_deleted_shared_page()
|
||||
{
|
||||
$this->get('/shared/19ZMPNiass4ZqWwQ')
|
||||
->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user