mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
99 lines
3.0 KiB
PHP
99 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Storage\Wiki\Video\Script\MoveScriptAction;
|
|
use App\Constants\Config\VideoConstants;
|
|
use App\Enums\Actions\ActionStatus;
|
|
use App\Models\Wiki\Video\VideoScript;
|
|
use Illuminate\Filesystem\FilesystemAdapter;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Http\Testing\File;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
uses(WithFaker::class);
|
|
|
|
test('default', function (): void {
|
|
Config::set(VideoConstants::SCRIPT_DISK_QUALIFIED, []);
|
|
Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED));
|
|
|
|
$script = VideoScript::factory()->createOne();
|
|
|
|
$action = new MoveScriptAction($script, fake()->word());
|
|
|
|
$storageResults = $action->handle();
|
|
|
|
$result = $storageResults->toActionResult();
|
|
|
|
$this->assertTrue($result->hasFailed());
|
|
});
|
|
|
|
test('passed', function (): void {
|
|
/** @var FilesystemAdapter $fs */
|
|
$fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED));
|
|
|
|
$file = File::fake()->create(fake()->word().'.txt', fake()->randomDigitNotNull());
|
|
|
|
$directory = fake()->unique()->word();
|
|
|
|
$script = VideoScript::factory()->createOne([
|
|
VideoScript::ATTRIBUTE_PATH => $fs->putFileAs($directory, $file, $file->getClientOriginalName()),
|
|
]);
|
|
|
|
$action = new MoveScriptAction($script, Str::replace($directory, fake()->unique()->word(), $script->path));
|
|
|
|
$storageResults = $action->handle();
|
|
|
|
$result = $storageResults->toActionResult();
|
|
|
|
$this->assertTrue($result->getStatus() === ActionStatus::PASSED);
|
|
});
|
|
|
|
test('moved in disk', function (): void {
|
|
/** @var FilesystemAdapter $fs */
|
|
$fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED));
|
|
|
|
$file = File::fake()->create(fake()->word().'.txt', fake()->randomDigitNotNull());
|
|
|
|
$directory = fake()->unique()->word();
|
|
|
|
$script = VideoScript::factory()->createOne([
|
|
VideoScript::ATTRIBUTE_PATH => $fs->putFileAs($directory, $file, $file->getClientOriginalName()),
|
|
]);
|
|
|
|
$from = $script->path;
|
|
$to = Str::replace($directory, fake()->unique()->word(), $script->path);
|
|
|
|
$action = new MoveScriptAction($script, $to);
|
|
|
|
$action->handle();
|
|
|
|
$fs->assertMissing($from);
|
|
$fs->assertExists($to);
|
|
});
|
|
|
|
test('script updated', function (): void {
|
|
/** @var FilesystemAdapter $fs */
|
|
$fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED));
|
|
|
|
$file = File::fake()->create(fake()->word().'.txt', fake()->randomDigitNotNull());
|
|
|
|
$directory = fake()->unique()->word();
|
|
|
|
$script = VideoScript::factory()->createOne([
|
|
VideoScript::ATTRIBUTE_PATH => $fs->putFileAs($directory, $file, $file->getClientOriginalName()),
|
|
]);
|
|
|
|
$to = Str::replace($directory, fake()->unique()->word(), $script->path);
|
|
|
|
$action = new MoveScriptAction($script, $to);
|
|
|
|
$result = $action->handle();
|
|
|
|
$action->then($result);
|
|
|
|
$this->assertDatabaseHas(VideoScript::class, [VideoScript::ATTRIBUTE_PATH => $to]);
|
|
});
|