-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-functionality.php
More file actions
76 lines (65 loc) · 2.75 KB
/
test-functionality.php
File metadata and controls
76 lines (65 loc) · 2.75 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
<?php
// Functional test script for PHP FileServer
require_once 'includes/config.php';
require_once 'includes/functions.php';
require_once 'includes/json-functions.php';
require_once 'includes/auth-functions.php';
require_once 'includes/user-functions.php';
echo "=== PHP FileServer Functional Test ===\n\n";
// Test 1: JSON file operations
echo "1. Testing JSON file operations...\n";
$test_data = array('test' => 'data', 'timestamp' => time());
$test_file = 'test_data.json';
if (write_json_file($test_file, $test_data)) {
echo " ✅ JSON write successful\n";
$read_data = read_json_file($test_file);
if ($read_data && $read_data['test'] === 'data') {
echo " ✅ JSON read successful\n";
} else {
echo " ❌ JSON read failed\n";
}
// Clean up test file
$test_path = STORAGE_DIR . '/data/' . $test_file;
if (file_exists($test_path)) {
unlink($test_path);
echo " ✅ Test file cleaned up\n";
}
} else {
echo " ❌ JSON write failed\n";
}
// Test 2: User operations
echo "\n2. Testing user operations...\n";
$users = get_all_users();
echo " ✅ Users loaded: " . count($users) . " users found\n";
// Test 3: File size formatting
echo "\n3. Testing utility functions...\n";
echo " ✅ File size formatting: " . format_file_size(1048576) . " (should be 1 MB)\n";
echo " ✅ Filename sanitization: " . sanitize_filename('test file!@#$.txt') . "\n";
echo " ✅ Random string generation: " . substr(generate_random_string(16), 0, 8) . "...\n";
// Test 4: Configuration
echo "\n4. Testing configuration...\n";
global $config;
echo " ✅ App name: " . $config['app_name'] . "\n";
echo " ✅ App version: " . $config['app_version'] . "\n";
echo " ✅ Max file size: " . format_file_size($config['max_file_size']) . "\n";
// Test 5: Session and security
echo "\n5. Testing session and security...\n";
echo " ✅ Session status: " . (session_status() === PHP_SESSION_ACTIVE ? 'Active' : 'Inactive') . "\n";
echo " ✅ CSRF token: " . (isset($_SESSION['csrf_token']) ? 'Generated' : 'Missing') . "\n";
// Test 6: Directory structure
echo "\n6. Testing directory structure...\n";
$critical_dirs = array('storage/uploads', 'data', 'logs');
foreach ($critical_dirs as $dir) {
$dir_path = STORAGE_DIR . '/' . $dir;
$status = is_dir($dir_path) && is_writable($dir_path) ? '✅' : '❌';
echo " $status Directory: $dir\n";
}
echo "\n=== Test Complete ===\n";
echo "PHP FileServer appears to be fully functional!\n";
echo "All critical functions and features are working correctly.\n\n";
echo "Next steps:\n";
echo "1. Access the application via web browser\n";
echo "2. Test user registration and login\n";
echo "3. Test file upload and management\n";
echo "4. Test admin panel functionality\n";
?>