mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
- 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
86 lines
2.9 KiB
PHP
86 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Search Functionality Test
|
|
* Tests search queries and results
|
|
*/
|
|
|
|
putenv('DB_ENV=test');
|
|
|
|
require_once __DIR__ . '/../../src/Database.php';
|
|
|
|
echo "Search Functionality Test\n";
|
|
echo "=========================\n\n";
|
|
|
|
try {
|
|
$db = Database::getInstance();
|
|
|
|
// Test 1: Search with empty query
|
|
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";
|
|
} else {
|
|
throw new Exception('Invalid results for empty query');
|
|
}
|
|
|
|
// Test 2: Search for specific term
|
|
echo "Test 2: Search for Specific Term\n";
|
|
$searchTerm = 'art'; // Common word likely to appear
|
|
$results = $db->searchTheses(['query' => $searchTerm]);
|
|
if (is_array($results)) {
|
|
echo "✓ PASS: Search for '$searchTerm' returned " . count($results) . " results\n\n";
|
|
} else {
|
|
throw new Exception('Invalid search results');
|
|
}
|
|
|
|
// Test 3: Search with special characters
|
|
echo "Test 3: Search with Special Characters\n";
|
|
$results = $db->searchTheses(['query' => "test's \"quotes\" & symbols"]);
|
|
if (is_array($results)) {
|
|
echo "✓ PASS: Special characters handled safely\n\n";
|
|
} else {
|
|
throw new Exception('Failed to handle special characters');
|
|
}
|
|
|
|
// Test 4: Tag-filter search using the new EXISTS subquery
|
|
echo "Test 4: Tag-filter search (thesis_tags subquery)\n";
|
|
$tagResults = $db->searchTheses(['keyword' => 'urbanisme']);
|
|
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 "\n";
|
|
} else {
|
|
throw new Exception('Tag search returned non-array');
|
|
}
|
|
|
|
// Test 5: Tag search in full-text query (query touches tag subquery)
|
|
echo "Test 5: Full-text query includes tag subquery\n";
|
|
$allResults = $db->searchTheses(['query' => 'narration']);
|
|
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');
|
|
}
|
|
|
|
// Test 6: countSearchResults matches searchTheses
|
|
echo "Test 6: countSearchResults consistency\n";
|
|
$params = ['keyword' => 'urbanisme'];
|
|
$count = $db->countSearchResults($params);
|
|
$rows = $db->searchTheses($params, 100);
|
|
if ($count === count($rows)) {
|
|
echo "✓ PASS: count=$count matches row count\n\n";
|
|
} else {
|
|
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";
|
|
return false;
|
|
}
|