"; echo "🧪 Test API"; echo ""; echo "

🧪 TEST DE LA API

"; // Lista de endpoints para probar $endpoints = [ 'get_settings.php' => 'Obtener configuración del sistema', 'get_stats.php' => 'Obtener estadísticas', 'get_users.php' => 'Obtener usuarios', 'get_menus.php' => 'Obtener menús', 'get_templates.php' => 'Obtener plantillas' ]; echo "
"; echo "

🚀 PROBANDO ENDPOINTS DE LA API...

"; foreach ($endpoints as $endpoint => $description) { echo "
"; echo "🔗 $endpoint - $description
"; $api_url = 'api/' . $endpoint; // Verificar que el archivo existe if (!file_exists($api_url)) { echo "
❌ Archivo no encontrado: $api_url
"; continue; } echo "
✅ Archivo existe
"; // Intentar ejecutar el endpoint usando output buffering ob_start(); try { // Simular REQUEST_METHOD para endpoints que lo requieran $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? 'localhost'; // Capturar cualquier error $error_before = error_get_last(); // Incluir el archivo de la API include $api_url; // Obtener la salida $output = ob_get_contents(); // Verificar errores $error_after = error_get_last(); if ($error_after && $error_after !== $error_before) { echo "
❌ Error PHP: " . htmlspecialchars($error_after['message']) . "
"; echo "
Línea: " . $error_after['line'] . " en " . basename($error_after['file']) . "
"; } else { // Verificar si la salida parece ser JSON válido if (!empty($output)) { $json_data = json_decode($output, true); if (json_last_error() === JSON_ERROR_NONE) { echo "
✅ Respuesta JSON válida (" . strlen($output) . " caracteres)
"; // Mostrar estructura básica if (is_array($json_data)) { $keys = array_keys($json_data); $preview_keys = array_slice($keys, 0, 3); echo "
📋 Claves: " . implode(', ', $preview_keys); if (count($keys) > 3) echo " (+" . (count($keys) - 3) . " más)"; echo "
"; } } else { echo "
⚠️ Salida no es JSON válido
"; if (strlen($output) < 200) { echo "
Salida: " . htmlspecialchars(substr($output, 0, 100)) . "
"; } } } else { echo "
⚠️ Sin salida
"; } } } catch (ParseError $e) { echo "
❌ Error de sintaxis: " . htmlspecialchars($e->getMessage()) . "
"; echo "
Línea: " . $e->getLine() . "
"; } catch (Error $e) { echo "
❌ Error fatal: " . htmlspecialchars($e->getMessage()) . "
"; echo "
Archivo: " . basename($e->getFile()) . " línea " . $e->getLine() . "
"; } catch (Exception $e) { echo "
❌ Excepción: " . htmlspecialchars($e->getMessage()) . "
"; } finally { ob_end_clean(); } echo "
"; } echo "
"; // Test directo de carga de configuración desde API echo "
"; echo "

⚙️ TEST DIRECTO DE CONFIGURACIÓN...

"; echo "
🔄 Simulando carga desde directorio API...
"; // Cambiar al directorio API temporalmente $original_dir = getcwd(); try { chdir('api'); echo "
✅ Cambiado a directorio API
"; // Intentar cargar la configuración if (file_exists('../config/config.php')) { echo "
✅ ../config/config.php existe desde API
"; try { require_once '../config/config.php'; echo "
✅ Configuración cargada exitosamente
"; // Verificar algunas constantes $test_constants = ['DB_HOST', 'DB_NAME', 'DB_USER', 'SECRET_KEY']; foreach ($test_constants as $const) { if (defined($const)) { echo "
✅ $const definida
"; } else { echo "
❌ $const no definida
"; } } } catch (Exception $e) { echo "
❌ Error cargando config: " . htmlspecialchars($e->getMessage()) . "
"; } } else { echo "
❌ ../config/config.php NO existe desde API
"; } } finally { chdir($original_dir); } echo "
"; // Resumen final echo "
"; echo "

📊 RESUMEN

"; echo "
✅ Rutas de API corregidas
"; echo "
✅ Todos los archivos usan '../config/config.php'
"; echo "
PRÓXIMOS PASOS:
"; echo "
1. Verificar que las tablas existan: test_config.php
"; echo "
2. Si faltan tablas, ejecutar: instalar_bd.php
"; echo "
3. Probar login: login.php
"; echo "
4. Probar panel: index.php
"; echo "
"; echo ""; ?>