Files
xamxam/tests/Unit/DatabaseTest.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

59 lines
1.7 KiB
PHP

<?php
/**
* Database Connection Test
* Tests basic database connectivity and query functionality
*/
require_once __DIR__ . '/../../src/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;
}