From 34a3001d115796febe040006a0ca72f07ead31d8 Mon Sep 17 00:00:00 2001 From: Tsama <1693710928@qq.com> Date: Sat, 15 Nov 2025 18:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_git_add_commit.php | 44 +++++++++++++++++++++++++++++++ test_git_operations.php | 57 +++++++++++++++++++++++++++++++++++++++++ test_upload.php | 37 ++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 test_git_add_commit.php create mode 100644 test_git_operations.php create mode 100644 test_upload.php diff --git a/test_git_add_commit.php b/test_git_add_commit.php new file mode 100644 index 0000000..227bc9d --- /dev/null +++ b/test_git_add_commit.php @@ -0,0 +1,44 @@ + true, + CURLOPT_POSTFIELDS => http_build_query(['action' => 'git_operation', 'operation' => 'add']), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'] +]); +$response = curl_exec($ch); +curl_close($ch); +if ($response) { + $result = json_decode($response, true); + echo "Git添加结果:\n"; + echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n"; +} + +// 测试Git提交 +echo "测试Git提交操作\n"; +$ch = curl_init($apiUrl); +curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => http_build_query([ + 'action' => 'git_operation', + 'operation' => 'commit', + 'message' => '测试提交:修复Git仓库路径问题' + ]), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'] +]); +$response = curl_exec($ch); +curl_close($ch); +if ($response) { + $result = json_decode($response, true); + echo "Git提交结果:\n"; + echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n"; +} + +echo "Git操作测试完成!\n"; +?> \ No newline at end of file diff --git a/test_git_operations.php b/test_git_operations.php new file mode 100644 index 0000000..cc8bd4f --- /dev/null +++ b/test_git_operations.php @@ -0,0 +1,57 @@ + true, + CURLOPT_POSTFIELDS => http_build_query(['action' => 'get_files']), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'] +]); +$response = curl_exec($ch); +curl_close($ch); +if ($response) { + $result = json_decode($response, true); + echo "文件列表结果:\n"; + echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n"; +} + +// 测试2: 获取分支列表 +echo "测试2: 获取分支列表\n"; +$ch = curl_init($apiUrl); +curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => http_build_query(['action' => 'get_branches']), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'] +]); +$response = curl_exec($ch); +curl_close($ch); +if ($response) { + $result = json_decode($response, true); + echo "分支列表结果:\n"; + echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n"; +} + +// 测试3: Git状态 +echo "测试3: Git状态\n"; +$ch = curl_init($apiUrl); +curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => http_build_query(['action' => 'git_operation', 'operation' => 'status']), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'] +]); +$response = curl_exec($ch); +curl_close($ch); +if ($response) { + $result = json_decode($response, true); + echo "Git状态结果:\n"; + echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n"; +} + +echo "测试完成!\n"; +?> \ No newline at end of file diff --git a/test_upload.php b/test_upload.php new file mode 100644 index 0000000..4176f98 --- /dev/null +++ b/test_upload.php @@ -0,0 +1,37 @@ + $uploadUrl, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => [ + 'action' => 'upload', + 'files' => new CURLFile('test_upload.txt') + ], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => [ + 'Content-Type: multipart/form-data' + ] +]); + +echo "正在测试文件上传功能...\n"; +$response = curl_exec($ch); +curl_close($ch); + +if ($response) { + $result = json_decode($response, true); + echo "上传结果:\n"; + echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +} else { + echo "上传失败:无法连接到服务器\n"; +} + +// 清理测试文件 +@unlink('test_upload.txt'); +?> \ No newline at end of file