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
89 lines
3.1 KiB
PHP
Executable File
89 lines
3.1 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
/**
|
|
* XAMXAM Test Runner
|
|
* Runs all tests in the tests/ directory
|
|
*/
|
|
|
|
echo "╔════════════════════════════════════════════╗\n";
|
|
echo "║ XAMXAM Test Suite ║\n";
|
|
echo "╚════════════════════════════════════════════╝\n\n";
|
|
|
|
$testFiles = [
|
|
['name' => 'Database (Unit)', 'path' => __DIR__ . '/Unit/DatabaseTest.php'],
|
|
['name' => 'Rate Limit (Unit)', 'path' => __DIR__ . '/Unit/RateLimitTest.php'],
|
|
['name' => 'Search (Integration)', 'path' => __DIR__ . '/Integration/SearchTest.php'],
|
|
['name' => 'Security', 'path' => __DIR__ . '/Security/SecurityTest.php'],
|
|
];
|
|
|
|
$totalTests = 0;
|
|
$passedTests = 0;
|
|
$failedTests = 0;
|
|
$skippedTests = 0;
|
|
|
|
foreach ($testFiles as $test) {
|
|
echo "┌─────────────────────────────────────────┐\n";
|
|
echo '│ ' . str_pad($test['name'], 41) . "│\n";
|
|
echo "└─────────────────────────────────────────┘\n\n";
|
|
|
|
$totalTests++;
|
|
$path = $test['path'];
|
|
$file = basename($path);
|
|
|
|
if (!file_exists($path)) {
|
|
echo "⚠️ SKIP: $file (not found)\n\n";
|
|
$skippedTests++;
|
|
continue;
|
|
}
|
|
|
|
ob_start();
|
|
$exitCode = 0;
|
|
$testResult = false;
|
|
|
|
try {
|
|
$testResult = include $path;
|
|
|
|
// Check if test returned false or had error indicators in output
|
|
$output = ob_get_contents();
|
|
if ($testResult === false ||
|
|
strpos($output, '❌') !== false ||
|
|
strpos($output, 'FAIL:') !== false) {
|
|
$exitCode = 1;
|
|
}
|
|
} catch (Exception $e) {
|
|
$exitCode = 1;
|
|
echo '❌ EXCEPTION: ' . $e->getMessage() . "\n";
|
|
}
|
|
|
|
$output = ob_get_clean();
|
|
echo $output;
|
|
|
|
if ($exitCode === 0 && $testResult !== false) {
|
|
echo "\n✅ TEST PASSED\n\n";
|
|
$passedTests++;
|
|
} else {
|
|
echo "\n❌ TEST FAILED\n\n";
|
|
$failedTests++;
|
|
}
|
|
}
|
|
|
|
echo "╔════════════════════════════════════════════╗\n";
|
|
echo "║ Test Summary ║\n";
|
|
echo "╠════════════════════════════════════════════╣\n";
|
|
echo '║ Total: ' . str_pad($totalTests, 34) . "║\n";
|
|
echo '║ Passed: ' . str_pad($passedTests . ' ✅', 35) . "║\n";
|
|
echo '║ Failed: ' . str_pad($failedTests . ($failedTests > 0 ? ' ❌' : ''), 35) . "║\n";
|
|
if ($skippedTests > 0) {
|
|
echo '║ Skipped: ' . str_pad($skippedTests . ' ⚠️', 36) . "║\n";
|
|
}
|
|
echo "╚════════════════════════════════════════════╝\n\n";
|
|
|
|
if ($failedTests > 0) {
|
|
echo "❌ Some tests failed!\n";
|
|
exit(1);
|
|
} else {
|
|
echo "✅ All tests passed!\n";
|
|
exit(0);
|
|
}
|