This commit is contained in:
2025-09-18 15:31:27 +02:00
commit 2abba0c2b7
406 changed files with 31879 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Services\GalleryService;
use App\Models\Hentai;
use App\Models\Episode;
use App\Models\Gallery;
use App\Models\Studios;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\RefreshDatabase;
class GalleryServiceTest extends TestCase
{
use RefreshDatabase;
protected $galleryService;
protected function setUp(): void
{
parent::setUp();
$this->galleryService = new GalleryService();
}
public function test_create_or_update_gallery()
{
// Fake the storage disk
Storage::fake('public');
// Create a Hentai and Episode instance
$hentai = Hentai::factory()->create();
$studio = Studios::factory()->create();
$episode = Episode::factory()->create(['hentai_id' => $hentai->id, 'studios_id' => $studio->id]);
// Create a fake image file
$file = UploadedFile::fake()->image('test_image.jpg');
// Create a request with the fake file
$request = new \Illuminate\Http\Request();
$request->files->add(['episodegallery1' => [$file]]);
// Call the method to test
$this->galleryService->createOrUpdateGallery($request, $hentai, $episode, $episode->episode, true);
$imageURL = "/images/hentai/{$hentai->slug}/gallery-ep-{$episode->episode}-0.webp";
$thumbnailURL = "/images/hentai/{$hentai->slug}/gallery-ep-{$episode->episode}-0-thumbnail.webp";
// Assert that the gallery was created
$this->assertDatabaseHas('gallery', [
'hentai_id' => $hentai->id,
'episode_id' => $episode->id,
'image_url' => $imageURL,
'thumbnail_url' => $thumbnailURL,
]);
// Assert that the image and thumbnail were saved
$this->assertTrue(Storage::disk('public')->exists($imageURL));
$this->assertTrue(Storage::disk('public')->exists($thumbnailURL));
}
}