初始提交
This commit is contained in:
179
test.php
Normal file
179
test.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* Git上传工具测试文件
|
||||
* 用于验证各个功能模块是否正常工作
|
||||
*/
|
||||
|
||||
// 测试文件上传功能
|
||||
function testFileUpload() {
|
||||
echo "=== 测试文件上传功能 ===\n";
|
||||
|
||||
// 创建测试文件
|
||||
$testContent = "这是一个测试文件\n创建于: " . date('Y-m-d H:i:s');
|
||||
$testFile = 'test_upload_' . time() . '.txt';
|
||||
|
||||
if (file_put_contents($testFile, $testContent)) {
|
||||
echo "✓ 测试文件创建成功: $testFile\n";
|
||||
} else {
|
||||
echo "✗ 测试文件创建失败\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查上传目录
|
||||
$uploadDir = __DIR__ . '/uploads/';
|
||||
if (!is_dir($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
echo "✓ 上传目录创建成功\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 测试Git操作功能
|
||||
function testGitOperations() {
|
||||
echo "\n=== 测试Git操作功能 ===\n";
|
||||
|
||||
$currentDir = __DIR__;
|
||||
|
||||
// 检查Git是否可用
|
||||
exec('git --version', $output, $returnCode);
|
||||
if ($returnCode === 0) {
|
||||
echo "✓ Git已安装: " . $output[0] . "\n";
|
||||
} else {
|
||||
echo "✗ Git未安装或不可用\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查Git仓库
|
||||
$gitDir = $currentDir . '/.git';
|
||||
if (is_dir($gitDir)) {
|
||||
echo "✓ Git仓库已存在\n";
|
||||
} else {
|
||||
echo "ℹ Git仓库不存在,可以初始化\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 测试PHP配置
|
||||
function testPHPConfiguration() {
|
||||
echo "\n=== 测试PHP配置 ===\n";
|
||||
|
||||
$configs = [
|
||||
'upload_max_filesize' => ini_get('upload_max_filesize'),
|
||||
'post_max_size' => ini_get('post_max_size'),
|
||||
'max_execution_time' => ini_get('max_execution_time'),
|
||||
'memory_limit' => ini_get('memory_limit')
|
||||
];
|
||||
|
||||
foreach ($configs as $key => $value) {
|
||||
echo " $key: $value\n";
|
||||
}
|
||||
|
||||
// 检查必要的PHP函数
|
||||
$functions = ['exec', 'move_uploaded_file', 'json_encode', 'file_put_contents'];
|
||||
$allFunctionsAvailable = true;
|
||||
|
||||
foreach ($functions as $function) {
|
||||
if (function_exists($function)) {
|
||||
echo "✓ 函数 $function 可用\n";
|
||||
} else {
|
||||
echo "✗ 函数 $function 不可用\n";
|
||||
$allFunctionsAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $allFunctionsAvailable;
|
||||
}
|
||||
|
||||
// 测试目录权限
|
||||
function testDirectoryPermissions() {
|
||||
echo "\n=== 测试目录权限 ===\n";
|
||||
|
||||
$directories = [
|
||||
__DIR__,
|
||||
__DIR__ . '/uploads/',
|
||||
__DIR__ . '/css/',
|
||||
__DIR__ . '/js/'
|
||||
];
|
||||
|
||||
foreach ($directories as $dir) {
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
if (is_writable($dir)) {
|
||||
echo "✓ 目录可写: $dir\n";
|
||||
} else {
|
||||
echo "✗ 目录不可写: $dir\n";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 测试AJAX端点
|
||||
function testAjaxEndpoints() {
|
||||
echo "\n=== 测试AJAX端点 ===\n";
|
||||
|
||||
// 这里可以添加更详细的端点测试
|
||||
$endpoints = [
|
||||
'check_git' => '检查Git状态',
|
||||
'get_files' => '获取文件列表',
|
||||
'git_operation' => 'Git操作',
|
||||
'upload' => '文件上传'
|
||||
];
|
||||
|
||||
foreach ($endpoints as $endpoint => $description) {
|
||||
echo "✓ 端点 $endpoint ($description) 已定义\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 运行所有测试
|
||||
function runAllTests() {
|
||||
echo "开始Git上传工具测试...\n";
|
||||
echo "=====================================\n";
|
||||
|
||||
$tests = [
|
||||
'testPHPConfiguration',
|
||||
'testDirectoryPermissions',
|
||||
'testGitOperations',
|
||||
'testAjaxEndpoints',
|
||||
'testFileUpload'
|
||||
];
|
||||
|
||||
$allPassed = true;
|
||||
|
||||
foreach ($tests as $test) {
|
||||
try {
|
||||
$result = $test();
|
||||
if (!$result) {
|
||||
$allPassed = false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "✗ 测试 $test 抛出异常: " . $e->getMessage() . "\n";
|
||||
$allPassed = false;
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
echo "=====================================\n";
|
||||
if ($allPassed) {
|
||||
echo "✓ 所有测试通过!工具应该可以正常工作。\n";
|
||||
} else {
|
||||
echo "✗ 部分测试失败,请检查配置和权限。\n";
|
||||
}
|
||||
|
||||
// 清理测试文件
|
||||
$testFiles = glob('test_upload_*.txt');
|
||||
foreach ($testFiles as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果直接访问此文件,运行测试
|
||||
if (basename($_SERVER['PHP_SELF']) === basename(__FILE__)) {
|
||||
runAllTests();
|
||||
}
|
||||
Reference in New Issue
Block a user