mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: tag management tests, maintenance mode polish, répertoire pagination fix
- tests/Unit/DatabaseTest.php: tests 5-7 for findOrCreateTag round-trip, getUsedTags column, alias - tests/Integration/SearchTest.php: tests 4-6 for tag subquery, full-text query, count consistency - Database: getAllPublishedTheses() bypasses 100-row search cap for student index - search.php: uses getAllPublishedTheses() for étudiantes column; all tests pass
This commit is contained in:
@@ -40,6 +40,39 @@ try {
|
||||
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;
|
||||
|
||||
|
||||
@@ -49,6 +49,39 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// Test 5: findOrCreateTag round-trip
|
||||
echo "Test 5: findOrCreateTag round-trip\n";
|
||||
$testTag = '__test_tag_' . bin2hex(random_bytes(4));
|
||||
$id1 = $db->findOrCreateTag($testTag);
|
||||
$id2 = $db->findOrCreateTag($testTag); // should return same id
|
||||
if ($id1 && $id1 === $id2) {
|
||||
echo "✓ PASS: findOrCreateTag returned consistent id=$id1 for '$testTag'\n\n";
|
||||
// Clean up
|
||||
$db->deleteTag($id1);
|
||||
} else {
|
||||
throw new Exception("findOrCreateTag round-trip failed: id1=$id1, id2=$id2");
|
||||
}
|
||||
|
||||
// Test 6: getUsedTags returns array with 'name' column
|
||||
echo "Test 6: getUsedTags returns name column\n";
|
||||
$tags = $db->getUsedTags();
|
||||
if (is_array($tags) && (empty($tags) || isset($tags[0]['name']))) {
|
||||
echo "✓ PASS: getUsedTags returned " . count($tags) . " tags with 'name' column\n\n";
|
||||
} else {
|
||||
throw new Exception("getUsedTags did not return expected structure: " . json_encode($tags[0] ?? []));
|
||||
}
|
||||
|
||||
// Test 7: backwards-compat alias findOrCreateKeyword
|
||||
echo "Test 7: findOrCreateKeyword alias\n";
|
||||
$testTag2 = '__kw_alias_' . bin2hex(random_bytes(4));
|
||||
$kwId = $db->findOrCreateKeyword($testTag2);
|
||||
if ($kwId > 0) {
|
||||
echo "✓ PASS: findOrCreateKeyword alias works, id=$kwId\n\n";
|
||||
$db->deleteTag($kwId);
|
||||
} else {
|
||||
throw new Exception("findOrCreateKeyword alias failed");
|
||||
}
|
||||
|
||||
echo "✅ All database tests passed!\n";
|
||||
return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user