From 06e541c1a71d471fd7e32b69a4f450268f0a6bee Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 11 Aug 2026 23:47:40 +0200 Subject: [PATCH] Add missing data to anidb list page --- app/Services/AnidbService.php | 14 ++++- tests/Feature/AdminAnidbControllerTest.php | 73 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/app/Services/AnidbService.php b/app/Services/AnidbService.php index 45bd2f113..cb99e9ecb 100644 --- a/app/Services/AnidbService.php +++ b/app/Services/AnidbService.php @@ -124,12 +124,24 @@ class AnidbService */ public function getAnimeRange(string $animeTitle = ''): LengthAwarePaginator // @phpstan-ignore missingType.generics { + $titleAggregate = DB::connection()->getDriverName() === 'sqlite' + ? "GROUP_CONCAT(at.title, ', ') AS title" + : "GROUP_CONCAT(at.title SEPARATOR ', ') AS title"; + $query = AnidbTitle::query() ->where('at.lang', '=', 'en'); if ($animeTitle !== '') { $query->where('at.title', 'like', '%'.$animeTitle.'%'); } - $query->select(['at.anidbid', DB::raw("GROUP_CONCAT(at.title SEPARATOR ', ') AS title"), 'ai.description']) + $query->select([ + 'at.anidbid', + DB::raw($titleAggregate), + 'ai.description', + 'ai.type', + 'ai.startdate', + 'ai.enddate', + 'ai.rating', + ]) ->from('anidb_titles as at') ->leftJoin('anidb_info as ai', 'ai.anidbid', '=', 'at.anidbid') ->groupBy('at.anidbid') diff --git a/tests/Feature/AdminAnidbControllerTest.php b/tests/Feature/AdminAnidbControllerTest.php index c1e2bcd4d..741f07c6e 100644 --- a/tests/Feature/AdminAnidbControllerTest.php +++ b/tests/Feature/AdminAnidbControllerTest.php @@ -4,7 +4,11 @@ declare(strict_types=1); namespace Tests\Feature; +use App\Services\AnidbService; use App\View\Composers\GlobalDataComposer; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; use ReflectionClass; use Tests\TestCase; @@ -14,6 +18,13 @@ final class AdminAnidbControllerTest extends TestCase { parent::setUp(); + if (! Schema::hasTable('settings')) { + Schema::create('settings', static function (Blueprint $table): void { + $table->string('name')->primary(); + $table->text('value')->nullable(); + }); + } + $this->setGlobalViewData([ 'serverroot' => 'http://localhost', 'site' => ['dereferrer_link' => ''], @@ -29,6 +40,9 @@ final class AdminAnidbControllerTest extends TestCase protected function tearDown(): void { $this->setGlobalViewData(null); + Schema::dropIfExists('anidb_info'); + Schema::dropIfExists('anidb_titles'); + Schema::dropIfExists('settings'); parent::tearDown(); } @@ -63,6 +77,65 @@ final class AdminAnidbControllerTest extends TestCase $this->assertStringContainsString('Display: 8.3 / 10', $html); } + public function test_list_query_and_view_include_anime_metadata(): void + { + Schema::create('anidb_titles', static function (Blueprint $table): void { + $table->unsignedInteger('anidbid'); + $table->string('type'); + $table->string('lang'); + $table->string('title'); + }); + Schema::create('anidb_info', static function (Blueprint $table): void { + $table->unsignedInteger('anidbid')->primary(); + $table->string('description')->nullable(); + $table->string('type')->nullable(); + $table->date('startdate')->nullable(); + $table->date('enddate')->nullable(); + $table->string('rating')->nullable(); + }); + + try { + DB::table('anidb_titles')->insert([ + 'anidbid' => 123, + 'type' => 'main', + 'lang' => 'en', + 'title' => 'Regression Test Anime', + ]); + DB::table('anidb_info')->insert([ + 'anidbid' => 123, + 'description' => 'Anime description', + 'type' => 'ONA', + 'startdate' => '2026-01-01', + 'enddate' => '2026-03-01', + 'rating' => '825', + ]); + + $animeList = (new AnidbService)->getAnimeRange(); + $anime = $animeList->first(); + + self::assertNotNull($anime); + self::assertSame('ONA', $anime->type); + self::assertSame('2026-01-01', $anime->startdate); + self::assertSame('2026-03-01', $anime->enddate); + self::assertSame('825', $anime->rating); + + $html = view('admin.anidb.index', [ + 'anidblist' => $animeList, + 'animetitle' => '', + 'title' => 'AniDB List', + 'meta_title' => 'AniDB List', + ])->render(); + + self::assertStringContainsString('ONA', $html); + self::assertStringContainsString('2026-01-01', $html); + self::assertStringContainsString('2026-03-01', $html); + self::assertStringContainsString('8.3', $html); + } finally { + Schema::dropIfExists('anidb_info'); + Schema::dropIfExists('anidb_titles'); + } + } + /** * @param array|null $data */