Files
xamxam/tests/Unit/RateLimitTest.php
Théophile Gervreau-Mercier 0e4921583e refactor: reorganize to standard PHP structure
- Moved /lib → /src (PHP source code)
- Moved /includes → /public/includes (main site templates)
- Admin section remains self-contained in /public/admin with its own /inc
- Updated all require/include paths across codebase
- Updated config/bootstrap.php, justfile, tests, docs
- All tests passing 

Structure now follows PHP best practices:
  /config      - Configuration files
  /database    - SQLite database + schema
  /docs        - Documentation (intact)
  /nginx       - Server config (intact)
  /public      - Web-accessible files (entry point)
    /admin     - Self-contained admin interface
    /assets    - CSS, fonts, icons
    /includes  - Main site templates (header/footer)
  /scripts     - Deployment scripts (intact)
  /src         - PHP source classes (Database, AdminAuth, RateLimit)
  /tests       - Test suites
2026-02-12 12:11:16 +01:00

55 lines
1.5 KiB
PHP

<?php
/**
* Rate Limit Test
* Tests rate limiting functionality
*/
require_once __DIR__ . '/../../src/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;
}