From ca37dbbce91ca10849d8a7065473cae8f0cd7705 Mon Sep 17 00:00:00 2001 From: liugang Date: Sun, 14 Sep 2025 16:19:25 +0800 Subject: [PATCH] + [misc] Add unit tests for extensionZen::checkSafe() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/extension/test/zen/checksafe.php | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 module/extension/test/zen/checksafe.php diff --git a/module/extension/test/zen/checksafe.php b/module/extension/test/zen/checksafe.php new file mode 100755 index 0000000000..dad8387f9c --- /dev/null +++ b/module/extension/test/zen/checksafe.php @@ -0,0 +1,48 @@ +#!/usr/bin/env php +rawModule = 'extension'; +$app->rawMethod = 'browse'; + +$zen = initReference('extension'); +$func = $zen->getMethod('checkSafe'); + +// 测试步骤1: 正常环境下的checkSafe调用 +$config->inContainer = false; +$config->safeFileTimeout = 86400; +$statusFile = $app->getAppRoot() . 'www' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'ok.txt'; +if(!is_dir(dirname($statusFile))) mkdir(dirname($statusFile), 0777, true); +touch($statusFile); +r($func->invokeArgs($zen->newInstance(), [])) && p() && e('0'); + +// 测试步骤2: 容器环境 +$config->inContainer = true; +r($func->invokeArgs($zen->newInstance(), [])) && p() && e('0'); + +// 测试步骤3: 正常环境下安全文件存在 +$config->inContainer = false; +r($func->invokeArgs($zen->newInstance(), [])) && p() && e('0'); + +// 测试步骤4: 多次调用测试稳定性 +r($func->invokeArgs($zen->newInstance(), [])) && p() && e('0'); + +// 测试步骤5: 最终验证 +r($func->invokeArgs($zen->newInstance(), [])) && p() && e('0'); \ No newline at end of file