- PHP 8.3 → 8.4 (Dockerfile + composer.json) - Symfony 7.0 → 8.0 (tous les composants symfony/*) - API Platform 3.x → 4.x : migration openapiContext → openapi: new Operation(...) - Doctrine DBAL 3 → 4 : suppression use_savepoints, replace prepare/executeQuery - Doctrine ORM 2.x → 3.x : ClassMetadataInfo → ClassMetadata, setParameters → setParameter - Doctrine Bundle 2.x → 3.x, Fixtures Bundle 3.x → 4.x - zenstruck/foundry 1.x → 2.x : ModelFactory → PersistentObjectFactory, getDefaults → defaults - phpmd/phpmd 2.x → 3.x-dev (seule version supportant Symfony 8) - phparkitect 0.3 → 0.8 : NotDependsOnTheseNamespaces prend un array - symfony/mercure-bundle 0.3 → 0.4, symfony/monolog-bundle 3 → 4 - Suppression de runtime/frankenphp-symfony (intégré nativement dans symfony/runtime 8) - worker.Caddyfile : suppression de APP_RUNTIME (détection automatique Symfony 8) - Routes errors.xml/wdt.xml/profiler.xml → .php (Symfony 8 supprime le XML) - Types::ARRAY → Types::JSON dans Entity/Manga.php (DBAL 4 retire array type) - Suppression de src/Schedule.php (doublon vide avec MonitoringSchedule) - Tests : hydra:Collection → Collection, hydra:member → member (API Platform 4)
147 lines
4.2 KiB
PHP
147 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Feature\Manga;
|
|
|
|
use App\Tests\Factory\ChapterFactory;
|
|
use App\Tests\Factory\MangaFactory;
|
|
use App\Tests\Feature\AbstractApiTestCase;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Zenstruck\Foundry\Test\Factories;
|
|
use Zenstruck\Foundry\Test\ResetDatabase;
|
|
|
|
class DownloadVolumeTest extends AbstractApiTestCase
|
|
{
|
|
use ResetDatabase;
|
|
use Factories;
|
|
|
|
public function testItDownloadsVolumeCbz(): void
|
|
{
|
|
// Arrange
|
|
$manga = MangaFactory::createOne([
|
|
'title' => 'One Piece',
|
|
'slug' => 'one-piece',
|
|
]);
|
|
|
|
// Create chapters for volume 1
|
|
ChapterFactory::createMany(3, [
|
|
'manga' => $manga,
|
|
'volume' => 1,
|
|
'visible' => true,
|
|
'cbzPath' => __DIR__.'/../../Shared/Files/test-chapter.cbz',
|
|
]);
|
|
|
|
$mangaId = $manga->getId();
|
|
|
|
// Act
|
|
static::createClient()->request('GET', "/api/mangas/{$mangaId}/volumes/1/download");
|
|
|
|
// Assert
|
|
$this->assertResponseIsSuccessful();
|
|
$this->assertResponseHeaderSame('Content-Type', 'application/x-cbz');
|
|
$contentDisposition = static::getClient()->getResponse()->headers->get('Content-Disposition');
|
|
$this->assertStringContainsString('attachment; filename=', $contentDisposition);
|
|
$this->assertStringContainsString('one-piece_vol1.cbz', $contentDisposition);
|
|
}
|
|
|
|
public function testItReturns404WhenMangaNotFound(): void
|
|
{
|
|
// Act
|
|
static::createClient()->request('GET', '/api/mangas/999999/volumes/1/download');
|
|
|
|
// Assert
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testItReturns404WhenVolumeNotFound(): void
|
|
{
|
|
// Arrange
|
|
$manga = MangaFactory::createOne([
|
|
'title' => 'One Piece',
|
|
'slug' => 'one-piece',
|
|
]);
|
|
|
|
$mangaId = $manga->getId();
|
|
|
|
// Act
|
|
static::createClient()->request('GET', "/api/mangas/{$mangaId}/volumes/999/download");
|
|
|
|
// Assert
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testItReturns404WhenNoAvailableChaptersInVolume(): void
|
|
{
|
|
// Arrange
|
|
$manga = MangaFactory::createOne([
|
|
'title' => 'One Piece',
|
|
'slug' => 'one-piece',
|
|
]);
|
|
|
|
// Create chapters for volume 1 but all without CBZ files
|
|
ChapterFactory::createMany(3, [
|
|
'manga' => $manga,
|
|
'volume' => 1,
|
|
'visible' => true,
|
|
'cbzPath' => null, // No CBZ files
|
|
]);
|
|
|
|
$mangaId = $manga->getId();
|
|
|
|
// Act
|
|
static::createClient()->request('GET', "/api/mangas/{$mangaId}/volumes/1/download");
|
|
|
|
// Assert
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testItOnlyIncludesVisibleChaptersWithCbz(): void
|
|
{
|
|
// Arrange
|
|
$manga = MangaFactory::createOne([
|
|
'title' => 'One Piece',
|
|
'slug' => 'one-piece',
|
|
]);
|
|
|
|
// Create a mix of chapters
|
|
ChapterFactory::createOne([
|
|
'manga' => $manga,
|
|
'volume' => 1,
|
|
'number' => 1.0,
|
|
'visible' => true,
|
|
'cbzPath' => __DIR__.'/../../Shared/Files/test-chapter.cbz',
|
|
]);
|
|
|
|
ChapterFactory::createOne([
|
|
'manga' => $manga,
|
|
'volume' => 1,
|
|
'number' => 2.0,
|
|
'visible' => false, // Soft deleted
|
|
'cbzPath' => __DIR__.'/../../Shared/Files/test-chapter.cbz',
|
|
]);
|
|
|
|
ChapterFactory::createOne([
|
|
'manga' => $manga,
|
|
'volume' => 1,
|
|
'number' => 3.0,
|
|
'visible' => true,
|
|
'cbzPath' => null, // No CBZ
|
|
]);
|
|
|
|
ChapterFactory::createOne([
|
|
'manga' => $manga,
|
|
'volume' => 1,
|
|
'number' => 4.0,
|
|
'visible' => true,
|
|
'cbzPath' => __DIR__.'/../../Shared/Files/test-chapter.cbz',
|
|
]);
|
|
|
|
$mangaId = $manga->getId();
|
|
|
|
// Act
|
|
static::createClient()->request('GET', "/api/mangas/{$mangaId}/volumes/1/download");
|
|
|
|
// Assert - Should succeed with only 2 chapters (1 and 4)
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
}
|