mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Combine phpstan, cs-check, cs-fix into lint-php recipe; fix lint issues + test failures + duplicate detection bug
This commit is contained in:
@@ -131,6 +131,17 @@ $db = Database::getInstance();
|
||||
$createCtrl = new ThesisCreateController($db);
|
||||
$editCtrl = new ThesisEditController($db);
|
||||
|
||||
// Clean up stale leftovers from previous test runs
|
||||
$pdo = $db->getConnection();
|
||||
$stale = $pdo->query("SELECT id FROM theses WHERE title LIKE 'Round-trip test titre%' OR title LIKE 'Language%test%' OR title LIKE 'Backoffice fields test%' OR title LIKE 'Lang checkbox test%' OR title LIKE 'Context note test%'")->fetchAll(\PDO::FETCH_COLUMN);
|
||||
foreach ($stale as $id) {
|
||||
try {
|
||||
$db->deleteThesis((int)$id);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$pdo->exec("DELETE FROM languages WHERE name LIKE 'TestLang%' OR name LIKE 'EditLang%' OR name LIKE 'Idempotent%'");
|
||||
|
||||
$createdIds = [];
|
||||
|
||||
try {
|
||||
@@ -139,21 +150,24 @@ try {
|
||||
// TEST 1: Create — basic fields persisted
|
||||
// =========================================================================
|
||||
echo "Test 1: Create — basic fields persisted\n";
|
||||
$uniq = bin2hex(random_bytes(4));
|
||||
$post = buildPost($db, [
|
||||
'titre' => 'Round-trip test titre',
|
||||
'titre' => 'Round-trip test titre ' . $uniq,
|
||||
'subtitle' => 'Round-trip subtitle',
|
||||
'synopsis' => 'Round-trip synopsis',
|
||||
'année' => '2025',
|
||||
'auteurice' => $uniq,
|
||||
'mail' => $uniq . '@example.com',
|
||||
]);
|
||||
|
||||
$thesisId = $createCtrl->submit($post, []);
|
||||
$createdIds[] = $thesisId;
|
||||
$row = $db->getThesis($thesisId);
|
||||
|
||||
assertEq('Round-trip test titre', $row['title'], 'title saved');
|
||||
assertEq('Round-trip subtitle', $row['subtitle'], 'subtitle saved');
|
||||
assertEq('Round-trip synopsis', $row['synopsis'], 'synopsis saved');
|
||||
assertEq(2025, (int)$row['year'], 'year saved');
|
||||
assertEq('Round-trip test titre ' . $uniq, $row['title'], 'title saved');
|
||||
assertEq('Round-trip subtitle', $row['subtitle'], 'subtitle saved');
|
||||
assertEq('Round-trip synopsis', $row['synopsis'], 'synopsis saved');
|
||||
assertEq(2025, (int)$row['year'], 'year saved');
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
@@ -172,12 +186,16 @@ try {
|
||||
|
||||
$langIds = $db->getThesisLanguageIds($thesisId);
|
||||
$allLangs = $db->getAllLanguages();
|
||||
$found = array_filter($allLangs, fn($l) => $l['name'] === $uniqueLang);
|
||||
$lowerLang = strtolower($uniqueLang);
|
||||
$found = array_filter($allLangs, fn ($l) => strtolower($l['name']) === $lowerLang);
|
||||
assertNotEmpty($found, "language '$uniqueLang' created in languages table");
|
||||
|
||||
$createdLangId = (int)array_values($found)[0]['id'];
|
||||
assertContains((string)$createdLangId, array_map('strval', $langIds),
|
||||
'language_autre ID linked to thesis');
|
||||
assertContains(
|
||||
(string)$createdLangId,
|
||||
array_map('strval', $langIds),
|
||||
'language_autre ID linked to thesis'
|
||||
);
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
@@ -197,13 +215,19 @@ try {
|
||||
$createdIds[] = $thesisId;
|
||||
$langIds = $db->getThesisLanguageIds($thesisId);
|
||||
|
||||
assertContains((string)$allLangs[0]['id'], array_map('strval', $langIds),
|
||||
'checkbox language linked');
|
||||
assertContains(
|
||||
(string)$allLangs[0]['id'],
|
||||
array_map('strval', $langIds),
|
||||
'checkbox language linked'
|
||||
);
|
||||
|
||||
$found2 = array_filter($db->getAllLanguages(), fn($l) => $l['name'] === $uniqueLang2);
|
||||
$found2 = array_filter($db->getAllLanguages(), fn ($l) => strtolower($l['name']) === strtolower($uniqueLang2));
|
||||
$createdLang2 = (int)array_values($found2)[0]['id'];
|
||||
assertContains((string)$createdLang2, array_map('strval', $langIds),
|
||||
'language_autre also linked');
|
||||
assertContains(
|
||||
(string)$createdLang2,
|
||||
array_map('strval', $langIds),
|
||||
'language_autre also linked'
|
||||
);
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
@@ -245,11 +269,14 @@ try {
|
||||
$editCtrl->save($thesisId, $editPost, []);
|
||||
|
||||
$langIds = $db->getThesisLanguageIds($thesisId);
|
||||
$found3 = array_filter($db->getAllLanguages(), fn($l) => $l['name'] === $uniqueLang3);
|
||||
$found3 = array_filter($db->getAllLanguages(), fn ($l) => strtolower($l['name']) === strtolower($uniqueLang3));
|
||||
assertNotEmpty($found3, "language '$uniqueLang3' created on edit");
|
||||
$createdLang3 = (int)array_values($found3)[0]['id'];
|
||||
assertContains((string)$createdLang3, array_map('strval', $langIds),
|
||||
'language_autre linked on edit');
|
||||
assertContains(
|
||||
(string)$createdLang3,
|
||||
array_map('strval', $langIds),
|
||||
'language_autre linked on edit'
|
||||
);
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
@@ -269,11 +296,11 @@ try {
|
||||
$createdIds[] = $thesisId;
|
||||
$raw = $db->getThesisRawFields($thesisId);
|
||||
|
||||
assertEq('Internal note here', $raw['remarks'], 'remarks saved');
|
||||
assertEq(15.5, (float)$raw['jury_points'], 'jury_points saved');
|
||||
assertEq(1, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu saved');
|
||||
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg saved');
|
||||
assertEq(1, (int)$raw['cc2r'], 'cc2r saved');
|
||||
assertEq('Internal note here', $raw['remarks'], 'remarks saved');
|
||||
assertEq(15.5, (float)$raw['jury_points'], 'jury_points saved');
|
||||
assertEq(1, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu saved');
|
||||
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg saved');
|
||||
assertEq(1, (int)$raw['cc2r'], 'cc2r saved');
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
@@ -291,11 +318,11 @@ try {
|
||||
$editCtrl->save($thesisId, $editPost, []);
|
||||
$raw = $db->getThesisRawFields($thesisId);
|
||||
|
||||
assertEq('Updated note', $raw['remarks'], 'remarks updated');
|
||||
assertEq(18.0, (float)$raw['jury_points'], 'jury_points updated');
|
||||
assertEq(0, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu cleared');
|
||||
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg retained');
|
||||
assertEq(0, (int)$raw['cc2r'], 'cc2r cleared');
|
||||
assertEq('Updated note', $raw['remarks'], 'remarks updated');
|
||||
assertEq(18.0, (float)$raw['jury_points'], 'jury_points updated');
|
||||
assertEq(0, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu cleared');
|
||||
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg retained');
|
||||
assertEq(0, (int)$raw['cc2r'], 'cc2r cleared');
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
@@ -338,7 +365,10 @@ try {
|
||||
} finally {
|
||||
// Clean up test theses
|
||||
foreach ($createdIds as $id) {
|
||||
try { $db->deleteThesis($id); } catch (Exception $e) { /* ignore */ }
|
||||
try {
|
||||
$db->deleteThesis($id);
|
||||
} catch (Exception $e) { /* ignore */
|
||||
}
|
||||
}
|
||||
// Clean up test languages
|
||||
$allLangs = $db->getAllLanguages();
|
||||
@@ -349,7 +379,8 @@ try {
|
||||
|| str_starts_with($lang['name'], 'Idempotent_')) {
|
||||
try {
|
||||
$db->getConnection()->prepare('DELETE FROM languages WHERE id = ?')->execute([$lang['id']]);
|
||||
} catch (Exception $e) { /* ignore */ }
|
||||
} catch (Exception $e) { /* ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user