Files
animethemes-server/tests/Unit/Models/Wiki/ThemeTest.php
T

108 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Enums\Models\Wiki\ThemeType;
use App\Models\Wiki\Anime;
use App\Models\Wiki\Entry;
use App\Models\Wiki\Group;
use App\Models\Wiki\Song;
use App\Models\Wiki\Theme;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Testing\WithFaker;
uses(WithFaker::class);
test('casts type to enum', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$type = $theme->type;
$this->assertInstanceOf(ThemeType::class, $type);
});
test('searchable as', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$this->assertIsString($theme->searchableAs());
});
test('to searchable array', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$this->assertIsArray($theme->toSearchableArray());
});
test('nameable', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$this->assertIsString($theme->getName());
});
test('has subtitle', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$this->assertIsString($theme->getSubtitle());
});
test('anime', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$this->assertInstanceOf(BelongsTo::class, $theme->anime());
$this->assertInstanceOf(Anime::class, $theme->anime()->first());
});
test('group', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->for(Group::factory())
->createOne();
$this->assertInstanceOf(BelongsTo::class, $theme->group());
$this->assertInstanceOf(Group::class, $theme->group()->first());
});
test('song', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->for(Song::factory())
->createOne();
$this->assertInstanceOf(BelongsTo::class, $theme->song());
$this->assertInstanceOf(Song::class, $theme->song()->first());
});
test('entries', function (): void {
$entryCount = fake()->randomDigitNotNull();
$theme = Theme::factory()
->for(Anime::factory())
->has(Entry::factory()->count($entryCount))
->createOne();
$this->assertInstanceOf(HasMany::class, $theme->entries());
$this->assertEquals($entryCount, $theme->entries()->count());
$this->assertInstanceOf(Entry::class, $theme->entries()->first());
});
test('theme creates slug', function (): void {
$theme = Theme::factory()
->for(Anime::factory())
->createOne();
$this->assertArrayHasKey('slug', $theme);
});