mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 09:34:50 +02:00
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Constants\Config\AudioConstants;
|
|
use App\Events\Wiki\Audio\AudioForceDeleting;
|
|
use App\Models\Wiki\Audio;
|
|
use App\Models\Wiki\Video;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Http\Testing\File;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
uses(WithFaker::class);
|
|
|
|
test('nameable', function (): void {
|
|
$audio = Audio::factory()->createOne();
|
|
|
|
$this->assertIsString($audio->getName());
|
|
});
|
|
|
|
test('has subtitle', function (): void {
|
|
$audio = Audio::factory()->createOne();
|
|
|
|
$this->assertIsString($audio->getSubtitle());
|
|
});
|
|
|
|
test('videos', function (): void {
|
|
$videoCount = fake()->randomDigitNotNull();
|
|
|
|
$audio = Audio::factory()
|
|
->has(Video::factory()->count($videoCount))
|
|
->createOne();
|
|
|
|
$this->assertInstanceOf(HasMany::class, $audio->videos());
|
|
$this->assertEquals($videoCount, $audio->videos()->count());
|
|
$this->assertInstanceOf(Video::class, $audio->videos()->first());
|
|
});
|
|
|
|
test('audio storage deletion', function (): void {
|
|
$fs = Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED));
|
|
$file = File::fake()->create(fake()->word().'.ogg', fake()->randomDigitNotNull());
|
|
$fsFile = $fs->putFile('', $file);
|
|
|
|
$audio = Audio::factory()->createOne([
|
|
Audio::ATTRIBUTE_PATH => $fsFile,
|
|
]);
|
|
|
|
$audio->delete();
|
|
|
|
$this->assertTrue($fs->exists($audio->path));
|
|
});
|
|
|
|
test('audio storage force deletion', function (): void {
|
|
Event::fakeExcept(AudioForceDeleting::class);
|
|
|
|
$fs = Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED));
|
|
$file = File::fake()->create(fake()->word().'.ogg', fake()->randomDigitNotNull());
|
|
$fsFile = $fs->putFile('', $file);
|
|
|
|
$audio = Audio::factory()->createOne([
|
|
Audio::ATTRIBUTE_PATH => $fsFile,
|
|
]);
|
|
|
|
$audio->forceDelete();
|
|
|
|
$this->assertFalse($fs->exists($audio->path));
|
|
});
|