23-01-2026
This commit is contained in:
parent
8fd1f4d451
commit
389d5d1820
59 changed files with 9642 additions and 883 deletions
249
dev/frontend-navigation/test-api.php
Normal file
249
dev/frontend-navigation/test-api.php
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Test-Script für die Navigation API
|
||||
*
|
||||
* Dieses Script testet alle verfügbaren Endpunkte der Navigation API
|
||||
* und zeigt die Ergebnisse in einer strukturierten Form.
|
||||
*
|
||||
* Verwendung:
|
||||
* 1. Passe die BASE_URL an deine Umgebung an
|
||||
* 2. Führe aus: php test-api.php
|
||||
*/
|
||||
|
||||
// Konfiguration
|
||||
define('BASE_URL', 'http://localhost'); // Passe dies an deine Umgebung an
|
||||
define('API_PREFIX', '/api/navigation');
|
||||
|
||||
// Terminal Farben
|
||||
define('COLOR_GREEN', "\033[0;32m");
|
||||
define('COLOR_RED', "\033[0;31m");
|
||||
define('COLOR_YELLOW', "\033[0;33m");
|
||||
define('COLOR_BLUE', "\033[0;34m");
|
||||
define('COLOR_RESET', "\033[0m");
|
||||
|
||||
/**
|
||||
* Führt einen API-Request aus
|
||||
*/
|
||||
function apiRequest($endpoint, $method = 'GET')
|
||||
{
|
||||
$url = BASE_URL . API_PREFIX . $endpoint;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$startTime = microtime(true);
|
||||
$response = curl_exec($ch);
|
||||
$endTime = microtime(true);
|
||||
$duration = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => $error,
|
||||
'duration' => $duration
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'http_code' => $httpCode,
|
||||
'data' => json_decode($response, true),
|
||||
'duration' => $duration
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausgabe-Helfer
|
||||
*/
|
||||
function printHeader($text)
|
||||
{
|
||||
echo "\n" . COLOR_BLUE . str_repeat('=', 80) . COLOR_RESET . "\n";
|
||||
echo COLOR_BLUE . $text . COLOR_RESET . "\n";
|
||||
echo COLOR_BLUE . str_repeat('=', 80) . COLOR_RESET . "\n\n";
|
||||
}
|
||||
|
||||
function printSuccess($text)
|
||||
{
|
||||
echo COLOR_GREEN . "✓ " . $text . COLOR_RESET . "\n";
|
||||
}
|
||||
|
||||
function printError($text)
|
||||
{
|
||||
echo COLOR_RED . "✗ " . $text . COLOR_RESET . "\n";
|
||||
}
|
||||
|
||||
function printInfo($text)
|
||||
{
|
||||
echo COLOR_YELLOW . "ℹ " . $text . COLOR_RESET . "\n";
|
||||
}
|
||||
|
||||
function printJson($data, $maxDepth = 3, $currentDepth = 0)
|
||||
{
|
||||
if ($currentDepth >= $maxDepth) {
|
||||
echo "[... gekürzt nach Tiefe $maxDepth]\n";
|
||||
return;
|
||||
}
|
||||
|
||||
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet einen einzelnen Endpunkt
|
||||
*/
|
||||
function testEndpoint($name, $endpoint, $method = 'GET', $showFullData = false)
|
||||
{
|
||||
printInfo("Teste: $name");
|
||||
echo " Endpunkt: $endpoint\n";
|
||||
echo " Methode: $method\n";
|
||||
|
||||
$result = apiRequest($endpoint, $method);
|
||||
|
||||
if (!$result['success']) {
|
||||
printError("Request fehlgeschlagen: " . $result['error']);
|
||||
return false;
|
||||
}
|
||||
|
||||
$httpCode = $result['http_code'];
|
||||
$data = $result['data'];
|
||||
$duration = $result['duration'];
|
||||
|
||||
echo " HTTP Status: $httpCode\n";
|
||||
echo " Dauer: {$duration}ms\n";
|
||||
|
||||
if ($httpCode === 200) {
|
||||
printSuccess("Erfolgreich");
|
||||
|
||||
if (isset($data['success']) && $data['success']) {
|
||||
if (isset($data['meta'])) {
|
||||
echo "\n Metadaten:\n";
|
||||
foreach ($data['meta'] as $key => $value) {
|
||||
echo " $key: $value\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($showFullData && isset($data['data'])) {
|
||||
echo "\n Daten (gekürzt):\n";
|
||||
$preview = $data['data'];
|
||||
if (is_array($preview) && count($preview) > 2) {
|
||||
$preview = array_slice($preview, 0, 2);
|
||||
echo " " . json_encode($preview, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
|
||||
echo " ... und " . (count($data['data']) - 2) . " weitere Einträge\n";
|
||||
} else {
|
||||
printJson($preview, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printError("HTTP-Fehler $httpCode");
|
||||
if (isset($data['error'])) {
|
||||
echo " Fehlermeldung: " . $data['error'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
return $httpCode === 200;
|
||||
}
|
||||
|
||||
// Hauptprogramm
|
||||
printHeader("Navigation API Test Suite");
|
||||
|
||||
echo "Base URL: " . BASE_URL . "\n";
|
||||
echo "API Prefix: " . API_PREFIX . "\n\n";
|
||||
|
||||
$results = [];
|
||||
|
||||
// Test 1: Kompletter Navigationsbaum
|
||||
printHeader("Test 1: Kompletter Navigationsbaum");
|
||||
$results['tree'] = testEndpoint(
|
||||
"Kompletter Navigationsbaum",
|
||||
"/tree",
|
||||
"GET",
|
||||
true
|
||||
);
|
||||
|
||||
// Test 2: Nur aktive Navigationspunkte
|
||||
printHeader("Test 2: Nur aktive Navigationspunkte");
|
||||
$results['tree_active'] = testEndpoint(
|
||||
"Aktive Navigationspunkte",
|
||||
"/tree/active",
|
||||
"GET",
|
||||
true
|
||||
);
|
||||
|
||||
// Test 3: Teilbaum (ersetze 1 mit einer existierenden Page-ID)
|
||||
printHeader("Test 3: Teilbaum ab Root-ID 1");
|
||||
$results['subtree'] = testEndpoint(
|
||||
"Teilbaum ab Root-ID 1",
|
||||
"/tree/1",
|
||||
"GET",
|
||||
true
|
||||
);
|
||||
|
||||
// Test 4: Flache Liste
|
||||
printHeader("Test 4: Flache Liste aller Navigationspunkte");
|
||||
$results['flat'] = testEndpoint(
|
||||
"Flache Liste",
|
||||
"/flat",
|
||||
"GET",
|
||||
true
|
||||
);
|
||||
|
||||
// Test 5: Breadcrumb (ersetze 1 mit einer existierenden Page-ID)
|
||||
printHeader("Test 5: Breadcrumb für Page-ID 1");
|
||||
$results['breadcrumb'] = testEndpoint(
|
||||
"Breadcrumb für Page-ID 1",
|
||||
"/breadcrumb/1",
|
||||
"GET",
|
||||
true
|
||||
);
|
||||
|
||||
// Test 6: Cache leeren
|
||||
printHeader("Test 6: Cache leeren");
|
||||
$results['cache_clear'] = testEndpoint(
|
||||
"Cache leeren",
|
||||
"/cache/clear",
|
||||
"POST",
|
||||
false
|
||||
);
|
||||
|
||||
// Zusammenfassung
|
||||
printHeader("Test-Zusammenfassung");
|
||||
|
||||
$total = count($results);
|
||||
$passed = count(array_filter($results));
|
||||
$failed = $total - $passed;
|
||||
|
||||
echo "Gesamt: $total Tests\n";
|
||||
printSuccess("Erfolgreich: $passed");
|
||||
if ($failed > 0) {
|
||||
printError("Fehlgeschlagen: $failed");
|
||||
}
|
||||
|
||||
$percentage = round(($passed / $total) * 100, 1);
|
||||
echo "\nErfolgsrate: $percentage%\n";
|
||||
|
||||
if ($percentage === 100.0) {
|
||||
printSuccess("\nAlle Tests bestanden! 🎉");
|
||||
} else {
|
||||
printError("\nEinige Tests sind fehlgeschlagen. Bitte überprüfen Sie die Ausgabe oben.");
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
// Weitere Hinweise
|
||||
printHeader("Weitere Informationen");
|
||||
echo "Vollständige API-Dokumentation: dev/frontend-navigation/navigation-api.md\n";
|
||||
echo "README: dev/frontend-navigation/README.md\n\n";
|
||||
echo "Hinweis: Wenn Tests fehlschlagen, überprüfen Sie:\n";
|
||||
echo " 1. Ist die BASE_URL korrekt?\n";
|
||||
echo " 2. Läuft der Server?\n";
|
||||
echo " 3. Sind Page-Einträge in der Datenbank vorhanden?\n";
|
||||
echo " 4. Sind die Routen korrekt registriert?\n\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue