- 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)
131 lines
4.8 KiB
PHP
131 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Feature\Setting;
|
|
|
|
use App\Entity\ContentSource;
|
|
use App\Tests\Feature\AbstractApiTestCase;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Zenstruck\Foundry\Test\ResetDatabase;
|
|
|
|
final class GetContentSourceTest extends AbstractApiTestCase
|
|
{
|
|
use ResetDatabase;
|
|
|
|
private int $sourceId;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Création d'une source de contenu
|
|
$source = new ContentSource();
|
|
$source->setBaseUrl('https://mangadex.org')
|
|
->setChapterUrlFormat('https://mangadex.org/chapter/{id}')
|
|
->setScrapingType('html')
|
|
->setImageSelector('.chapter-image img')
|
|
->setNextPageSelector('.next-page')
|
|
->setChapterSelector('.chapter-list a');
|
|
|
|
$this->entityManager->persist($source);
|
|
$this->entityManager->flush();
|
|
|
|
$this->sourceId = $source->getId();
|
|
}
|
|
|
|
public function testItReturnsNotFoundWhenSourceDoesNotExist(): void
|
|
{
|
|
$response = static::createClient()->request('GET', '/api/content-sources/999999');
|
|
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
|
$this->assertJsonContains([
|
|
'detail' => 'ContentSource with id 999999 not found',
|
|
]);
|
|
}
|
|
|
|
public function testItReturnsSourceSuccessfully(): void
|
|
{
|
|
$response = static::createClient()->request('GET', "/api/content-sources/{$this->sourceId}");
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
$data = $response->toArray();
|
|
|
|
$this->assertArrayHasKey('id', $data);
|
|
$this->assertEquals($this->sourceId, $data['id']);
|
|
$this->assertArrayHasKey('baseUrl', $data);
|
|
$this->assertEquals('https://mangadex.org', $data['baseUrl']);
|
|
$this->assertArrayHasKey('chapterUrlFormat', $data);
|
|
$this->assertEquals('https://mangadex.org/chapter/{id}', $data['chapterUrlFormat']);
|
|
$this->assertArrayHasKey('scrapingType', $data);
|
|
$this->assertEquals('html', $data['scrapingType']);
|
|
$this->assertArrayHasKey('imageSelector', $data);
|
|
$this->assertEquals('.chapter-image img', $data['imageSelector']);
|
|
$this->assertArrayHasKey('nextPageSelector', $data);
|
|
$this->assertEquals('.next-page', $data['nextPageSelector']);
|
|
$this->assertArrayHasKey('chapterSelector', $data);
|
|
$this->assertEquals('.chapter-list a', $data['chapterSelector']);
|
|
$this->assertArrayHasKey('cleanBaseUrl', $data);
|
|
$this->assertEquals('mangadex.org', $data['cleanBaseUrl']);
|
|
}
|
|
|
|
public function testItReturnsSourceWithJavascriptScrapingType(): void
|
|
{
|
|
// Créer une source avec le type javascript
|
|
$source = new ContentSource();
|
|
$source->setBaseUrl('https://mangakakalot.com')
|
|
->setChapterUrlFormat('https://mangakakalot.com/chapter/{id}')
|
|
->setScrapingType('javascript')
|
|
->setImageSelector('.page-image img')
|
|
->setNextPageSelector('.next-button')
|
|
->setChapterSelector('.chapter-link');
|
|
|
|
$this->entityManager->persist($source);
|
|
$this->entityManager->flush();
|
|
|
|
$response = static::createClient()->request('GET', "/api/content-sources/{$source->getId()}");
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
$data = $response->toArray();
|
|
|
|
$this->assertEquals('javascript', $data['scrapingType']);
|
|
$this->assertEquals('https://mangakakalot.com', $data['baseUrl']);
|
|
$this->assertEquals('mangakakalot.com', $data['cleanBaseUrl']);
|
|
}
|
|
|
|
public function testItReturnsSourceWithNullOptionalFields(): void
|
|
{
|
|
// Créer une source sans les champs optionnels
|
|
$source = new ContentSource();
|
|
$source->setBaseUrl('https://simple-source.com')
|
|
->setChapterUrlFormat('https://simple-source.com/chapter/{id}')
|
|
->setScrapingType('html');
|
|
|
|
$this->entityManager->persist($source);
|
|
$this->entityManager->flush();
|
|
|
|
$response = static::createClient()->request('GET', "/api/content-sources/{$source->getId()}");
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
$data = $response->toArray();
|
|
|
|
// Les champs optionnels peuvent ne pas être présents dans la réponse
|
|
if (array_key_exists('imageSelector', $data)) {
|
|
$this->assertNull($data['imageSelector']);
|
|
}
|
|
if (array_key_exists('nextPageSelector', $data)) {
|
|
$this->assertNull($data['nextPageSelector']);
|
|
}
|
|
if (array_key_exists('chapterSelector', $data)) {
|
|
$this->assertNull($data['chapterSelector']);
|
|
}
|
|
}
|
|
|
|
public function testItValidatesIdFormat(): void
|
|
{
|
|
$response = static::createClient()->request('GET', '/api/content-sources/invalid-id');
|
|
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
|
}
|
|
}
|