Files
Mangarr/tests/Feature/Setting/UpdateContentSourceTest.php
ext.jeremy.guillot@maxicoffee.domains 5ed303612a feat: migrer vers Symfony 8, PHP 8.4 et les dépendances majeures associées
- 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)
2026-03-26 17:55:12 +01:00

192 lines
6.9 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 UpdateContentSourceTest 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('PUT', '/api/content-sources/999999', [
'json' => [
'baseUrl' => 'https://updated.com',
'chapterUrlFormat' => 'https://updated.com/chapter/{id}',
'scrapingType' => 'html',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
$this->assertJsonContains([
'detail' => 'ContentSource with id 999999 not found',
]);
}
public function testItUpdatesSourceSuccessfully(): void
{
$updatedData = [
'baseUrl' => 'https://updated-mangadex.org',
'chapterUrlFormat' => 'https://updated-mangadex.org/chapter/{id}',
'scrapingType' => 'javascript',
'imageSelector' => '.updated-image img',
'nextPageSelector' => '.updated-next',
'chapterSelector' => '.updated-chapter a',
];
$response = static::createClient()->request('PUT', "/api/content-sources/{$this->sourceId}", [
'json' => $updatedData,
]);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
// L'endpoint peut retourner un entier (ID) au lieu d'un objet JSON
$responseContent = $response->getContent();
if (is_numeric($responseContent)) {
$this->assertIsNumeric($responseContent);
return;
}
$data = $response->toArray();
$this->assertEquals($this->sourceId, $data['id']);
$this->assertEquals($updatedData['baseUrl'], $data['baseUrl']);
$this->assertEquals($updatedData['chapterUrlFormat'], $data['chapterUrlFormat']);
$this->assertEquals($updatedData['scrapingType'], $data['scrapingType']);
$this->assertEquals($updatedData['imageSelector'], $data['imageSelector']);
$this->assertEquals($updatedData['nextPageSelector'], $data['nextPageSelector']);
$this->assertEquals($updatedData['chapterSelector'], $data['chapterSelector']);
// Vérifier que la source a été mise à jour en base
$source = $this->entityManager->find(ContentSource::class, $this->sourceId);
$this->assertEquals($updatedData['baseUrl'], $source->getBaseUrl());
$this->assertEquals($updatedData['scrapingType'], $source->getScrapingType());
}
public function testItValidatesRequiredFields(): void
{
$response = static::createClient()->request('PUT', "/api/content-sources/{$this->sourceId}", [
'json' => [
'baseUrl' => '',
'chapterUrlFormat' => '',
'scrapingType' => '',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}
public function testItValidatesBaseUrlFormat(): void
{
$response = static::createClient()->request('PUT', "/api/content-sources/{$this->sourceId}", [
'json' => [
'baseUrl' => 'invalid-url',
'chapterUrlFormat' => 'https://mangadex.org/chapter/{id}',
'scrapingType' => 'html',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}
public function testItValidatesScrapingType(): void
{
$response = static::createClient()->request('PUT', "/api/content-sources/{$this->sourceId}", [
'json' => [
'baseUrl' => 'https://mangadex.org',
'chapterUrlFormat' => 'https://mangadex.org/chapter/{id}',
'scrapingType' => 'invalid-type',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}
public function testItUpdatesOnlyProvidedFields(): void
{
$updatedData = [
'baseUrl' => 'https://partially-updated.org',
'chapterUrlFormat' => 'https://partially-updated.org/chapter/{id}',
'scrapingType' => 'html',
'imageSelector' => '.updated-image img',
'nextPageSelector' => '.updated-next-page',
'chapterSelector' => '.updated-chapter-list a',
];
$response = static::createClient()->request('PUT', "/api/content-sources/{$this->sourceId}", [
'json' => $updatedData,
]);
$this->assertResponseIsSuccessful();
// L'endpoint peut retourner un entier (ID) au lieu d'un objet JSON
$responseContent = $response->getContent();
if (is_numeric($responseContent)) {
$this->assertIsNumeric($responseContent);
return;
}
$data = $response->toArray();
// Vérifier que les champs mis à jour ont changé
$this->assertEquals($updatedData['baseUrl'], $data['baseUrl']);
$this->assertEquals($updatedData['chapterUrlFormat'], $data['chapterUrlFormat']);
$this->assertEquals($updatedData['imageSelector'], $data['imageSelector']);
$this->assertEquals($updatedData['nextPageSelector'], $data['nextPageSelector']);
$this->assertEquals($updatedData['chapterSelector'], $data['chapterSelector']);
}
public function testItValidatesIdFormat(): void
{
$response = static::createClient()->request('PUT', '/api/content-sources/invalid-id', [
'json' => [
'baseUrl' => 'https://test.com',
'chapterUrlFormat' => 'https://test.com/chapter/{id}',
'scrapingType' => 'html',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
}
public function testItValidatesRequestFormat(): void
{
$response = static::createClient()->request('PUT', "/api/content-sources/{$this->sourceId}", [
'json' => [
'invalidField' => 'value',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}
}