mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
Major refactor
- update the structure to have monolithic setup - updated deployments - added live-reloading for devops
This commit is contained in:
58
tests/Unit/DatabaseTest.php
Normal file
58
tests/Unit/DatabaseTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Database Connection Test
|
||||
* Tests basic database connectivity and query functionality
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../lib/Database.php';
|
||||
|
||||
echo "Database Connection Test\n";
|
||||
echo "========================\n\n";
|
||||
|
||||
try {
|
||||
// Test 1: Database connection
|
||||
echo "Test 1: Database Connection\n";
|
||||
$db = Database::getInstance();
|
||||
echo "✓ PASS: Database connection successful\n\n";
|
||||
|
||||
// Test 2: Count published theses
|
||||
echo "Test 2: Count Published Theses\n";
|
||||
$count = $db->countPublishedTheses();
|
||||
if ($count >= 0) {
|
||||
echo "✓ PASS: Found {$count} published theses\n\n";
|
||||
} else {
|
||||
throw new Exception("Invalid count returned");
|
||||
}
|
||||
|
||||
// Test 3: Get published theses
|
||||
echo "Test 3: Get Published Theses\n";
|
||||
$theses = $db->getPublishedTheses(5, 0);
|
||||
if (is_array($theses)) {
|
||||
echo "✓ PASS: Retrieved " . count($theses) . " theses\n\n";
|
||||
} else {
|
||||
throw new Exception("Invalid theses array returned");
|
||||
}
|
||||
|
||||
// Test 4: Get single thesis (if any exist)
|
||||
if (count($theses) > 0) {
|
||||
echo "Test 4: Get Single Thesis\n";
|
||||
$first = $theses[0];
|
||||
$thesis = $db->getThesisById($first['id']);
|
||||
|
||||
if ($thesis && isset($thesis['id'])) {
|
||||
echo "✓ PASS: Successfully retrieved thesis #{$first['id']}\n";
|
||||
echo " Title: " . $thesis['title'] . "\n";
|
||||
echo " Author(s): " . ($thesis['authors'] ?? 'N/A') . "\n";
|
||||
echo " Year: " . $thesis['year'] . "\n\n";
|
||||
} else {
|
||||
throw new Exception("Failed to retrieve thesis by ID");
|
||||
}
|
||||
}
|
||||
|
||||
echo "✅ All database tests passed!\n";
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ FAIL: " . $e->getMessage() . "\n";
|
||||
return false;
|
||||
}
|
||||
54
tests/Unit/RateLimitTest.php
Normal file
54
tests/Unit/RateLimitTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Rate Limit Test
|
||||
* Tests rate limiting functionality
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../lib/RateLimit.php';
|
||||
|
||||
echo "Rate Limit Test\n";
|
||||
echo "===============\n\n";
|
||||
|
||||
try {
|
||||
// Test 1: Rate limit initialization
|
||||
echo "Test 1: Rate Limit Initialization\n";
|
||||
$rateLimit = new RateLimit(5, 60); // 5 requests per minute
|
||||
echo "✓ PASS: RateLimit object created\n\n";
|
||||
|
||||
// Test 2: Check method exists and works
|
||||
echo "Test 2: Check Method\n";
|
||||
$allowed = $rateLimit->check();
|
||||
if (is_bool($allowed)) {
|
||||
echo "✓ PASS: check() returns boolean (allowed: " . ($allowed ? 'yes' : 'no') . ")\n\n";
|
||||
} else {
|
||||
throw new Exception("check() did not return boolean");
|
||||
}
|
||||
|
||||
// Test 3: Headers method
|
||||
echo "Test 3: Send Headers Method\n";
|
||||
ob_start();
|
||||
$rateLimit->sendHeaders();
|
||||
ob_end_clean();
|
||||
echo "✓ PASS: sendHeaders() executed without error\n\n";
|
||||
|
||||
// Test 4: Get reset time
|
||||
echo "Test 4: Get Reset Time\n";
|
||||
$resetTime = $rateLimit->getResetTime();
|
||||
if (is_int($resetTime) && $resetTime >= 0) {
|
||||
echo "✓ PASS: getResetTime() returns valid value ($resetTime seconds)\n\n";
|
||||
} else {
|
||||
throw new Exception("Invalid reset time");
|
||||
}
|
||||
|
||||
// Test 5: Cleanup method
|
||||
echo "Test 5: Cleanup Method\n";
|
||||
$rateLimit->cleanup();
|
||||
echo "✓ PASS: cleanup() executed without error\n\n";
|
||||
|
||||
echo "✅ All rate limit tests passed!\n";
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ FAIL: " . $e->getMessage() . "\n";
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user