mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 08:09:18 +02:00
Add integration tests (Phase 2: DatabaseExtended, ShareLinkExtended, RateLimitExtended) and controller validation tests (Phase 3: ThesisCreate, ThesisEdit, AutofocusField)
This commit is contained in:
138
tests/phpunit/AutofocusFieldForErrorTest.php
Normal file
138
tests/phpunit/AutofocusFieldForErrorTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* AutofocusFieldForErrorTest — Tests for the autofocusFieldForError helpers
|
||||
* on both ThesisCreateController and ThesisEditController.
|
||||
*/
|
||||
class AutofocusFieldForErrorTest extends TestCase
|
||||
{
|
||||
// ── ThesisCreateController::autofocusFieldForError ────────────────────────
|
||||
|
||||
public function testCreateAutofocusTitle(): void
|
||||
{
|
||||
$this->assertSame('titre', ThesisCreateController::autofocusFieldForError("Le champ 'Titre du TFE' est requis."));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusAuthors(): void
|
||||
{
|
||||
$this->assertSame('auteurice', ThesisCreateController::autofocusFieldForError("Le champ 'Auteur·ice(s)' est requis."));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusSynopsis(): void
|
||||
{
|
||||
$this->assertSame('synopsis', ThesisCreateController::autofocusFieldForError("Le champ 'Synopsis' est requis."));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusYear(): void
|
||||
{
|
||||
$this->assertSame('année', ThesisCreateController::autofocusFieldForError('Année invalide. Veuillez entrer une année valide.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusOrientation(): void
|
||||
{
|
||||
$this->assertSame('orientation', ThesisCreateController::autofocusFieldForError('Veuillez sélectionner une orientation.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusAP(): void
|
||||
{
|
||||
$this->assertSame('ap', ThesisCreateController::autofocusFieldForError("Veuillez sélectionner un 'Atelier Pratique'."));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusFinality(): void
|
||||
{
|
||||
$this->assertSame('finality', ThesisCreateController::autofocusFieldForError("La finalité est manquante."));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusLanguages(): void
|
||||
{
|
||||
$this->assertSame('languages', ThesisCreateController::autofocusFieldForError('Veuillez sélectionner au moins une langue.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusPromoteur(): void
|
||||
{
|
||||
$this->assertSame('jury_promoteur', ThesisCreateController::autofocusFieldForError('Veuillez indiquer au moins un·e promoteur·ice.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusLecteurInterne(): void
|
||||
{
|
||||
$this->assertSame('jury_lecteur_interne[]', ThesisCreateController::autofocusFieldForError('Veuillez indiquer un·e lecteur·ice interne.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusLecteurExterne(): void
|
||||
{
|
||||
$this->assertSame('jury_lecteur_externe[]', ThesisCreateController::autofocusFieldForError('Veuillez indiquer un·e lecteur·ice externe.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusFormats(): void
|
||||
{
|
||||
$this->assertSame('formats', ThesisCreateController::autofocusFieldForError('Veuillez sélectionner au moins un format.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusLicense(): void
|
||||
{
|
||||
$this->assertSame('license_id', ThesisCreateController::autofocusFieldForError('Veuillez sélectionner une licence.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusUrl(): void
|
||||
{
|
||||
$this->assertSame('lien', ThesisCreateController::autofocusFieldForError('Lien URL invalide.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusTags(): void
|
||||
{
|
||||
$this->assertSame('tag', ThesisCreateController::autofocusFieldForError('Veuillez indiquer au moins 3 mots-clés.'));
|
||||
}
|
||||
|
||||
public function testCreateAutofocusUnknownErrorReturnsNull(): void
|
||||
{
|
||||
$this->assertNull(ThesisCreateController::autofocusFieldForError('Some completely unrelated error'));
|
||||
}
|
||||
|
||||
// ── ThesisEditController::autofocusFieldForError ──────────────────────────
|
||||
|
||||
public function testEditAutofocusTitle(): void
|
||||
{
|
||||
$this->assertSame('titre', ThesisEditController::autofocusFieldForError("Le champ 'Titre du TFE' est requis."));
|
||||
}
|
||||
|
||||
public function testEditAutofocusYear(): void
|
||||
{
|
||||
$this->assertSame('année', ThesisEditController::autofocusFieldForError("L'année est invalide."));
|
||||
}
|
||||
|
||||
public function testEditAutofocusSynopsis(): void
|
||||
{
|
||||
$this->assertSame('synopsis', ThesisEditController::autofocusFieldForError("Le champ 'Synopsis' est requis."));
|
||||
}
|
||||
|
||||
public function testEditAutofocusAuthors(): void
|
||||
{
|
||||
$this->assertSame('auteurice', ThesisEditController::autofocusFieldForError("Le champ 'Auteur·ice(s)' est requis."));
|
||||
}
|
||||
|
||||
public function testEditAutofocusUnknownErrorReturnsNull(): void
|
||||
{
|
||||
$this->assertNull(ThesisEditController::autofocusFieldForError('Some completely unrelated error'));
|
||||
}
|
||||
|
||||
// ── No field name leak between Create and Edit controllers ────────────────
|
||||
|
||||
public function testCreateDoesNotLeakEditFieldNames(): void
|
||||
{
|
||||
// 'titre' is the Edit controller field name, but Create returns 'titre' too
|
||||
// Actually check that Create-specific field names like 'auteurice' exist
|
||||
// and that Edit doesn't return a Create-only name for an unrelated error
|
||||
|
||||
// Create returns 'auteurice' for author errors
|
||||
$this->assertSame('auteurice', ThesisCreateController::autofocusFieldForError("Le champ 'Auteur·ice(s)' est requis."));
|
||||
|
||||
// Edit returns 'auteurice' for author errors too (same naming)
|
||||
$this->assertSame('auteurice', ThesisEditController::autofocusFieldForError("Le champ 'Auteur·ice(s)' est requis."));
|
||||
|
||||
// Both return null for unknown errors (no spurious field)
|
||||
$this->assertNull(ThesisCreateController::autofocusFieldForError('bogus error'));
|
||||
$this->assertNull(ThesisEditController::autofocusFieldForError('bogus error'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user