mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Remove duration_pages/duration_minutes/file_size_info; rename cc4r → cc2r in DB and code
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* - autofocusFieldForError()
|
||||
* - detectFileType() — via subclass to access private
|
||||
* - generateAuthorSlug() — accent stripping, uppercase, underscore
|
||||
* - buildFileSizeInfo() — pages, minutes, annexes combinations
|
||||
*
|
||||
* ExportController:
|
||||
* - CSV_HEADERS count matches exportAllTheses() row width
|
||||
@@ -37,7 +36,6 @@ require_once APP_ROOT . '/src/Database.php';
|
||||
require_once APP_ROOT . '/src/RateLimit.php';
|
||||
require_once APP_ROOT . '/src/Controllers/TfeController.php';
|
||||
require_once APP_ROOT . '/src/Controllers/ThesisCreateController.php';
|
||||
require_once APP_ROOT . '/src/Controllers/ThesisEditController.php';
|
||||
require_once APP_ROOT . '/src/Controllers/SearchController.php';
|
||||
require_once APP_ROOT . '/src/Controllers/ExportController.php';
|
||||
|
||||
@@ -101,14 +99,6 @@ class ThesisCreateControllerTestable extends ThesisCreateController
|
||||
}
|
||||
}
|
||||
|
||||
class ThesisEditControllerTestable extends ThesisEditController
|
||||
{
|
||||
public function testBuildFileSizeInfo(array $post): string
|
||||
{
|
||||
return $this->buildFileSizeInfo($post);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Setup ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
echo "Pure Logic Unit Test\n";
|
||||
@@ -117,7 +107,6 @@ echo "====================\n\n";
|
||||
$db = Database::getInstance();
|
||||
$tfe = new TfeControllerTestable($db);
|
||||
$createCtrl = new ThesisCreateControllerTestable($db);
|
||||
$editCtrl = new ThesisEditControllerTestable($db);
|
||||
|
||||
try {
|
||||
|
||||
@@ -338,44 +327,10 @@ try {
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
// SECTION C: ThesisEditController — buildFileSizeInfo
|
||||
// SECTION C: ExportController — CSV column count consistency
|
||||
// =========================================================================
|
||||
|
||||
echo "C1: buildFileSizeInfo — pages only\n";
|
||||
$info = $editCtrl->testBuildFileSizeInfo(['duration_pages' => '84', 'duration_minutes' => '']);
|
||||
plAssertEq('84 pages', $info, 'pages only');
|
||||
echo "\n";
|
||||
|
||||
echo "C2: buildFileSizeInfo — minutes only\n";
|
||||
$info = $editCtrl->testBuildFileSizeInfo(['duration_pages' => '', 'duration_minutes' => '32']);
|
||||
plAssertEq('32 minutes', $info, 'minutes only');
|
||||
echo "\n";
|
||||
|
||||
echo "C3: buildFileSizeInfo — pages + minutes\n";
|
||||
$info = $editCtrl->testBuildFileSizeInfo(['duration_pages' => '84', 'duration_minutes' => '32']);
|
||||
plAssertEq('84 pages + 32 minutes', $info, 'pages + minutes');
|
||||
echo "\n";
|
||||
|
||||
echo "C4: buildFileSizeInfo — annexes appended\n";
|
||||
$info = $editCtrl->testBuildFileSizeInfo(['duration_pages' => '50', 'duration_minutes' => '', 'has_annexes' => '1']);
|
||||
plAssertEq('50 pages + annexe(s)', $info, 'annexes appended');
|
||||
echo "\n";
|
||||
|
||||
echo "C5: buildFileSizeInfo — annexes only (no pages/minutes)\n";
|
||||
$info = $editCtrl->testBuildFileSizeInfo(['duration_pages' => '', 'duration_minutes' => '', 'has_annexes' => '1']);
|
||||
plAssertEq('Annexe(s)', $info, 'annexes only');
|
||||
echo "\n";
|
||||
|
||||
echo "C6: buildFileSizeInfo — empty fields = empty string\n";
|
||||
$info = $editCtrl->testBuildFileSizeInfo(['duration_pages' => '', 'duration_minutes' => '']);
|
||||
plAssertEq('', $info, 'empty when nothing set');
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
// SECTION D: ExportController — CSV column count consistency
|
||||
// =========================================================================
|
||||
|
||||
echo "D1: ExportController — CSV_HEADERS count matches row column count\n";
|
||||
echo "C1: ExportController — CSV_HEADERS count matches row column count\n";
|
||||
$export = new ExportController($db);
|
||||
$rows = $export->exportAllTheses();
|
||||
$headerCount = count(ExportController::CSV_HEADERS);
|
||||
@@ -397,10 +352,10 @@ try {
|
||||
echo "\n";
|
||||
|
||||
// =========================================================================
|
||||
// SECTION E: SearchController — coverMap key always present (regression)
|
||||
// SECTION D: SearchController — coverMap key always present (regression)
|
||||
// =========================================================================
|
||||
|
||||
echo "E1: SearchController::handleSearch() — coverMap key always in return array\n";
|
||||
echo "D1: SearchController::handleSearch() — coverMap key always in return array\n";
|
||||
// Simulate $_GET for the method (it reads from $_GET directly via collectSearchParams)
|
||||
$_GET = ['query' => ''];
|
||||
$rateLimit = new RateLimit(1000, 60);
|
||||
|
||||
@@ -213,7 +213,7 @@ try {
|
||||
|
||||
$anyLink = $model->create($adminId, null, null, 'invalid_value');
|
||||
$createdIds[] = $anyLink['id'];
|
||||
slAssertEq(null, $anyLink['objet_restriction'], 'invalid objet_restriction stored as null');
|
||||
slAssertEq('tfe', $anyLink['objet_restriction'], 'invalid objet_restriction defaults to tfe');
|
||||
echo "\n";
|
||||
|
||||
echo "✅ All ShareLink tests passed!\n";
|
||||
|
||||
Reference in New Issue
Block a user