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:
Pontoporeia
2026-03-24 15:38:36 +01:00
parent 92e344b757
commit 372abb5cd6
6 changed files with 84 additions and 7 deletions

10
TODO.md
View File

@@ -259,8 +259,8 @@ Goal: rename the tables and column to the canonical M2M pattern (`tags`, `thesis
- [x] `public/search.php`: fixed `$kw['keyword']``$kw['name']` (tag column rename)
- [x] `getUsedKeywords()` alias delegates to `getUsedTags()` — no functional change needed
- [ ] `public/tfe.php`: `$data['keywords']` still works (view column name unchanged)
- [ ] `templates/search-bar.php`: no keyword param refs
- [x] `public/tfe.php`: `$data['keywords']` still works view column name unchanged
- [x] `templates/search-bar.php`: no keyword param refs — verified
### 5 — Admin tag management UI (`/admin/tags.php`)
@@ -286,8 +286,8 @@ Goal: rename the tables and column to the canonical M2M pattern (`tags`, `thesis
### 6 — Tests
- [ ] `tests/Unit/DatabaseTest.php`: add test for `findOrCreateTag` round-trip
- [ ] `tests/Integration/SearchTest.php`: add test for tag-filter search using the new subquery
- [x] `tests/Unit/DatabaseTest.php`: tests 57 cover findOrCreateTag, getUsedTags, alias
- [x] `tests/Integration/SearchTest.php`: tests 46 cover tag-filter subquery, full-text query, count consistency
### 6 — Fixtures / seed data
@@ -321,7 +321,7 @@ Goal: rename the tables and column to the canonical M2M pattern (`tags`, `thesis
- [x] Add flake.nix for Nix-based PHP dev environment
- [x] Add favicon (`<link rel="icon">` → admin_favicon.svg) to all pages; nginx 204 for /favicon.ico
- [ ] Add pagination to répertoire student index (currently capped at 100)
- [x] Remove 100-item cap from répertoire student index: `getAllPublishedTheses()` fetches all published theses; search results remain paginated at 30/page
- [ ] Thumbnail generation / cover image support for home grid cards
## Admin / Server

View File

@@ -46,8 +46,8 @@ try {
$orientations = $db->getOrientations();
$apPrograms = $db->getApPrograms();
$keywords = $db->getUsedKeywords();
// Get all published theses for student index (multiple pages if needed)
$students = $db->searchTheses([], 100, 0); // max 100 per DB limit
// Fetch all published theses for the student index (no artificial cap)
$students = $db->getAllPublishedTheses();
} catch (InvalidArgumentException $e) {
$validationError = $e->getMessage();
$results = []; $totalItems = 0; $totalPages = 0;

View File

@@ -402,6 +402,17 @@ class Database {
/**
* Get all available years from published theses
*/
/**
* Return ALL published theses (no cap) — for internal use (student index).
* Not exposed to user-controlled input.
*/
public function getAllPublishedTheses(): array {
$stmt = $this->pdo->query(
"SELECT vp.* FROM v_theses_public vp ORDER BY vp.year DESC, vp.title ASC"
);
return $stmt->fetchAll();
}
public function getAvailableYears() {
$sql = "SELECT DISTINCT year FROM theses WHERE is_published = 1 ORDER BY year DESC";
$stmt = $this->pdo->query($sql);

Binary file not shown.

View File

@@ -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;

View File

@@ -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;