diff --git a/module/ai/test/model/parsechatresponse.php b/module/ai/test/model/parsechatresponse.php index 0a1c597036..ff23293434 100755 --- a/module/ai/test/model/parsechatresponse.php +++ b/module/ai/test/model/parsechatresponse.php @@ -26,8 +26,8 @@ su('admin'); $aiTest = new aiModelTest(); // 4. 模拟设置为ERNIE模型类型 -$aiTest->objectModel->modelConfig = new stdClass(); -$aiTest->objectModel->modelConfig->type = 'baidu-ernie'; +$aiTest->instance->modelConfig = new stdClass(); +$aiTest->instance->modelConfig->type = 'baidu-ernie'; // 测试步骤 // 步骤1:测试ERNIE模型正常响应解析 @@ -37,7 +37,7 @@ $ernieResponse->content = '{"result":"这是文心一言的回复消息","id":"a r($aiTest->parseChatResponseTest($ernieResponse)) && p('0') && e('这是文心一言的回复消息'); // 步骤2:测试OpenAI模型正常响应解析 -$aiTest->objectModel->modelConfig->type = 'openai-gpt35'; +$aiTest->instance->modelConfig->type = 'openai-gpt35'; $openaiResponse = new stdClass(); $openaiResponse->result = 'success'; $openaiResponse->content = '{"id":"chatcmpl-123","object":"chat.completion","created":1677652288,"model":"gpt-3.5-turbo","choices":[{"index":0,"message":{"role":"assistant","content":"Hello! How can I help you today?"},"finish_reason":"stop"},{"index":1,"message":{"role":"assistant","content":"Another response message"},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21}}'; @@ -50,14 +50,14 @@ $failResponse->message = 'API request failed'; r($aiTest->parseChatResponseTest($failResponse)) && p() && e('0'); // 步骤4:测试ERNIE模型缺少result字段的响应 -$aiTest->objectModel->modelConfig->type = 'baidu-ernie'; +$aiTest->instance->modelConfig->type = 'baidu-ernie'; $ernieNoResultResponse = new stdClass(); $ernieNoResultResponse->result = 'success'; $ernieNoResultResponse->content = '{"id":"as-bcfa043ctv","object":"chat.completion","created":1681277883,"sentence_id":0}'; r($aiTest->parseChatResponseTest($ernieNoResultResponse)) && p() && e('0'); // 步骤5:测试OpenAI模型缺少choices字段的响应 -$aiTest->objectModel->modelConfig->type = 'openai-gpt35'; +$aiTest->instance->modelConfig->type = 'openai-gpt35'; $openaiNoChoicesResponse = new stdClass(); $openaiNoChoicesResponse->result = 'success'; $openaiNoChoicesResponse->content = '{"id":"chatcmpl-123","object":"chat.completion","created":1677652288,"model":"gpt-3.5-turbo","usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21}}'; diff --git a/module/ai/test/model/parsefunctioncallresponse.php b/module/ai/test/model/parsefunctioncallresponse.php index e5d2011d46..ee1249f59e 100755 --- a/module/ai/test/model/parsefunctioncallresponse.php +++ b/module/ai/test/model/parsefunctioncallresponse.php @@ -26,8 +26,8 @@ su('admin'); $aiTest = new aiModelTest(); // 4. 设置模型配置 -$aiTest->objectModel->modelConfig = new stdClass(); -$aiTest->objectModel->modelConfig->type = 'openai-gpt35'; +$aiTest->instance->modelConfig = new stdClass(); +$aiTest->instance->modelConfig->type = 'openai-gpt35'; // 5. 构造测试数据 $openaiResponseData = json_encode((object)array( @@ -79,7 +79,7 @@ $failedResponse = (object)array('result' => 'fail', 'message' => 'API request fa r($aiTest->parseFunctionCallResponseTest($openaiResponse)) && p('0') && e('{"key": "value"}'); // 步骤2:测试Ernie模型正常function call响应解析 -$aiTest->objectModel->modelConfig->type = 'baidu-ernie'; +$aiTest->instance->modelConfig->type = 'baidu-ernie'; r($aiTest->parseFunctionCallResponseTest($ernieResponse)) && p('0') && e('{"ernie_key": "ernie_value"}'); // 步骤3:测试空content响应处理 @@ -89,5 +89,5 @@ r($aiTest->parseFunctionCallResponseTest($emptyResponse)) && p() && e('0'); r($aiTest->parseFunctionCallResponseTest($failedResponse)) && p() && e('0'); // 步骤5:测试无function_call的响应处理 -$aiTest->objectModel->modelConfig->type = 'openai-gpt35'; +$aiTest->instance->modelConfig->type = 'openai-gpt35'; r(count($aiTest->parseFunctionCallResponseTest($noFunctionCallResponse))) && p() && e(0); \ No newline at end of file diff --git a/module/api/test/lib/model.class.php b/module/api/test/lib/model.class.php index 1f9fb9f7e7..77e171f780 100644 --- a/module/api/test/lib/model.class.php +++ b/module/api/test/lib/model.class.php @@ -404,7 +404,7 @@ class apiModelTest extends baseTest $result = $this->instance->config->api->search; // 恢复原始配置 - if($originalConfig !== null) $tester->config->api->search = $originalConfig; + if($originalConfig !== null) $this->instance->config->api->search = $originalConfig; return $result; } diff --git a/module/bi/test/model/downloadduckdb.php b/module/bi/test/model/downloadduckdb.php index a60b807ae2..be7926ae5f 100755 --- a/module/bi/test/model/downloadduckdb.php +++ b/module/bi/test/model/downloadduckdb.php @@ -19,8 +19,8 @@ cid=15155 $biTest = new biModelTest(); -r(method_exists($biTest->objectModel, 'downloadDuckdb')) && p() && e('1'); // 步骤1:验证方法存在性 +r(method_exists($biTest->instance, 'downloadDuckdb')) && p() && e('1'); // 步骤1:验证方法存在性 r(is_string($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤2:检查返回值类型 r(in_array($biTest->downloadDuckdbTest(), array('ok', 'fail', 'loading'))) && p() && e('1'); // 步骤3:验证返回值状态 r(is_string($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤4:测试方法可重复调用 -r(!empty($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤5:验证方法执行完整性 \ No newline at end of file +r(!empty($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤5:验证方法执行完整性 diff --git a/module/block/test/lib/model.class.php b/module/block/test/lib/model.class.php index 50bdf528c6..6909a7a190 100644 --- a/module/block/test/lib/model.class.php +++ b/module/block/test/lib/model.class.php @@ -17,7 +17,7 @@ class blockModelTest extends baseTest */ public function createTest($block) { - $blockID = $this->objectModel->create($block); + $blockID = $this->instance->create($block); if(dao::isError()) return dao::getError(); return $blockID; } @@ -31,7 +31,7 @@ class blockModelTest extends baseTest */ public function getBlockInitStatusTest($dashboard) { - $result = $this->objectModel->getBlockInitStatus($dashboard); + $result = $this->instance->getBlockInitStatus($dashboard); if(dao::isError()) return dao::getError(); return $result; } @@ -59,7 +59,7 @@ class blockModelTest extends baseTest */ public function getMyDashboardTest(string $dashboard) { - $result = $this->objectModel->getMyDashboard($dashboard); + $result = $this->instance->getMyDashboard($dashboard); if(dao::isError()) return dao::getError(); return $result; } @@ -75,7 +75,7 @@ class blockModelTest extends baseTest */ public function getSpecifiedBlockIDTest(string $dashboard, string $module, string $code) { - $result = $this->objectModel->getSpecifiedBlockID($dashboard, $module, $code); + $result = $this->instance->getSpecifiedBlockID($dashboard, $module, $code); if(dao::isError()) return dao::getError(); return $result; } @@ -89,7 +89,7 @@ class blockModelTest extends baseTest */ public function resetTest(string $dashboard) { - $result = $this->objectModel->reset($dashboard); + $result = $this->instance->reset($dashboard); if(dao::isError()) return dao::getError(); return $result; } @@ -103,7 +103,7 @@ class blockModelTest extends baseTest */ public function updateTest($block) { - $blockID = $this->objectModel->update($block); + $blockID = $this->instance->update($block); if(dao::isError()) return dao::getError(); return $blockID; } diff --git a/module/branch/test/lib/model.class.php b/module/branch/test/lib/model.class.php index 7965ecfa25..a5623dc0e1 100644 --- a/module/branch/test/lib/model.class.php +++ b/module/branch/test/lib/model.class.php @@ -225,7 +225,7 @@ class branchModelTest extends baseTest $this->instance->linkBranch4Project($productID); if(dao::isError()) return dao::getError(); - return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productIDList)->andWhere('branch')->gt(0)->fetch('count'); + return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productID)->andWhere('branch')->gt(0)->fetch('count'); } /** @@ -398,7 +398,9 @@ class branchModelTest extends baseTest public function isClickableTest(int $branchID, string $status): bool { $branch = $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); - return $this->instance->isClickable($branch, $status); + $result = $this->invokeArgs('isClickable', [$branch, $status]); + if(dao::isError()) return dao::getError(); + return $result; } /** diff --git a/module/branch/test/model/isclickable.php b/module/branch/test/model/isclickable.php index bcaa649a2b..8d1cd8f385 100755 --- a/module/branch/test/model/isclickable.php +++ b/module/branch/test/model/isclickable.php @@ -12,6 +12,15 @@ title=测试branchModel->isClickable(); timeout=0 cid=15332 +- 分支为空 @0 +- 分支2状态为为activate,action为activate @0 +- 分支3状态为为close,action为activate @1 +- 分支不存在 @0 +- 分支为空 @0 +- 分支2状态为为activate,action为close @1 +- 分支3状态为为close,action为close @0 +- 分支不存在 @0 + */ $branch = new branchModelTest('admin'); $idList = array(0, 2, 3, 30); @@ -24,4 +33,4 @@ r($branch->isClickableTest($idList[3], 'activate')) && p() && e('0'); // 分支 r($branch->isClickableTest($idList[0], 'close')) && p() && e('0'); // 分支为空 r($branch->isClickableTest($idList[1], 'close')) && p() && e('1'); // 分支2状态为为activate,action为close r($branch->isClickableTest($idList[2], 'close')) && p() && e('0'); // 分支3状态为为close,action为close -r($branch->isClickableTest($idList[3], 'close')) && p() && e('0'); // 分支不存在 +r($branch->isClickableTest($idList[3], 'close')) && p() && e('0'); // 分支不存在 \ No newline at end of file diff --git a/module/bug/test/lib/model.class.php b/module/bug/test/lib/model.class.php index 43a4c26139..abe16d1bbd 100644 --- a/module/bug/test/lib/model.class.php +++ b/module/bug/test/lib/model.class.php @@ -303,7 +303,7 @@ class bugModelTest extends baseTest $this->instance->resolve($bug, $output); if(dao::isError()) return str_replace('\n', '', dao::getError(true)); - return $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); + return $this->instance->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); } /** @@ -1005,7 +1005,7 @@ class bugModelTest extends baseTest $this->instance->createBuild($bug, $oldBug); if(dao::isError()) return dao::getError(true); - return $tester->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch(); + return $this->instance->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch(); } /** @@ -1179,7 +1179,7 @@ class bugModelTest extends baseTest public function getRelatedObjectsTest(string $object, string $pairs = ''): object { /* 设置bugQueryCondition来模拟有查询条件的情况 */ - $_SESSION['bugQueryCondition'] = "SELECT * FROM " . TABLE_BUG . " WHERE deleted = '0'"; + $_SESSION['bugQueryCondition'] = "deleted = '0'"; $_SESSION['bugOnlyCondition'] = true; $objects = $this->instance->getRelatedObjects($object, $pairs); diff --git a/module/bug/test/model/buildsearchconfig.php b/module/bug/test/model/buildsearchconfig.php old mode 100644 new mode 100755 index e5a3be9444..62d6d7b90a --- a/module/bug/test/model/buildsearchconfig.php +++ b/module/bug/test/model/buildsearchconfig.php @@ -8,7 +8,9 @@ su('admin'); /** title=bugModel->buildSearchConfig(); +timeout=0 cid=15346 + - 测试字段名称 - 属性title @Bug标题 - 属性module @所属模块 @@ -25,4 +27,4 @@ $searchConfig = $bugTest->instance->buildSearchConfig(1, 'story'); r($searchConfig['fields']) && p('title,module,steps') && e('Bug标题,所属模块,重现步骤'); // 测试字段名称 r($searchConfig['params']['assignedTo']) && p('operator,control') && e('=,select'); // 测试指派给字段 -r(count($searchConfig['params']['severity']['values'])) && p('') && e('6'); // 测试严重程度字段 +r(count($searchConfig['params']['severity']['values'])) && p('') && e('6'); // 测试严重程度字段 \ No newline at end of file diff --git a/module/build/test/model/unlinkstory.php b/module/build/test/model/unlinkstory.php index 772e0c76b6..cad6b6c73f 100755 --- a/module/build/test/model/unlinkstory.php +++ b/module/build/test/model/unlinkstory.php @@ -24,8 +24,8 @@ zenData('build')->gen(20); zenData('story')->gen(10); su('admin'); -$buildIDList = array('1', '11', '15'); -$stories = array('2', '4', '6'); +$buildIDList = array(1, 11, 15); +$stories = array(2, 4, 6); $build = new buildModelTest(); diff --git a/module/build/test/model/update.php b/module/build/test/model/update.php index ee509a4620..84b100f90b 100755 --- a/module/build/test/model/update.php +++ b/module/build/test/model/update.php @@ -27,7 +27,7 @@ zenData('build')->loadYaml('build')->gen(20); zenData('project')->loadYaml('project')->gen(100); su('admin'); -$buildIDList = array('1', '11'); +$buildIDList = array(1, 11); $normalExecution = array('name' => '修改版本一', 'builder' => 'admin'); $executionBuild = array('name' => '修改执行版本一', 'builder' => 'admin'); @@ -39,4 +39,4 @@ r($buildTester->updateTest($buildIDList[0], $normalExecution)) && p('0:field,old r($buildTester->updateTest($buildIDList[1], $executionBuild)) && p('0:field,old,new') && e('name,版本11,修改执行版本一'); // 修改执行版本 r($buildTester->updateTest($buildIDList[0], $noName)) && p('name:0') && e('『名称』不能为空。'); // 名称为空测试 r($buildTester->updateTest($buildIDList[0], $noBuilder)) && p('builder:0') && e('『构建者』不能为空。'); // 构建者为空测试 -r($buildTester->updateTest($buildIDList[1], $normalExecution)) && p('name:0') && e('『名称』已经有『修改版本一』这条记录了。如果您确定该记录已删除,请到后台-系统设置-回收站还原。'); // 修改重复名称 \ No newline at end of file +r($buildTester->updateTest($buildIDList[1], $normalExecution)) && p('name:0') && e('『名称』已经有『修改版本一』这条记录了。如果您确定该记录已删除,请到后台-系统设置-回收站还原。'); // 修改重复名称 diff --git a/module/caselib/test/model/buildsearchconfig.php b/module/caselib/test/model/buildsearchconfig.php index 77a7165865..655d4a208e 100644 --- a/module/caselib/test/model/buildsearchconfig.php +++ b/module/caselib/test/model/buildsearchconfig.php @@ -21,7 +21,7 @@ cid=15525 */ $caselib = new caselibModelTest(); -$searchConfig = $caselib->instance->buildSearchConfig(1); +$searchConfig = $caselib->buildSearchConfigTest(1); r($searchConfig['fields']) && p('title,story,type') && e('用例名称,关联需求,用例类型'); // 测试字段名称 r($searchConfig['params']['module']) && p('operator,control') && e('belong,select'); // 测试模块字段 diff --git a/module/chart/test/lib/model.class.php b/module/chart/test/lib/model.class.php index c9977f3d2f..dbd8fe99f6 100644 --- a/module/chart/test/lib/model.class.php +++ b/module/chart/test/lib/model.class.php @@ -64,7 +64,9 @@ class chartModelTest extends baseTest */ public function isClickableTest(int $chartID, string $action) { - $chart = $this->getByIdTest($chartID); + $chart = $this->getByIdTest($chartID); + if(!$chart) return false; + $result = chartModel::isClickable($chart, $action); if(dao::isError()) return dao::getError(); return $result; diff --git a/module/common/test/lib/model.class.php b/module/common/test/lib/model.class.php index b782d95568..cf3e87d36b 100644 --- a/module/common/test/lib/model.class.php +++ b/module/common/test/lib/model.class.php @@ -122,7 +122,8 @@ class commonModelTest extends baseTest */ public function getDotStyleTest(bool $showCount, int $unreadCount): array { - $result = commonModel::getDotStyle($showCount, $unreadCount); + $result = $this->invokeArgs('getDotStyle', [$showCount, $unreadCount]); + if(dao::isError()) return dao::getError(); return $result; } @@ -136,7 +137,7 @@ class commonModelTest extends baseTest */ public function getMainNavListTest($moduleName, $useDefault = false) { - $result = commonModel::getMainNavList($moduleName, $useDefault); + $result = $this->invokeArgs('getMainNavList', [$moduleName, $useDefault]); if(dao::isError()) return dao::getError(); return $result; } @@ -151,7 +152,7 @@ class commonModelTest extends baseTest */ public function isOpenMethodTest($module, $method) { - $result = $this->objectModel->isOpenMethod($module, $method); + $result = $this->invokeArgs('isOpenMethod', [$module, $method]); if(dao::isError()) return dao::getError(); return $result; } @@ -164,7 +165,7 @@ class commonModelTest extends baseTest */ public function isTutorialModeTest() { - $result = commonModel::isTutorialMode(); + $result = $this->invokeArgs('isTutorialMode'); if(dao::isError()) return dao::getError(); return $result ? '1' : '0'; } @@ -184,11 +185,8 @@ class commonModelTest extends baseTest if(isset($this->instance->app->user)) unset($app->user); } - // 执行setUser方法 - $this->instance->setUser(); + $this->invokeArgs('setUser'); if(dao::isError()) return dao::getError(); - - // 返回结果 return $this->instance->app->user; } @@ -202,44 +200,11 @@ class commonModelTest extends baseTest */ public function strEndsWithTest($haystack, $needle) { - $result = commonModel::strEndsWith($haystack, $needle); + $result = $this->invokeArgs('strEndsWith', [$haystack, $needle]); if(dao::isError()) return dao::getError(); return $result; } - /** - * Test printBack method. - * - * @param string $backLink - * @param string $class - * @param string $misc - * @param bool $onlyBody - * @access public - * @return mixed - */ - public function printBackTest(string $backLink, string $class = '', string $misc = '', bool $onlyBody = false) - { - if($onlyBody) - { - $_GET['onlybody'] = 'yes'; - } - else - { - unset($_GET['onlybody']); - } - - ob_start(); - $result = commonModel::printBack($backLink, $class, $misc); - $output = ob_get_clean(); - - if(dao::isError()) return dao::getError(); - - // Return different data based on what we're testing - if($onlyBody) return $result; - if(!empty($output)) return $output; - return $result; - } - /** * Test printDuration method. * @@ -266,13 +231,6 @@ class commonModelTest extends baseTest */ public function printPreAndNextTest($preAndNext = '', string $linkTemplate = '', bool $onlyBody = false) { - global $app, $lang; - - // 保存原始值 - $originalApp = $app ?? null; - $originalLang = $lang ?? null; - $originalGet = $_GET ?? array(); - // 设置onlybody模式 if($onlyBody) { @@ -283,27 +241,7 @@ class commonModelTest extends baseTest unset($_GET['onlybody']); } - // 模拟完整的app对象 - $app = new class { - public $tab = 'my'; - public $apiVersion = ''; - private $moduleName = 'test'; - private $methodName = 'view'; - private $appName = 'sys'; - private $viewType = ''; - public function getModuleName() { return $this->moduleName; } - public function getMethodName() { return $this->methodName; } - public function getAppName() { return $this->appName; } - public function getViewType() { return $this->viewType; } - public function setModuleName($name) { $this->moduleName = $name; } - public function setMethodName($name) { $this->methodName = $name; } - }; - // 设置语言 - if(!isset($lang)) - { - $lang = new stdClass(); - } if(!isset($lang->preShortcutKey)) $lang->preShortcutKey = '(←)'; if(!isset($lang->nextShortcutKey)) $lang->nextShortcutKey = '(→)'; @@ -311,11 +249,6 @@ class commonModelTest extends baseTest $result = commonModel::printPreAndNext($preAndNext, $linkTemplate); $output = ob_get_clean(); - // 恢复原始值 - if($originalApp !== null) $app = $originalApp; - if($originalLang !== null) $lang = $originalLang; - $_GET = $originalGet; - if(dao::isError()) return dao::getError(); // 如果是onlybody模式,返回false @@ -334,8 +267,68 @@ class commonModelTest extends baseTest */ public function processMarkdownTest(string $markdown) { - $result = commonModel::processMarkdown($markdown); + $result = $this->invokeArgs('processMarkdown', [$markdown]); if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test checkSafeFile method. + * + * @param string $scenario 测试场景 + * @access public + * @return mixed + */ + public function checkSafeFileTest($scenario = '') + { + // 备份原始配置和状态 + $originalInContainer = $this->instance->config->inContainer; + $originalModuleName = $this->instance->app->getModuleName(); + $originalUpgrading = $this->instance->app->upgrading ?? false; + $originalSafeFileEnv = getenv('ZT_CHECK_SAFE_FILE'); + + try { + // 根据场景设置不同的测试环境 + switch($scenario) { + case 'inContainer': + $this->instance->config->inContainer = true; + break; + + case 'validSafeFile': + $this->instance->config->inContainer = false; + // 设置环境变量模拟有效的安全文件状态 + putenv('ZT_CHECK_SAFE_FILE=true'); + break; + + case 'upgradeModule': + $this->instance->config->inContainer = false; + if(isset($_SESSION)) $_SESSION['upgrading'] = true; + $this->instance->app->setModuleName('upgrade'); + break; + + case 'noSafeFile': + case 'expiredSafeFile': + default: + $this->instance->config->inContainer = false; + // 确保没有有效的安全文件 + putenv('ZT_CHECK_SAFE_FILE=false'); + if(isset($_SESSION)) $_SESSION['upgrading'] = false; + break; + } + + $result = $this->invokeArgs('checkSafeFile'); + if(dao::isError()) return dao::getError(); + return $result; + } finally { + // 恢复原始配置和状态 + $this->instance->config->inContainer = $originalInContainer; + if(isset($_SESSION)) $_SESSION['upgrading'] = $originalUpgrading; + $this->instance->app->setModuleName($originalModuleName); + if($originalSafeFileEnv !== false) { + putenv("ZT_CHECK_SAFE_FILE=$originalSafeFileEnv"); + } else { + putenv('ZT_CHECK_SAFE_FILE'); + } + } + } } diff --git a/module/common/test/lib/tao.class.php b/module/common/test/lib/tao.class.php index 9074274715..7665c0b354 100644 --- a/module/common/test/lib/tao.class.php +++ b/module/common/test/lib/tao.class.php @@ -66,70 +66,6 @@ class commonTaoTest extends baseTest } } - /** - * Test checkSafeFile method. - * - * @param string $scenario 测试场景 - * @access public - * @return mixed - */ - public function checkSafeFileTest($scenario = '') - { - global $app, $config; - - // 备份原始配置和状态 - $originalInContainer = isset($config->inContainer) ? $config->inContainer : false; - $originalModuleName = method_exists($app, 'getModuleName') ? $app->getModuleName() : 'common'; - $originalUpgrading = isset($_SESSION['upgrading']) ? $_SESSION['upgrading'] : false; - $originalSafeFileEnv = getenv('ZT_CHECK_SAFE_FILE'); - - try { - // 根据场景设置不同的测试环境 - switch($scenario) { - case 'inContainer': - $config->inContainer = true; - break; - - case 'validSafeFile': - $config->inContainer = false; - // 设置环境变量模拟有效的安全文件状态 - putenv('ZT_CHECK_SAFE_FILE=true'); - break; - - case 'upgradeModule': - $config->inContainer = false; - if(isset($_SESSION)) $_SESSION['upgrading'] = true; - // 设置为upgrade模块 - if(method_exists($app, 'setModuleName')) $app->setModuleName('upgrade'); - break; - - case 'noSafeFile': - case 'expiredSafeFile': - default: - $config->inContainer = false; - // 确保没有有效的安全文件 - putenv('ZT_CHECK_SAFE_FILE=false'); - if(isset($_SESSION)) $_SESSION['upgrading'] = false; - break; - } - - $result = $this->objectModel->checkSafeFile(); - if(dao::isError()) return dao::getError(); - - return $result; - } finally { - // 恢复原始配置和状态 - $config->inContainer = $originalInContainer; - if(isset($_SESSION)) $_SESSION['upgrading'] = $originalUpgrading; - if(method_exists($app, 'setModuleName')) $app->setModuleName($originalModuleName); - if($originalSafeFileEnv !== false) { - putenv("ZT_CHECK_SAFE_FILE=$originalSafeFileEnv"); - } else { - putenv('ZT_CHECK_SAFE_FILE'); - } - } - } - /** * 检查详情页操作按钮的权限。 * Check the privilege of the operate action. @@ -149,7 +85,6 @@ class commonTaoTest extends baseTest return is_array($result) ? !empty($result['url']) : $result; } - /** * Test initAuthorize method. * diff --git a/module/common/test/model/printback.php b/module/common/test/model/printback.php deleted file mode 100755 index 4c244d4216..0000000000 --- a/module/common/test/model/printback.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -printBackMetaTest('exists')) && p() && e('1'); // 测试步骤1:检查printBack方法是否存在 -r($commonTest->printBackMetaTest('static')) && p() && e('1'); // 测试步骤2:检查printBack方法是否为静态方法 -r($commonTest->printBackMetaTest('public')) && p() && e('1'); // 测试步骤3:检查printBack方法是否为公共方法 -r($commonTest->printBackMetaTest('paramCount')) && p() && e('3'); // 测试步骤4:检查printBack方法参数数量 -r($commonTest->printBackTest('index.php', '', '', true)) && p() && e('0'); // 测试步骤5:在onlybody模式下调用printBack返回false \ No newline at end of file diff --git a/module/company/test/model/getoutsidecompanies.php b/module/company/test/model/getoutsidecompanies.php index 7322c03ed7..31c9be72b8 100755 --- a/module/company/test/model/getoutsidecompanies.php +++ b/module/company/test/model/getoutsidecompanies.php @@ -9,10 +9,13 @@ cid=15733 - 步骤1:测试获取外部公司列表返回数组长度为4 @4 - 步骤2:验证第一个外部公司名称为外部公司A属性2 @外部公司A -- 步骤3:验证内部公司ID=1被正确排除属性1 @0 +- 步骤3:验证内部公司ID=1被正确排除属性1 @~~ - 步骤4:验证最后一个外部公司名称为外部公司D属性5 @外部公司D - 步骤5:验证返回的键值结构正确 - - 属性keys(*) @2 + - @2 + - 属性1 @3 + - 属性2 @4 + - 属性3 @5 */ @@ -27,8 +30,8 @@ su('admin'); $company = new companyModelTest(); -r($company->getOutsideCompaniesTest()) && p() && e('4'); // 步骤1:测试获取外部公司列表返回数组长度为4 -r($company->getOutsideCompaniesTest()) && p('2') && e('外部公司A'); // 步骤2:验证第一个外部公司名称为外部公司A -r($company->getOutsideCompaniesTest()) && p('1') && e('0'); // 步骤3:验证内部公司ID=1被正确排除 -r($company->getOutsideCompaniesTest()) && p('5') && e('外部公司D'); // 步骤4:验证最后一个外部公司名称为外部公司D -r($company->getOutsideCompaniesTest()) && p('keys(*)') && e('2,3,4,5'); // 步骤5:验证返回的键值结构正确 \ No newline at end of file +r(count($company->getOutsideCompaniesTest())) && p() && e('4'); // 步骤1:测试获取外部公司列表返回数组长度为4 +r($company->getOutsideCompaniesTest()) && p('2') && e('外部公司A'); // 步骤2:验证第一个外部公司名称为外部公司A +r($company->getOutsideCompaniesTest()) && p('1') && e('~~'); // 步骤3:验证内部公司ID=1被正确排除 +r($company->getOutsideCompaniesTest()) && p('5') && e('外部公司D'); // 步骤4:验证最后一个外部公司名称为外部公司D +r(array_keys($company->getOutsideCompaniesTest())) && p('0,1,2,3') && e('2,3,4,5'); // 步骤5:验证返回的键值结构正确 diff --git a/module/company/test/model/getusers.php b/module/company/test/model/getusers.php index f44dad03a8..65d3a5baec 100755 --- a/module/company/test/model/getusers.php +++ b/module/company/test/model/getusers.php @@ -39,11 +39,11 @@ cid=15734 */ -$count = array('0','1'); +$count = array(0,1); $browseType = array('inside', 'outside'); $type = array('', 'bydept'); -$queryID = array('0', '3'); -$deptID = array('0', '1'); +$queryID = array(0, 3); +$deptID = array(0, 1); $sort = array('realname_asc', 'account_desc'); $company = new companyModelTest(); diff --git a/module/convert/model.php b/module/convert/model.php index 09e2cb1dd9..07e0d97e7e 100644 --- a/module/convert/model.php +++ b/module/convert/model.php @@ -65,8 +65,7 @@ class convertModel extends model public function dbExists(string $dbName = ''): object|false { if(!$this->checkDBName($dbName)) return false; - $quotedDbName = $this->dbh->quote($dbName); - return $this->dbh->query("SHOW DATABASES like {$quotedDbName}")->fetch(); + return $this->dbh->dbExists($dbName); } /** diff --git a/module/convert/test/lib/model.class.php b/module/convert/test/lib/model.class.php index 96f4d331ea..fafedf4009 100644 --- a/module/convert/test/lib/model.class.php +++ b/module/convert/test/lib/model.class.php @@ -34,4 +34,164 @@ class convertModelTest extends baseTest if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test checkDBName method. + * + * @param string $dbName + * @access public + * @return mixed + */ + public function checkDBNameTest($dbName = null) + { + $result = $this->invokeArgs('checkDBName', [$dbName]); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test checkImportJira method. + * + * @param string $step + * @param array $postData + * @access public + * @return mixed + */ + public function checkImportJiraTest($step = '', $postData = array()) + { + $result = $this->invokeArgs('checkImportJira', [$step, $postData]); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test convertStage method. + * + * @param string $jiraStatus + * @param string $issueType + * @param array $relations + * @access public + * @return mixed + */ + public function convertStageTest($jiraStatus = '', $issueType = '', $relations = array()) + { + $originalJiraRelation = $this->instance->app->session->jiraRelation; + + // 如果没有提供relations参数,设置测试session数据 + if(empty($relations)) + { + $testRelations = array( + 'zentaoStage1' => array( + 'open' => 'wait', + 'in-progress' => 'developing', + 'done' => 'developed', + 'closed' => 'closed' + ), + 'zentaoStage2' => array( + 'to-do' => 'wait', + 'in-progress' => 'developing', + 'done' => 'developed' + ) + ); + $this->instance->app->session->set('jiraRelation', json_encode($testRelations)); + } + + $result = $this->invokeArgs('convertStage', [$jiraStatus, $issueType, $relations]); + if(dao::isError()) return dao::getError(); + + $this->instance->app->session->set('jiraRelation', $originalJiraRelation); + + return $result; + } + + /** + * Test convertStatus method. + * + * @param string $objectType + * @param string $jiraStatus + * @param string $issueType + * @param array $relations + * @access public + * @return mixed + */ + public function convertStatusTest($objectType = '', $jiraStatus = '', $issueType = '', $relations = array()) + { + $this->instance->app->loadConfig('testcase'); + $this->instance->app->loadConfig('feedback'); + + // 备份原始session数据和配置 + $originalJiraRelation = $this->instance->app->session->jiraRelation; + $originalTestcaseNeedReview = $this->instance->config->testcase->needReview; + $originalFeedbackNeedReview = $this->instance->config->feedback->needReview; + $originalFeedbackTicket = $this->instance->config->feedback->ticket; + + // 如果没有提供relations参数,设置测试session数据 + if(empty($relations)) + { + $testRelations = array( + 'zentaoStatus1' => array( + 'open' => 'active', + 'in-progress' => 'doing', + 'done' => 'closed', + 'resolved' => 'resolved' + ), + 'zentaoStatus2' => array( + 'to-do' => 'wait', + 'in-progress' => 'doing', + 'done' => 'done' + ) + ); + $this->instance->app->session->set('jiraRelation', json_encode($testRelations)); + } + + $result = $this->invokeArgs('convertStatus', [$objectType, $jiraStatus, $issueType, $relations]); + if(dao::isError()) return dao::getError(); + + // 恢复原始session数据和配置 + $this->instance->app->session->set('jiraRelation', $originalJiraRelation); + $this->instance->config->testcase->needReview = $originalTestcaseNeedReview; + $this->instance->config->feedback->needReview = $originalFeedbackNeedReview; + $this->instance->config->feedback->ticket = $originalFeedbackTicket; + + return $result; + } + + /** + * Test createTmpTable4Jira method. + * + * @access public + * @return mixed + */ + public function createTmpTable4JiraTest() + { + try + { + // 先删除可能存在的表 + $this->instance->dao->exec("DROP TABLE IF EXISTS `jiratmprelation`"); + + $this->invokeArgs('createTmpTable4Jira'); + if(dao::isError()) return dao::getError(); + + // 检查表是否创建成功 + return $this->instance->dao->descTable('jiratmprelation'); + } + catch(Exception $e) + { + return 'exception: ' . $e->getMessage(); + } + } + + /** + * Test dbExists method. + * + * @param string $dbName + * @access public + * @return mixed + */ + public function dbExistsTest($dbName) + { + $result = $this->invokeArgs('dbExists', [$dbName]); + if(dao::isError()) return dao::getError(); + return $result; + } } diff --git a/module/convert/test/model/calljiraapi.php b/module/convert/test/model/calljiraapi.php deleted file mode 100755 index 9e23ec7246..0000000000 --- a/module/convert/test/model/calljiraapi.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -callJiraAPITest('/test/api', 0)) && p() && e('0'); // 步骤1:空Session情况 -r($convertTest->callJiraAPITest('/rest/api/2/status', 10)) && p() && e('0'); // 步骤2:无效的jiraApi Session数据 -r($convertTest->callJiraAPITest('/rest/api/2/project', 0)) && p() && e('0'); // 步骤3:缺少domain的jiraApi配置 -r($convertTest->callJiraAPITest('', 5)) && p() && e('0'); // 步骤4:正常的jiraApi配置但模拟HTTP请求失败 -r($convertTest->callJiraAPITest('/rest/api/2/issue/search?jql=project=TEST', 20)) && p() && e('0'); // 步骤5:正常的jiraApi配置和有效URL参数 \ No newline at end of file diff --git a/module/convert/test/model/checkjiraapi.php b/module/convert/test/model/checkjiraapi.php deleted file mode 100755 index de63f38dc0..0000000000 --- a/module/convert/test/model/checkjiraapi.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -checkJiraApiTest()) && p() && e('0'); // 步骤1:session无jiraApi数据时返回false -r($convertTest->checkJiraApiTest(array('admin' => 'test', 'token' => 'token'))) && p() && e('0'); // 步骤2:domain为空时返回false -r($convertTest->checkJiraApiTest(array('domain' => 'http://invalid-domain.com', 'admin' => 'test', 'token' => 'token'))) && p() && e('0'); // 步骤3:无效domain时返回false -r($convertTest->checkJiraApiTest(array('domain' => 'https://test.atlassian.net', 'admin' => 'wronguser', 'token' => 'wrongtoken'))) && p() && e('0'); // 步骤4:错误认证时返回false -r($convertTest->checkJiraApiTest(array('domain' => 'https://test.atlassian.net', 'admin' => 'admin', 'token' => 'validtoken'))) && p() && e('0'); // 步骤5:有效配置时返回false(测试环境无法连接) \ No newline at end of file diff --git a/module/convert/test/model/connectdb.php b/module/convert/test/model/connectdb.php deleted file mode 100755 index 621f009cbd..0000000000 --- a/module/convert/test/model/connectdb.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -objectModel, 'connectDB' @1 -- 执行$convertTest->objectModel, 'sourceDBH' @1 -- 执行$convertTest->objectModel, 'connectDB' @1 -- 执行 @1 -- 执行 @1 - -*/ - -include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -su('admin'); - -$convertTest = new convertModelTest(); - -r(method_exists($convertTest->objectModel, 'connectDB')) && p() && e('1'); -r(property_exists($convertTest->objectModel, 'sourceDBH')) && p() && e('1'); -r(is_callable(array($convertTest->objectModel, 'connectDB'))) && p() && e('1'); -r(class_exists('convertModel')) && p() && e('1'); -r((new ReflectionMethod('convertModel', 'connectDB'))->hasReturnType()) && p() && e('1'); \ No newline at end of file diff --git a/module/convert/test/model/createtmptable4jira.php b/module/convert/test/model/createtmptable4jira.php index 88cbf0229d..0c36d1da06 100755 --- a/module/convert/test/model/createtmptable4jira.php +++ b/module/convert/test/model/createtmptable4jira.php @@ -7,11 +7,11 @@ title=测试 convertModel::createTmpTable4Jira(); timeout=0 cid=15768 -- 执行convertTest模块的createTmpTable4JiraTest方法 属性id @int(8) -- 执行convertTest模块的createTmpTable4JiraTest方法 属性AType @char(30) -- 执行convertTest模块的createTmpTable4JiraTest方法 属性AID @char(100) -- 执行convertTest模块的createTmpTable4JiraTest方法 属性BType @char(30) -- 执行convertTest模块的createTmpTable4JiraTest方法 属性BID @char(100) +- 执行convertTest模块的createTmpTable4JiraTest方法 第id条的type属性 @int(8) +- 执行convertTest模块的createTmpTable4JiraTest方法 第AType条的type属性 @char(30) +- 执行convertTest模块的createTmpTable4JiraTest方法 第AID条的type属性 @char(100) +- 执行convertTest模块的createTmpTable4JiraTest方法 第BType条的type属性 @char(30) +- 执行convertTest模块的createTmpTable4JiraTest方法 第BID条的type属性 @char(100) */ @@ -22,8 +22,8 @@ su('admin'); $convertTest = new convertModelTest(); -r($convertTest->createTmpTable4JiraTest()) && p('id') && e('int(8)'); -r($convertTest->createTmpTable4JiraTest()) && p('AType') && e('char(30)'); -r($convertTest->createTmpTable4JiraTest()) && p('AID') && e('char(100)'); -r($convertTest->createTmpTable4JiraTest()) && p('BType') && e('char(30)'); -r($convertTest->createTmpTable4JiraTest()) && p('BID') && e('char(100)'); \ No newline at end of file +r($convertTest->createTmpTable4JiraTest()) && p('id:type') && e('int(8)'); +r($convertTest->createTmpTable4JiraTest()) && p('AType:type') && e('char(30)'); +r($convertTest->createTmpTable4JiraTest()) && p('AID:type') && e('char(100)'); +r($convertTest->createTmpTable4JiraTest()) && p('BType:type') && e('char(30)'); +r($convertTest->createTmpTable4JiraTest()) && p('BID:type') && e('char(100)'); diff --git a/module/convert/test/model/dbexists.php b/module/convert/test/model/dbexists.php index 836f4ba0c1..837f856267 100755 --- a/module/convert/test/model/dbexists.php +++ b/module/convert/test/model/dbexists.php @@ -25,8 +25,8 @@ $tester->loadModel('convert'); $convertTest = new convertModelTest(); -r(method_exists($convertTest->objectModel, 'dbExists')) && p() && e('1'); // 步骤1:检查方法是否存在 -r(is_callable(array($convertTest->objectModel, 'dbExists'))) && p() && e('1'); // 步骤2:检查方法是否可调用 -r($convertTest->dbExistsTest('')) && p() && e('0'); // 步骤3:测试空数据库名称 -r($convertTest->dbExistsTest('123invalid')) && p() && e('0'); // 步骤4:测试无效数据库名称(数字开头) -r($convertTest->dbExistsTest('test-db')) && p() && e('0'); // 步骤5:测试无效数据库名称(特殊字符) \ No newline at end of file +r(method_exists($convertTest->instance, 'dbExists')) && p() && e('1'); // 步骤1:检查方法是否存在 +r(is_callable(array($convertTest->instance, 'dbExists'))) && p() && e('1'); // 步骤2:检查方法是否可调用 +r($convertTest->dbExistsTest('')) && p() && e('0'); // 步骤3:测试空数据库名称 +r($convertTest->dbExistsTest('123invalid')) && p() && e('0'); // 步骤4:测试无效数据库名称(数字开头) +r($convertTest->dbExistsTest('test-db')) && p() && e('0'); // 步骤5:测试无效数据库名称(特殊字符)