-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_portability.php
More file actions
115 lines (101 loc) · 3.92 KB
/
test_portability.php
File metadata and controls
115 lines (101 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Script de prueba para verificar portabilidad de URLs
* Ejecutar desde diferentes dominios/carpetas para validar configuración
*/
// Simular diferentes entornos
$testEnvironments = [
[
'name' => 'Producción actual',
'server' => [
'HTTP_HOST' => 'cerberogrowthsolutions.com',
'REQUEST_URI' => '/catai/api/test_portability.php',
'SCRIPT_NAME' => '/catai/api/test_portability.php',
'HTTPS' => 'on'
]
],
[
'name' => 'Subcarpeta diferente',
'server' => [
'HTTP_HOST' => 'midominio.com',
'REQUEST_URI' => '/miapp/api/test_portability.php',
'SCRIPT_NAME' => '/miapp/api/test_portability.php',
'HTTPS' => 'on'
]
],
[
'name' => 'Raíz del dominio',
'server' => [
'HTTP_HOST' => 'otrodominio.com',
'REQUEST_URI' => '/api/test_portability.php',
'SCRIPT_NAME' => '/api/test_portability.php',
'HTTPS' => 'on'
]
],
[
'name' => 'Desarrollo local',
'server' => [
'HTTP_HOST' => 'localhost:8000',
'REQUEST_URI' => '/api/test_portability.php',
'SCRIPT_NAME' => '/api/test_portability.php'
]
]
];
require_once 'api/config.php';
require_once 'api/helpers.php';
echo "<h1>Prueba de Portabilidad CATAI</h1>";
echo "<p>Entorno actual detectado:</p>";
echo "<ul>";
echo "<li><strong>BASE_URL:</strong> " . $BASE_URL . "</li>";
echo "<li><strong>API_BASE_URL:</strong> " . $CONFIG['API_BASE_URL'] . "</li>";
echo "<li><strong>getApiUrl():</strong> " . getApiUrl() . "</li>";
echo "<li><strong>getApiUrl('auth_me.php'):</strong> " . getApiUrl('auth_me.php') . "</li>";
echo "</ul>";
echo "<h2>Simulación de diferentes entornos:</h2>";
foreach ($testEnvironments as $env) {
echo "<h3>{$env['name']}</h3>";
echo "<ul>";
// Simular variables del servidor
$originalServer = $_SERVER;
$_SERVER = array_merge($_SERVER, $env['server']);
// Recargar configuración
$testConfig = require 'api/config.php';
require_once 'api/helpers.php'; // Recargar helpers
echo "<li><strong>HTTP_HOST:</strong> " . ($_SERVER['HTTP_HOST'] ?? 'N/A') . "</li>";
echo "<li><strong>SCRIPT_NAME:</strong> " . ($_SERVER['SCRIPT_NAME'] ?? 'N/A') . "</li>";
echo "<li><strong>Detectado BASE_URL:</strong> " . ($testConfig['BASE_URL'] ?? 'ERROR') . "</li>";
echo "<li><strong>Detectado API_BASE_URL:</strong> " . ($testConfig['API_BASE_URL'] ?? 'ERROR') . "</li>";
echo "<li><strong>getApiUrl():</strong> " . (function_exists('getApiUrl') ? getApiUrl() : 'ERROR') . "</li>";
echo "<li><strong>getApiUrl('test.php'):</strong> " . (function_exists('getApiUrl') ? getApiUrl('test.php') : 'ERROR') . "</li>";
// Restaurar servidor original
$_SERVER = $originalServer;
echo "</ul>";
}
echo "<h2>Configuración CORS:</h2>";
echo "<pre>" . json_encode($CONFIG['ALLOWED_ORIGINS'], JSON_PRETTY_PRINT) . "</pre>";
echo "<h2>Estado de portabilidad:</h2>";
$issues = [];
if (strpos($BASE_URL, 'cerberogrowthsolutions.com') !== false && strpos($BASE_URL, 'localhost') === false) {
$issues[] = "⚠️ BASE_URL contiene dominio hardcodeado";
}
if (function_exists('getApiUrl')) {
$testUrl = getApiUrl('test.php');
if (strpos($testUrl, 'cerberogrowthsolutions.com') !== false && strpos($testUrl, 'localhost') === false) {
$issues[] = "⚠️ getApiUrl() retorna URL hardcodeada";
} else {
echo "<p>✅ getApiUrl() usa detección automática</p>";
}
} else {
$issues[] = "❌ getApiUrl() no está definida";
}
if (empty($issues)) {
echo "<p style='color: green; font-weight: bold;'>✅ Configuración completamente portable</p>";
} else {
echo "<p style='color: red; font-weight: bold;'>❌ Problemas encontrados:</p>";
echo "<ul>";
foreach ($issues as $issue) {
echo "<li>$issue</li>";
}
echo "</ul>";
}
?>