Remove duration_pages/duration_minutes/file_size_info; rename cc4r → cc2r in DB and code

This commit is contained in:
Pontoporeia
2026-05-09 18:39:38 +02:00
parent cc0ae32df0
commit c4a23d5c2d
18 changed files with 130 additions and 309 deletions

View File

@@ -9,7 +9,6 @@
* Covered fields:
* - titre, subtitle, synopsis, année
* - orientation, ap, finality
* - duration_pages, duration_minutes, has_annexes → file_size_info + individual columns
* - languages (checkboxes), language_autre (free-text)
* - formats (checkboxes)
* - jury (promoteur, lecteur interne, lecteur externe)
@@ -17,7 +16,7 @@
* - lien (baiu_link), license_id, access_type_id
* - objet
* - context_note
* - remarks, jury_points, exemplaire_baiu, exemplaire_erg, cc4r (backoffice)
* - remarks, jury_points, exemplaire_baiu, exemplaire_erg, cc2r (backoffice)
* - is_published
*/
@@ -65,8 +64,6 @@ function buildPost(Database $db, array $overrides = []): array
'orientation' => (string)$orientations[0]['id'],
'ap' => (string)$apPrograms[0]['id'],
'finality' => (string)$finalityTypes[0]['id'],
'duration_pages' => '120',
'duration_minutes' => '',
'has_annexes' => '',
'languages' => [(string)$languages[0]['id']],
'language_autre' => '',
@@ -160,44 +157,9 @@ try {
echo "\n";
// =========================================================================
// TEST 2: Create — duration_pages saved as individual column
// TEST 2: Create — language_autre creates and links new language
// =========================================================================
echo "Test 2: Create — duration_pages saved as individual column\n";
$post = buildPost($db, [
'titre' => 'Duration pages test',
'duration_pages' => '84',
]);
$thesisId = $createCtrl->submit($post, []);
$createdIds[] = $thesisId;
$raw = $db->getThesisRawFields($thesisId);
assertEq(84, (int)$raw['duration_pages'], 'duration_pages column saved');
assertEq(null, $raw['duration_minutes'], 'duration_minutes null when not set');
echo "\n";
// =========================================================================
// TEST 3: Create — duration_minutes saved as individual column
// =========================================================================
echo "Test 3: Create — duration_minutes saved as individual column\n";
$post = buildPost($db, [
'titre' => 'Duration minutes test',
'duration_pages' => '',
'duration_minutes' => '42',
]);
$thesisId = $createCtrl->submit($post, []);
$createdIds[] = $thesisId;
$raw = $db->getThesisRawFields($thesisId);
assertEq(null, $raw['duration_pages'], 'duration_pages null when not set');
assertEq(42, (int)$raw['duration_minutes'], 'duration_minutes column saved');
echo "\n";
// =========================================================================
// TEST 4: Create — language_autre creates and links new language
// =========================================================================
echo "Test 4: Create — language_autre creates and links new language\n";
echo "Test 2: Create — language_autre creates and links new language\n";
$uniqueLang = 'TestLang_' . bin2hex(random_bytes(4));
$post = buildPost($db, [
'titre' => 'Language autre test',
@@ -219,7 +181,7 @@ try {
echo "\n";
// =========================================================================
// TEST 5: Create — language_autre + checkbox together
// TEST 3: Create — language_autre + checkbox together
// =========================================================================
echo "Test 5: Create — language_autre appended alongside checked languages\n";
$db2 = Database::getInstance();
@@ -245,45 +207,9 @@ try {
echo "\n";
// =========================================================================
// TEST 6: Edit — duration_pages / duration_minutes updated
// TEST 4: Edit — language checkboxes round-trip
// =========================================================================
echo "Test 6: Edit — duration_pages / duration_minutes updated\n";
$post = buildPost($db, ['titre' => 'Edit duration test']);
$thesisId = $createCtrl->submit($post, []);
$createdIds[] = $thesisId;
$editPost = buildPost($db, [
'titre' => 'Edit duration test',
'duration_pages' => '99',
'duration_minutes' => '30',
]);
$editCtrl->save($thesisId, $editPost, []);
$raw = $db->getThesisRawFields($thesisId);
assertEq(99, (int)$raw['duration_pages'], 'duration_pages updated on edit');
assertEq(30, (int)$raw['duration_minutes'], 'duration_minutes updated on edit');
echo "\n";
// =========================================================================
// TEST 7: Edit — clearing duration_pages saves null
// =========================================================================
echo "Test 7: Edit — clearing duration_pages saves null\n";
$editPost = buildPost($db, [
'titre' => 'Edit duration test',
'duration_pages' => '',
'duration_minutes' => '',
]);
$editCtrl->save($thesisId, $editPost, []);
$raw = $db->getThesisRawFields($thesisId);
assertEq(null, $raw['duration_pages'], 'duration_pages cleared to null');
assertEq(null, $raw['duration_minutes'], 'duration_minutes cleared to null');
echo "\n";
// =========================================================================
// TEST 8: Edit — languages pre-populated (checkboxes round-trip)
// =========================================================================
echo "Test 8: Edit — language checkboxes round-trip\n";
echo "Test 3: Edit — language checkboxes round-trip\n";
$allLangs = $db->getAllLanguages();
$lang1 = (string)$allLangs[0]['id'];
$lang2 = (string)$allLangs[1]['id'];
@@ -307,9 +233,9 @@ try {
echo "\n";
// =========================================================================
// TEST 9: Edit — language_autre adds new language
// TEST 5: Edit — language_autre adds new language
// =========================================================================
echo "Test 9: Edit — language_autre creates and links on edit\n";
echo "Test 4: Edit — language_autre creates and links on edit\n";
$uniqueLang3 = 'EditLang_' . bin2hex(random_bytes(4));
$editPost = buildPost($db, [
'titre' => 'Lang checkbox test',
@@ -327,9 +253,9 @@ try {
echo "\n";
// =========================================================================
// TEST 10: Create — backoffice fields persisted
// TEST 6: Create — backoffice fields persisted
// =========================================================================
echo "Test 10: Create — backoffice fields (remarks, jury_points, exemplaires, cc4r)\n";
echo "Test 5: Create — backoffice fields (remarks, jury_points, exemplaires, cc2r)\n";
$post = buildPost($db, [
'titre' => 'Backoffice fields test',
'remarks' => 'Internal note here',
@@ -347,13 +273,13 @@ try {
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['cc4r'], 'cc4r saved');
assertEq(1, (int)$raw['cc2r'], 'cc2r saved');
echo "\n";
// =========================================================================
// TEST 11: Edit — backoffice fields updated
// TEST 7: Edit — backoffice fields updated
// =========================================================================
echo "Test 11: Edit — backoffice fields updated\n";
echo "Test 6: Edit — backoffice fields updated\n";
$editPost = buildPost($db, [
'titre' => 'Backoffice fields test',
'remarks' => 'Updated note',
@@ -369,13 +295,13 @@ try {
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['cc4r'], 'cc4r cleared');
assertEq(0, (int)$raw['cc2r'], 'cc2r cleared');
echo "\n";
// =========================================================================
// TEST 12: getOrCreateLanguage — idempotent
// TEST 8: getOrCreateLanguage — idempotent
// =========================================================================
echo "Test 12: getOrCreateLanguage — idempotent (same name returns same ID)\n";
echo "Test 7: getOrCreateLanguage — idempotent (same name returns same ID)\n";
$uniqueName = 'Idempotent_' . bin2hex(random_bytes(4));
$id1 = $db->getOrCreateLanguage($uniqueName);
$id2 = $db->getOrCreateLanguage($uniqueName);
@@ -386,28 +312,9 @@ try {
echo "\n";
// =========================================================================
// TEST 13: Create — has_annexes flag in file_size_info
// TEST 9: Edit — context_note saved
// =========================================================================
echo "Test 13: Create — has_annexes appended to file_size_info\n";
$post = buildPost($db, [
'titre' => 'Annexes test',
'duration_pages' => '50',
'has_annexes' => '1',
]);
$thesisId = $createCtrl->submit($post, []);
$createdIds[] = $thesisId;
$row = $db->getThesis($thesisId);
assertNotEmpty($row['file_size_info'], 'file_size_info not empty');
if (strpos((string)$row['file_size_info'], 'annexe') === false) {
throw new RuntimeException("FAIL has_annexes: 'annexe' not in file_size_info: " . $row['file_size_info']);
}
echo " ✓ 'annexe' present in file_size_info\n\n";
// =========================================================================
// TEST 14: Edit — context_note saved
// =========================================================================
echo "Test 14: Edit — context_note saved\n";
echo "Test 8: Edit — context_note saved\n";
$post = buildPost($db, ['titre' => 'Context note test']);
$thesisId = $createCtrl->submit($post, []);
$createdIds[] = $thesisId;