-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_safe_array
More file actions
107 lines (84 loc) · 3.88 KB
/
test_safe_array
File metadata and controls
107 lines (84 loc) · 3.88 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
<?php
/**
* Focused test to verify SafeArray class loading fix
* This specifically tests the SafeArray class that was causing the original fatal error
*/
// Simulate WordPress environment for testing
define('ABSPATH', '/tmp/');
define('SMO_SOCIAL_STANDALONE', true);
// Mock global $wpdb for testing
global $wpdb;
$wpdb = new stdClass();
$wpdb->prefix = 'wp_';
// Mock WordPress functions
if (!function_exists('get_option')) {
function get_option($option, $default = false) {
return $default;
}
}
if (!function_exists('current_time')) {
function current_time($type, $gmt = false) {
return date('Y-m-d H:i:s');
}
}
if (!function_exists('error_log')) {
function error_log($message) {
echo "[ERROR] $message\n";
}
}
echo "=== Testing the Original SafeArray Fatal Error Fix ===\n\n";
try {
// Test the exact scenario from the original error
echo "1. Testing SafeArray class autoloading...\n";
// This simulates what happens in DatabaseProviderLoader line 82:
// $provider_name = SafeArray::get_string($db_provider, 'name', 'unknown');
require_once 'includes/Core/SafeArray.php';
if (!class_exists('SMO_Social\\Core\\SafeArray')) {
throw new Exception("SafeArray class was not loaded properly");
}
echo " ✓ SafeArray class loaded successfully\n";
// Test the exact method call that was failing
echo "\n2. Testing SafeArray::get_string() method (line 82 scenario)...\n";
$db_provider = [
'name' => 'openai',
'display_name' => 'OpenAI',
'status' => 'active'
];
$provider_name = SMO_Social\Core\SafeArray::get_string($db_provider, 'name', 'unknown');
if ($provider_name === 'openai') {
echo " ✓ SafeArray::get_string() working correctly: $provider_name\n";
} else {
throw new Exception("SafeArray::get_string() returned unexpected value: $provider_name");
}
// Test other SafeArray methods used in DatabaseProviderLoader
echo "\n3. Testing other SafeArray methods used in DatabaseProviderLoader...\n";
$json_data = '{"key": "value", "count": 42}';
$decoded = SMO_Social\Core\SafeArray::json_decode($json_data, true, []);
echo " ✓ SafeArray::json_decode() working: " . (is_array($decoded) ? 'array decoded' : 'failed') . "\n";
$bool_value = SMO_Social\Core\SafeArray::get_bool($db_provider, 'is_default', false);
echo " ✓ SafeArray::get_bool() working: " . ($bool_value ? 'true' : 'false') . "\n";
$array_value = SMO_Social\Core\SafeArray::get_array($decoded, 'settings', []);
echo " ✓ SafeArray::get_array() working: " . (is_array($array_value) ? 'array returned' : 'failed') . "\n";
echo "\n=== Original Error Analysis ===\n";
echo "The original fatal error was:\n";
echo " PHP Fatal error: Uncaught Error: Class \"SMO_Social\\Core\\SafeArray\" not found\n";
echo " in DatabaseProviderLoader.php:82\n\n";
echo "Root cause:\n";
echo " - SafeArray class existed in SafeArrayAccessor.php\n";
echo " - But file was named incorrectly for PHP autoloading\n";
echo " - PHP autoloader expects SafeArray.php for SafeArray class\n\n";
echo "Fix applied:\n";
echo " - Renamed SafeArrayAccessor.php to SafeArray.php\n";
echo " - Now PHP can autoload the SafeArray class correctly\n\n";
echo "=== RESULT ===\n";
echo "✓ SUCCESS: The original SafeArray class loading error has been FIXED!\n";
echo "✓ The plugin should now load past the DatabaseProviderLoader initialization.\n";
echo "✓ SafeArray::get_string() and other methods work correctly.\n";
} catch (Exception $e) {
echo "\n=== Test Failed ===\n";
echo "❌ ERROR: " . $e->getMessage() . "\n";
echo "File: " . $e->getFile() . "\n";
echo "Line: " . $e->getLine() . "\n";
echo "\n❌ The SafeArray fix did not work properly.\n";
exit(1);
}