mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
feat: prevent duplicate TFE submissions with logging and user feedback
- Add DuplicateThesisException (typed, carries existing thesis metadata) - Add Database::findDuplicateThesis(): matches on year + author + normalised title (exact, prefix, Levenshtein ≤10% of longer string) - ThesisCreateController::submit() runs duplicate check before any DB write and throws DuplicateThesisException on match - AppLogger::logDuplicate() writes status=duplicate entries to the JSON-lines log for audit purposes - App::flash/consumeFlash extended to support 'warning' flash type - admin/actions/formulaire.php: catches DuplicateThesisException, logs it, flashes an HTML warning toast with a clickable link to the existing thesis, and repopulates the form fields - partage/index.php: same catch block; surfaces a plain-text flash-warning banner on the student form with identifier, title, and year of the match; form is repopulated via session - toast.php: renders toast--warning variant - admin.css: .toast--warning + link colour rules - form.css: .flash-warning style for the partage form
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Search Functionality Test
|
||||
* Tests search queries and results
|
||||
@@ -18,9 +19,9 @@ try {
|
||||
echo "Test 1: Empty Search Query\n";
|
||||
$results = $db->searchTheses([]);
|
||||
if (is_array($results)) {
|
||||
echo "✓ PASS: Empty query handled (returned " . count($results) . " results)\n\n";
|
||||
echo '✓ PASS: Empty query handled (returned ' . count($results) . " results)\n\n";
|
||||
} else {
|
||||
throw new Exception("Invalid results for empty query");
|
||||
throw new Exception('Invalid results for empty query');
|
||||
}
|
||||
|
||||
// Test 2: Search for specific term
|
||||
@@ -30,7 +31,7 @@ try {
|
||||
if (is_array($results)) {
|
||||
echo "✓ PASS: Search for '$searchTerm' returned " . count($results) . " results\n\n";
|
||||
} else {
|
||||
throw new Exception("Invalid search results");
|
||||
throw new Exception('Invalid search results');
|
||||
}
|
||||
|
||||
// Test 3: Search with special characters
|
||||
@@ -39,7 +40,7 @@ try {
|
||||
if (is_array($results)) {
|
||||
echo "✓ PASS: Special characters handled safely\n\n";
|
||||
} else {
|
||||
throw new Exception("Failed to handle special characters");
|
||||
throw new Exception('Failed to handle special characters');
|
||||
}
|
||||
|
||||
// Test 4: Tag-filter search using the new EXISTS subquery
|
||||
@@ -48,11 +49,11 @@ try {
|
||||
if (is_array($tagResults)) {
|
||||
echo "✓ PASS: Tag search for 'urbanisme' returned " . count($tagResults) . " result(s)\n";
|
||||
foreach ($tagResults as $r) {
|
||||
echo " - " . $r['title'] . " (" . $r['year'] . ")\n";
|
||||
echo ' - ' . $r['title'] . ' (' . $r['year'] . ")\n";
|
||||
}
|
||||
echo "\n";
|
||||
} else {
|
||||
throw new Exception("Tag search returned non-array");
|
||||
throw new Exception('Tag search returned non-array');
|
||||
}
|
||||
|
||||
// Test 5: Tag search in full-text query (query touches tag subquery)
|
||||
@@ -61,7 +62,7 @@ try {
|
||||
if (is_array($allResults)) {
|
||||
echo "✓ PASS: Query 'narration' returned " . count($allResults) . " result(s)\n\n";
|
||||
} else {
|
||||
throw new Exception("Full-text query with tag subquery failed");
|
||||
throw new Exception('Full-text query with tag subquery failed');
|
||||
}
|
||||
|
||||
// Test 6: countSearchResults matches searchTheses
|
||||
@@ -72,13 +73,13 @@ try {
|
||||
if ($count === count($rows)) {
|
||||
echo "✓ PASS: count=$count matches row count\n\n";
|
||||
} else {
|
||||
throw new Exception("countSearchResults ($count) != searchTheses row count (" . count($rows) . ")");
|
||||
throw new Exception("countSearchResults ($count) != searchTheses row count (" . count($rows) . ')');
|
||||
}
|
||||
|
||||
echo "✅ All search tests passed!\n";
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ FAIL: " . $e->getMessage() . "\n";
|
||||
echo '❌ FAIL: ' . $e->getMessage() . "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user