From ff3ec0cb7f929d368fe11547bac649389b2fec77 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 16 Jan 2026 14:39:56 +0800 Subject: [PATCH] * [refac] Refactor test lib classes. --- .../action/test/model/getdynamicbyproduct.php | 2 +- module/action/test/model/getfirstaction.php | 4 +- module/action/test/model/updatecomment.php | 6 +- module/admin/test/model/setsubmenu.php | 2 +- module/ai/test/lib/model.class.php | 2 +- module/ai/test/model/converseforjson.php | 81 +- module/api/test/lib/model.class.php | 431 +- module/backup/test/lib/model.class.php | 99 +- module/backup/test/lib/zen.class.php | 33 +- module/bi/model.php | 2 + module/bi/test/lib/model.class.php | 32 + module/bi/test/model/checkduckdbinstall.php | 4 +- module/bi/test/model/getparams4rebuild.php | 14 +- module/bi/test/model/preparecolumns.php | 6 +- .../test/model/updatedownloadingtagfile.php | 6 +- module/block/test/lib/model.class.php | 88 +- module/block/test/lib/zen.class.php | 440 +- module/block/test/model/checkapi.php | 70 - module/block/test/model/updatelayout.php | 4 +- module/branch/test/lib/model.class.php | 108 +- module/branch/test/lib/tao.class.php | 481 +-- module/branch/test/model/isclickable.php | 18 +- module/bug/model.php | 2 +- module/bug/test/lib/model.class.php | 2772 +----------- module/bug/test/lib/tao.class.php | 3701 +---------------- module/bug/test/lib/zen.class.php | 170 +- module/bug/test/model/buildsearchconfig.php | 4 +- module/bug/test/model/getproductbugpairs.php | 26 +- module/bug/zen.php | 2 - .../caselib/test/model/buildsearchconfig.php | 2 +- module/cne/test/model/alldblist.php | 31 - module/cne/test/model/appdbdetail.php | 52 - module/cne/test/model/appdblist.php | 55 - module/cne/test/model/backupdetail.php | 34 - module/cne/test/model/batchquerystatus.php | 68 - module/cne/test/model/certinfo.php | 27 - module/cne/test/model/dbdetail.php | 31 - module/cne/test/model/getappconfig.php | 29 - module/cne/test/model/getapplogs.php | 31 - module/cne/test/model/getcomponents.php | 28 - module/cne/test/model/getdefaultaccount.php | 52 - module/cne/test/model/getdomain.php | 42 - module/cne/test/model/getevents.php | 27 - module/cne/test/model/getpods.php | 37 - module/cne/test/model/getrestorestatus.php | 68 - module/cne/test/model/getsettingsmapping.php | 33 - module/cne/test/model/querystatus.php | 29 - module/cne/test/model/shareddblist.php | 38 - module/cne/test/model/startapp.php | 29 - module/cne/test/model/translateerror.php | 62 - module/cne/test/model/updateconfig.php | 29 - module/cne/test/model/validatedb.php | 55 - module/common/test/lib/model.class.php | 186 +- module/common/test/model/apidelete.php | 33 - module/common/test/model/apiget.php | 29 - module/common/test/model/apipost.php | 28 - module/common/test/model/apiput.php | 33 - module/common/test/model/buildactionitem.php | 33 - module/common/test/model/buildiconbutton.php | 29 - module/common/test/model/buildmorebutton.php | 47 - module/common/test/model/buildoperatemenu.php | 29 - module/common/test/model/checkentry.php | 42 - .../test/model/checkmenuvarsreplaced.php | 29 - module/common/test/model/checknotcn.php | 33 - .../common/test/model/checkupgradestatus.php | 37 - .../common/test/model/getactivemainmenu.php | 33 - module/common/test/model/gethasprivlink.php | 40 - module/common/test/model/getsysurl.php | 36 - module/common/test/model/getuserpriv.php | 32 - module/common/test/model/http.php | 32 - module/common/test/model/initauthorize.php | 30 - module/common/test/model/printaboutbar.php | 27 - module/common/test/model/printclientlink.php | 29 - module/common/test/model/printcreatelist.php | 29 - module/common/test/model/printicon.php | 33 - module/common/test/model/printlink.php | 27 - module/common/test/model/printorderlink.php | 27 - module/common/test/model/printuserbar.php | 27 - module/common/test/model/sendheader.php | 44 - module/common/test/model/setmainmenu.php | 33 - module/common/test/model/setmenuvars.php | 33 - module/common/test/model/setmenuvarsex.php | 47 - module/common/test/model/sortfeaturemenu.php | 29 - .../test/{model => tao}/replacemenulang.php | 6 +- module/execution/test/lib/model.class.php | 486 +-- 85 files changed, 1220 insertions(+), 9947 deletions(-) delete mode 100755 module/block/test/model/checkapi.php delete mode 100755 module/cne/test/model/alldblist.php delete mode 100755 module/cne/test/model/appdbdetail.php delete mode 100755 module/cne/test/model/appdblist.php delete mode 100755 module/cne/test/model/backupdetail.php delete mode 100755 module/cne/test/model/batchquerystatus.php delete mode 100755 module/cne/test/model/certinfo.php delete mode 100755 module/cne/test/model/dbdetail.php delete mode 100755 module/cne/test/model/getappconfig.php delete mode 100644 module/cne/test/model/getapplogs.php delete mode 100755 module/cne/test/model/getcomponents.php delete mode 100755 module/cne/test/model/getdefaultaccount.php delete mode 100755 module/cne/test/model/getdomain.php delete mode 100755 module/cne/test/model/getevents.php delete mode 100755 module/cne/test/model/getpods.php delete mode 100755 module/cne/test/model/getrestorestatus.php delete mode 100755 module/cne/test/model/getsettingsmapping.php delete mode 100755 module/cne/test/model/querystatus.php delete mode 100755 module/cne/test/model/shareddblist.php delete mode 100755 module/cne/test/model/startapp.php delete mode 100755 module/cne/test/model/translateerror.php delete mode 100755 module/cne/test/model/updateconfig.php delete mode 100755 module/cne/test/model/validatedb.php delete mode 100755 module/common/test/model/apidelete.php delete mode 100755 module/common/test/model/apiget.php delete mode 100755 module/common/test/model/apipost.php delete mode 100755 module/common/test/model/apiput.php delete mode 100755 module/common/test/model/buildactionitem.php delete mode 100755 module/common/test/model/buildiconbutton.php delete mode 100755 module/common/test/model/buildmorebutton.php delete mode 100755 module/common/test/model/buildoperatemenu.php delete mode 100755 module/common/test/model/checkentry.php delete mode 100755 module/common/test/model/checkmenuvarsreplaced.php delete mode 100755 module/common/test/model/checknotcn.php delete mode 100755 module/common/test/model/checkupgradestatus.php delete mode 100755 module/common/test/model/getactivemainmenu.php delete mode 100644 module/common/test/model/gethasprivlink.php delete mode 100755 module/common/test/model/getsysurl.php delete mode 100755 module/common/test/model/getuserpriv.php delete mode 100755 module/common/test/model/http.php delete mode 100755 module/common/test/model/initauthorize.php delete mode 100755 module/common/test/model/printaboutbar.php delete mode 100755 module/common/test/model/printclientlink.php delete mode 100755 module/common/test/model/printcreatelist.php delete mode 100755 module/common/test/model/printicon.php delete mode 100755 module/common/test/model/printlink.php delete mode 100755 module/common/test/model/printorderlink.php delete mode 100755 module/common/test/model/printuserbar.php delete mode 100755 module/common/test/model/sendheader.php delete mode 100755 module/common/test/model/setmainmenu.php delete mode 100755 module/common/test/model/setmenuvars.php delete mode 100755 module/common/test/model/setmenuvarsex.php delete mode 100755 module/common/test/model/sortfeaturemenu.php rename module/common/test/{model => tao}/replacemenulang.php (96%) diff --git a/module/action/test/model/getdynamicbyproduct.php b/module/action/test/model/getdynamicbyproduct.php index 4c122e1a9f..394872c741 100755 --- a/module/action/test/model/getdynamicbyproduct.php +++ b/module/action/test/model/getdynamicbyproduct.php @@ -42,7 +42,7 @@ r($actionTest->getDynamicByProductTest($productID, $accountList[1])) && p() && e r($actionTest->getDynamicByProductTest($productID, $accountList[2])) && p() && e('2'); // 查找用户dev17动态 r($actionTest->getDynamicByProductTest($productID, $accountList[3])) && p() && e('2'); // 查找用户test18动态 -$actionTest->objectModel->dao->update(TABLE_ACTIONPRODUCT)->set('product')->eq('1')->where('action')->eq('33')->exec(); +$actionTest->instance->dao->update(TABLE_ACTIONPRODUCT)->set('product')->eq('1')->where('action')->eq('33')->exec(); r($actionTest->getDynamicByProductTest($productID, $accountList[3], $typeList[1])) && p() && e('1'); // 查找今天的动态 r($actionTest->getDynamicByProductTest($productID, $accountList[1], $typeList[2])) && p() && e('0'); // 查找昨天的动态 diff --git a/module/action/test/model/getfirstaction.php b/module/action/test/model/getfirstaction.php index 416f58c328..cc70af3d7c 100755 --- a/module/action/test/model/getfirstaction.php +++ b/module/action/test/model/getfirstaction.php @@ -30,5 +30,5 @@ $action = new actionModelTest(); r($action->getFirstActionTest()) && p('id,objectID,objectType,action,extra') && e('1,1,product,common,1'); // 测试获取对象类型 story 对象ID 1 的动态信息 -$action->objectModel->dao->delete()->from(TABLE_ACTION)->exec(); -r($action->getFirstActionTest()) && p() && e('0'); // 没有动态数据 \ No newline at end of file +$action->instance->dao->delete()->from(TABLE_ACTION)->exec(); +r($action->getFirstActionTest()) && p() && e('0'); // 没有动态数据 diff --git a/module/action/test/model/updatecomment.php b/module/action/test/model/updatecomment.php index a63cad2df8..113032cb3d 100755 --- a/module/action/test/model/updatecomment.php +++ b/module/action/test/model/updatecomment.php @@ -2,7 +2,7 @@ gen(2); @@ -29,8 +29,8 @@ $commentList = array('备注1', '备注2', '

$value) $param .= '&' . $key . '=' . $value; - $param = ltrim($param, '&'); - } - $url = $host . "/$moduleName-$methodName" . ($param ? "-$param" : '') . ".json"; - $url .= strpos($url, '?') === false ? '?' : '&'; - $url .= 'zentaosid=test_session_id'; - } - - // 模拟响应内容,不实际进行HTTP请求 - $content = 'mock_response_content'; - - // 恢复原始 $_POST 数据 - $_POST = $originalPost; - - if(dao::isError()) return dao::getError(); - - return array('url' => $url, 'content' => $content); - } - /** * Test getPrivApis method. * diff --git a/module/backup/test/lib/model.class.php b/module/backup/test/lib/model.class.php index b5f51efb30..8e70a1e4f2 100644 --- a/module/backup/test/lib/model.class.php +++ b/module/backup/test/lib/model.class.php @@ -136,35 +136,9 @@ class backupModelTest extends baseTest */ public function getBackupListTest() { - global $tester; - - // 手动实现getBackupList的逻辑,避免复杂的类加载问题 - $backupPath = $this->instance->getBackupPath(); - $sqlFiles = glob("{$backupPath}*.sql*"); - - if(empty($sqlFiles)) return array(); - - $backupList = array(); - foreach($sqlFiles as $file) - { - $fileName = basename($file); - $backupFile = new stdclass(); - $backupFile->time = filemtime($file); - $backupFile->name = substr($fileName, 0, strpos($fileName, '.')); - $backupFile->files = array(); - $backupFile->files[$file] = $this->instance->getBackupSummary($file); - - $fileBackup = $this->instance->getBackupFile($backupFile->name, 'file'); - if($fileBackup) $backupFile->files[$fileBackup] = $this->instance->getBackupSummary($fileBackup); - - $codeBackup = $this->instance->getBackupFile($backupFile->name, 'code'); - if($codeBackup) $backupFile->files[$codeBackup] = $this->instance->getBackupSummary($codeBackup); - - $backupList[$backupFile->name] = $backupFile; - } - krsort($backupList); - - return $backupList; + $result = $this->instance->getBackupList(); + if(dao::isError()) return dao::getError(); + return $result; } /** @@ -177,20 +151,9 @@ class backupModelTest extends baseTest */ public function backupSQLTest($fileName = null, $reload = 'no') { - // Mock implementation to simulate backupSQL behavior - if(empty($fileName)) - { - $fileName = 'test_backup_' . time(); - } - - // Mock different scenarios based on input - if($fileName === 'fail_test') - { - return array('result' => 'fail', 'message' => 'Mock backup failed'); - } - - // Return success for normal cases - return array('result' => 'success'); + $result = $this->instance->backupSQL($fileName, $reload); + if(dao::isError()) return dao::getError(); + return $result; } /** @@ -203,34 +166,9 @@ class backupModelTest extends baseTest */ public function backupFileTest($fileName = null, $reload = 'no') { - // Mock implementation to simulate backupFile behavior - if(empty($fileName)) - { - $fileName = 'test_backup_file_' . time(); - } - - // Mock different scenarios based on input - if($fileName === 'fail_test') - { - if($reload === 'yes') - { - return array('result' => 'fail', 'message' => 'Mock file backup failed'); - } - else - { - // For reload=no, it would print error directly, but we mock as returning the message - return array('result' => 'fail', 'message' => 'Mock file backup failed'); - } - } - - // Mock nofile setting check - if nofile is in config, skip file backup - if(isset($this->instance->config->backup->setting) && str_contains($this->instance->config->backup->setting, 'nofile')) - { - return array('result' => 'success'); - } - - // Return success for normal cases - return array('result' => 'success'); + $result = $this->instance->backupFile($fileName, $reload); + if(dao::isError()) return dao::getError(); + return $result; } /** @@ -334,23 +272,4 @@ class backupModelTest extends baseTest if(dao::isError()) return dao::getError(); return $result; } - - /** - * Clean up test directory. - * - * @param string $dir - * @access private - * @return void - */ - private function cleanupTestDir($dir) - { - if(!is_dir($dir)) return; - - $files = glob($dir . '*'); - foreach($files as $file) - { - if(is_file($file)) unlink($file); - } - rmdir($dir); - } } diff --git a/module/backup/test/lib/zen.class.php b/module/backup/test/lib/zen.class.php index 8f9cf89a07..556ac0b632 100644 --- a/module/backup/test/lib/zen.class.php +++ b/module/backup/test/lib/zen.class.php @@ -31,11 +31,14 @@ class backupZenTest extends baseTest */ public function backupCodeTestWithNofile() { - global $config; - $oldSetting = $config->backup->setting; - $config->backup->setting = 'nofile'; + $oldSetting = $this->instance->config->backup->setting; + + $this->instance->config->backup->setting = 'nofile'; + $result = $this->invokeArgs('backupCode', ['test_nofile']); - $config->backup->setting = $oldSetting; + + $this->instance->config->backup->setting = $oldSetting; + if(dao::isError()) return dao::getError(); return $result; } @@ -63,11 +66,14 @@ class backupZenTest extends baseTest */ public function backupFileTestWithNofile() { - global $config; - $oldSetting = $config->backup->setting; - $config->backup->setting = 'nofile'; + $oldSetting = $this->instance->config->backup->setting; + + $this->instance->config->backup->setting = 'nofile'; + $result = $this->invokeArgs('backupFile', ['test_nofile']); - $config->backup->setting = $oldSetting; + + $this->instance->config->backup->setting = $oldSetting; + if(dao::isError()) return dao::getError(); return $result; } @@ -95,11 +101,14 @@ class backupZenTest extends baseTest */ public function backupSQLTestWithNosafe() { - global $config; - $oldSetting = $config->backup->setting; - $config->backup->setting = 'nosafe'; + $oldSetting = $this->instance->config->backup->setting; + + $this->instance->config->backup->setting = 'nosafe'; + $result = $this->invokeArgs('backupSQL', ['test_nosafe_' . time()]); - $config->backup->setting = $oldSetting; + + $this->instance->config->backup->setting = $oldSetting; + if(dao::isError()) return dao::getError(); return $result; } diff --git a/module/bi/model.php b/module/bi/model.php index be001d3f73..856bc3a2fd 100755 --- a/module/bi/model.php +++ b/module/bi/model.php @@ -1413,6 +1413,8 @@ class biModel extends model $this->app->loadClass('sqlparser', true); $parser = new sqlparser($sql); + if(!isset($this->lang->dataview)) $this->app->loadLang('dataview'); + if($parser->statementsCount == 0) { if($mode == 'builder') return $this->lang->dataview->emptyBuilder; diff --git a/module/bi/test/lib/model.class.php b/module/bi/test/lib/model.class.php index 80e6416769..70834ddd6c 100644 --- a/module/bi/test/lib/model.class.php +++ b/module/bi/test/lib/model.class.php @@ -682,6 +682,38 @@ class biModelTest extends baseTest return $result; } + /** + * Test saveLogs method. + * + * @param string $log + * @access public + * @return mixed + */ + public function saveLogsTest($log) + { + $logFile = $this->instance->getLogFile(); + if(file_exists($logFile)) unlink($logFile); + + $this->instance->saveLogs($log); + + // 检查文件是否被创建 + if(!file_exists($logFile)) return false; + + // 读取文件内容进行验证 + $content = file_get_contents($logFile); + + // 清理测试文件 + if(file_exists($logFile)) unlink($logFile); + + return array( + 'fileExists' => true, + 'hasPhpHeader' => strpos($content, ' strpos($content, 'die();') !== false, + 'hasLogContent' => strpos($content, $log) !== false, + 'hasTimestamp' => preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $content) === 1 + ); + } + /** * Test parseSqlVars method. * diff --git a/module/bi/test/model/checkduckdbinstall.php b/module/bi/test/model/checkduckdbinstall.php index b9b5b4441f..f51eec6173 100755 --- a/module/bi/test/model/checkduckdbinstall.php +++ b/module/bi/test/model/checkduckdbinstall.php @@ -19,8 +19,8 @@ cid=15153 $biTest = new biModelTest(); -r(method_exists($biTest->objectModel, 'checkDuckdbInstall')) && p() && e('1'); // 步骤1:验证方法存在性 +r(method_exists($biTest->instance, 'checkDuckdbInstall')) && p() && e('1'); // 步骤1:验证方法存在性 r(is_array($biTest->checkDuckdbInstallTest())) && p() && e('1'); // 步骤2:检查返回值为数组类型 r(array_key_exists('loading', $biTest->checkDuckdbInstallTest()) && array_key_exists('ok', $biTest->checkDuckdbInstallTest()) && array_key_exists('fail', $biTest->checkDuckdbInstallTest())) && p() && e('1'); // 步骤3:验证返回结果包含所有必要字段 r(in_array($biTest->checkDuckdbInstallTest()['duckdb'], array('ok', 'fail', 'loading'))) && p() && e('1'); // 步骤4:验证返回状态值合法性 -r(is_array($biTest->checkDuckdbInstallTest())) && p() && e('1'); // 步骤5:测试方法可重复调用 \ No newline at end of file +r(is_array($biTest->checkDuckdbInstallTest())) && p() && e('1'); // 步骤5:测试方法可重复调用 diff --git a/module/bi/test/model/getparams4rebuild.php b/module/bi/test/model/getparams4rebuild.php index 7683eab070..6a292ed3c6 100755 --- a/module/bi/test/model/getparams4rebuild.php +++ b/module/bi/test/model/getparams4rebuild.php @@ -21,31 +21,31 @@ $bi = new biModelTest(); // 测试用例1:简单SELECT语句 $sql1 = "SELECT 1 as id, 'test' as name"; -$statement1 = $bi->objectModel->sql2Statement($sql1); +$statement1 = $bi->instance->sql2Statement($sql1); $columnFields1 = array('id' => 'id', 'name' => 'name'); -// 测试用例2:带别名的SELECT语句 +// 测试用例2:带别名的SELECT语句 $sql2 = "SELECT 1 as user_id, 'admin' as user_name"; -$statement2 = $bi->objectModel->sql2Statement($sql2); +$statement2 = $bi->instance->sql2Statement($sql2); $columnFields2 = array('user_id' => 'user_id', 'user_name' => 'user_name'); // 测试用例3:空字段列表 $sql3 = "SELECT 'test' as value"; -$statement3 = $bi->objectModel->sql2Statement($sql3); +$statement3 = $bi->instance->sql2Statement($sql3); $columnFields3 = array(); // 测试用例4:多字段 $sql4 = "SELECT 1 as id, 'name' as title, 'desc' as description"; -$statement4 = $bi->objectModel->sql2Statement($sql4); +$statement4 = $bi->instance->sql2Statement($sql4); $columnFields4 = array('id' => 'id', 'title' => 'title', 'description' => 'description'); // 测试用例5:聚合函数 $sql5 = "SELECT COUNT(1) as total, 'admin' as role"; -$statement5 = $bi->objectModel->sql2Statement($sql5); +$statement5 = $bi->instance->sql2Statement($sql5); $columnFields5 = array('total' => 'total', 'role' => 'role'); r(count($bi->getParams4RebuildTest($sql1, $statement1, $columnFields1))) && p() && e(4); // 测试简单SELECT语句,检查返回数组包含4个元素 r($bi->getParams4RebuildTest($sql2, $statement2, $columnFields2)) && p('2:user_id') && e('user_id'); // 测试带别名的SELECT语句,验证字段映射处理 r(count($bi->getParams4RebuildTest($sql3, $statement3, $columnFields3))) && p() && e(4); // 测试空字段列表参数,确保方法能正常处理 r($bi->getParams4RebuildTest($sql4, $statement4, $columnFields4)) && p('2:description') && e('description'); // 测试复杂SELECT语句,验证多字段处理 -r($bi->getParams4RebuildTest($sql5, $statement5, $columnFields5)) && p('2:total') && e('total'); // 测试聚合函数SQL,验证计算字段处理 \ No newline at end of file +r($bi->getParams4RebuildTest($sql5, $statement5, $columnFields5)) && p('2:total') && e('total'); // 测试聚合函数SQL,验证计算字段处理 diff --git a/module/bi/test/model/preparecolumns.php b/module/bi/test/model/preparecolumns.php index 6b5674521d..ea1c2d1d31 100755 --- a/module/bi/test/model/preparecolumns.php +++ b/module/bi/test/model/preparecolumns.php @@ -31,14 +31,14 @@ $biTest = new biModelTest(); // 测试用例1:简单SELECT语句 $sql1 = "SELECT id, account FROM zt_user LIMIT 1"; -$statement1 = $biTest->objectModel->sql2Statement($sql1); +$statement1 = $biTest->instance->sql2Statement($sql1); // 测试用例2:多字段SELECT语句 $sql2 = "SELECT id, account, realname FROM zt_user LIMIT 1"; -$statement2 = $biTest->objectModel->sql2Statement($sql2); +$statement2 = $biTest->instance->sql2Statement($sql2); r(count($biTest->prepareColumnsTest($sql1, $statement1, 'mysql'))) && p() && e('2'); // 测试简单SELECT语句,验证返回结果包含两个元素 r($biTest->prepareColumnsTest($sql1, $statement1, 'mysql')[0]) && p('id:name') && e('id'); // 测试简单SELECT语句,验证第一个元素columns包含id字段 r($biTest->prepareColumnsTest($sql1, $statement1, 'mysql')[0]) && p('account:name') && e('account'); // 测试简单SELECT语句,验证第一个元素columns包含account字段 r($biTest->prepareColumnsTest($sql1, $statement1, 'mysql')[1]) && p('id') && e('user'); // 测试简单SELECT语句,验证第二个元素relatedObjects包含id字段 -r(count($biTest->prepareColumnsTest($sql2, $statement2, 'mysql')[0])) && p() && e('3'); // 测试多字段SELECT语句,验证columns字段数量 \ No newline at end of file +r(count($biTest->prepareColumnsTest($sql2, $statement2, 'mysql')[0])) && p() && e('3'); // 测试多字段SELECT语句,验证columns字段数量 diff --git a/module/bi/test/model/updatedownloadingtagfile.php b/module/bi/test/model/updatedownloadingtagfile.php index 00b7eb0301..cfa61c2a0a 100755 --- a/module/bi/test/model/updatedownloadingtagfile.php +++ b/module/bi/test/model/updatedownloadingtagfile.php @@ -9,7 +9,7 @@ title=测试 biModel::updateDownloadingTagFile(); timeout=0 cid=15218 -- 执行$biTest->objectModel, 'updateDownloadingTagFile' @1 +- 检查$biTest->instance是否存在updateDownloadingTagFile方法 @1 - 执行biTest模块的updateDownloadingTagFileTest方法 @1 - 执行biTest模块的updateDownloadingTagFileTest方法,参数是'file', 'create'), array @1 - 执行biTest模块的updateDownloadingTagFileTest方法,参数是'file', 'check'), array @1 @@ -21,10 +21,10 @@ cid=15218 $biTest = new biModelTest(); -r(method_exists($biTest->objectModel, 'updateDownloadingTagFile')) && p() && e('1'); +r(method_exists($biTest->instance, 'updateDownloadingTagFile')) && p() && e('1'); r(is_string($biTest->updateDownloadingTagFileTest())) && p() && e('1'); r(in_array($biTest->updateDownloadingTagFileTest('file', 'create'), array('ok', 'fail'))) && p() && e('1'); r(in_array($biTest->updateDownloadingTagFileTest('file', 'check'), array('ok', 'fail', 'loading'))) && p() && e('1'); r(in_array($biTest->updateDownloadingTagFileTest('file', 'remove'), array('ok', 'fail'))) && p() && e('1'); r(is_string($biTest->updateDownloadingTagFileTest('extension_dm', 'create'))) && p() && e('1'); -r(is_string($biTest->updateDownloadingTagFileTest('extension_mysql', 'create'))) && p() && e('1'); \ No newline at end of file +r(is_string($biTest->updateDownloadingTagFileTest('extension_mysql', 'create'))) && p() && e('1'); diff --git a/module/block/test/lib/model.class.php b/module/block/test/lib/model.class.php index 9e2bec1310..50bdf528c6 100644 --- a/module/block/test/lib/model.class.php +++ b/module/block/test/lib/model.class.php @@ -8,6 +8,34 @@ class blockModelTest extends baseTest protected $moduleName = 'block'; protected $className = 'model'; + /** + * Test create a block. + * + * @param object $block + * @access public + * @return int|false + */ + public function createTest($block) + { + $blockID = $this->objectModel->create($block); + if(dao::isError()) return dao::getError(); + return $blockID; + } + + /** + * Test getBlockInitStatus method. + * + * @param string $dashboard + * @access public + * @return bool + */ + public function getBlockInitStatusTest($dashboard) + { + $result = $this->objectModel->getBlockInitStatus($dashboard); + if(dao::isError()) return dao::getError(); + return $result; + } + /** * Test getModelType4Projects method. * @@ -17,8 +45,66 @@ class blockModelTest extends baseTest */ public function getModelType4ProjectsTest($projectIdList = array()) { - $result = $this->invokeArgs('getModelType4Projects', array($projectIdList)); + $result = $this->invokeArgs('getModelType4Projects', [$projectIdList]); if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test getMyDashboard method. + * + * @param string $dashboard + * @access public + * @return object + */ + public function getMyDashboardTest(string $dashboard) + { + $result = $this->objectModel->getMyDashboard($dashboard); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test getSpecifiedBlockID method. + * + * @param string $dashboard + * @param string $module + * @param string $code + * @access public + * @return int|false + */ + public function getSpecifiedBlockIDTest(string $dashboard, string $module, string $code) + { + $result = $this->objectModel->getSpecifiedBlockID($dashboard, $module, $code); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test reset method. + * + * @param string $dashboard + * @access public + * @return bool + */ + public function resetTest(string $dashboard) + { + $result = $this->objectModel->reset($dashboard); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Update a block. + * + * @param object $block + * @access public + * @return int|false + */ + public function updateTest($block) + { + $blockID = $this->objectModel->update($block); + if(dao::isError()) return dao::getError(); + return $blockID; + } } diff --git a/module/block/test/lib/zen.class.php b/module/block/test/lib/zen.class.php index 431aa15596..d744de1f47 100644 --- a/module/block/test/lib/zen.class.php +++ b/module/block/test/lib/zen.class.php @@ -17,10 +17,11 @@ class blockZenTest extends baseTest */ public function printBuildBlockTest(object $block) { - $this->invokeArgs('printBuildBlock', array($block)); + $this->invokeArgs('printBuildBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->builds)) { @@ -46,10 +47,11 @@ class blockZenTest extends baseTest */ public function printCaseBlockTest(object $block) { - $this->invokeArgs('printCaseBlock', array($block)); + $this->invokeArgs('printCaseBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->cases)) { @@ -75,11 +77,13 @@ class blockZenTest extends baseTest public function printDocDynamicBlockTest() { ob_start(); - $this->invokeArgs('printDocDynamicBlock', array()); + $this->invokeArgs('printDocDynamicBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->actions)) { @@ -114,11 +118,13 @@ class blockZenTest extends baseTest public function printDocMyCollectionBlockTest() { ob_start(); - $this->invokeArgs('printDocMyCollectionBlock', array()); + $this->invokeArgs('printDocMyCollectionBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->docList)) { @@ -144,11 +150,13 @@ class blockZenTest extends baseTest public function printDocCollectListBlockTest() { ob_start(); - $this->invokeArgs('printDocCollectListBlock', array()); + $this->invokeArgs('printDocCollectListBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->docList)) { @@ -174,11 +182,13 @@ class blockZenTest extends baseTest public function printDocMyCreatedBlockTest() { ob_start(); - $this->invokeArgs('printDocMyCreatedBlock', array()); + $this->invokeArgs('printDocMyCreatedBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->docList)) { @@ -204,11 +214,13 @@ class blockZenTest extends baseTest public function printDocRecentUpdateBlockTest() { ob_start(); - $this->invokeArgs('printDocRecentUpdateBlock', array()); + $this->invokeArgs('printDocRecentUpdateBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->docList)) { @@ -234,11 +246,13 @@ class blockZenTest extends baseTest public function printDocViewListBlockTest() { ob_start(); - $this->invokeArgs('printDocViewListBlock', array()); + $this->invokeArgs('printDocViewListBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->docList)) { @@ -264,10 +278,11 @@ class blockZenTest extends baseTest */ public function printExecutionListBlockTest(object $block) { - $this->invokeArgs('printExecutionListBlock', array($block)); + $this->invokeArgs('printExecutionListBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->executions)) { @@ -294,16 +309,17 @@ class blockZenTest extends baseTest */ public function printExecutionStatisticBlockTest(object $block, array $params = array()) { - $this->invokeArgs('printExecutionStatisticBlock', array($block, $params)); + $this->invokeArgs('printExecutionStatisticBlock', [$block, $params]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->executionsCount = isset($view->executions) ? count($view->executions) : 0; - $result->projectsCount = isset($view->projects) ? count($view->projects) : 0; - $result->hasChartData = isset($view->chartData) ? 1 : 0; + $result->executionsCount = isset($view->executions) ? count($view->executions) : 0; + $result->projectsCount = isset($view->projects) ? count($view->projects) : 0; + $result->hasChartData = isset($view->chartData) ? 1 : 0; $result->labelsCount = isset($view->chartData['labels']) ? count($view->chartData['labels']) : 0; - $result->currentProjectID = isset($view->currentProjectID) ? $view->currentProjectID : 0; + $result->currentProjectID = isset($view->currentProjectID) ? $view->currentProjectID : 0; return $result; } @@ -316,20 +332,21 @@ class blockZenTest extends baseTest */ public function printGuideBlockTest(object $block) { - $this->invokeArgs('printGuideBlock', array($block)); + $this->invokeArgs('printGuideBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->blockID = isset($view->blockID) ? $view->blockID : 0; - $result->programsCount = isset($view->programs) ? count($view->programs) : 0; - $result->programID = isset($view->programID) ? $view->programID : 0; - $result->URSRListCount = isset($view->URSRList) ? count($view->URSRList) : 0; - $result->URSR = isset($view->URSR) ? $view->URSR : ''; - $result->programLink = isset($view->programLink) ? $view->programLink : ''; - $result->productLink = isset($view->productLink) ? $view->productLink : ''; - $result->projectLink = isset($view->projectLink) ? $view->projectLink : ''; - $result->executionLink = isset($view->executionLink) ? $view->executionLink : ''; + $result->blockID = isset($view->blockID) ? $view->blockID : 0; + $result->programsCount = isset($view->programs) ? count($view->programs) : 0; + $result->programID = isset($view->programID) ? $view->programID : 0; + $result->URSRListCount = isset($view->URSRList) ? count($view->URSRList) : 0; + $result->URSR = isset($view->URSR) ? $view->URSR : ''; + $result->programLink = isset($view->programLink) ? $view->programLink : ''; + $result->productLink = isset($view->productLink) ? $view->productLink : ''; + $result->projectLink = isset($view->projectLink) ? $view->projectLink : ''; + $result->executionLink = isset($view->executionLink) ? $view->executionLink : ''; return $result; } @@ -341,17 +358,18 @@ class blockZenTest extends baseTest */ public function printMonthlyProgressBlockTest() { - $this->invokeArgs('printMonthlyProgressBlock', array()); + $this->invokeArgs('printMonthlyProgressBlock'); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->doneStoryEstimateCount = isset($view->doneStoryEstimate) ? count($view->doneStoryEstimate) : 0; - $result->doneStoryCountCount = isset($view->doneStoryCount) ? count($view->doneStoryCount) : 0; - $result->createStoryCountCount = isset($view->createStoryCount) ? count($view->createStoryCount) : 0; - $result->fixedBugCountCount = isset($view->fixedBugCount) ? count($view->fixedBugCount) : 0; - $result->createBugCountCount = isset($view->createBugCount) ? count($view->createBugCount) : 0; - $result->totalDataArrays = $result->doneStoryEstimateCount + $result->doneStoryCountCount + $result->createStoryCountCount + $result->fixedBugCountCount + $result->createBugCountCount; + $result->doneStoryCountCount = isset($view->doneStoryCount) ? count($view->doneStoryCount) : 0; + $result->createStoryCountCount = isset($view->createStoryCount) ? count($view->createStoryCount) : 0; + $result->fixedBugCountCount = isset($view->fixedBugCount) ? count($view->fixedBugCount) : 0; + $result->createBugCountCount = isset($view->createBugCount) ? count($view->createBugCount) : 0; + $result->totalDataArrays = $result->doneStoryEstimateCount + $result->doneStoryCountCount + $result->createStoryCountCount + $result->fixedBugCountCount + $result->createBugCountCount; return $result; } @@ -365,14 +383,15 @@ class blockZenTest extends baseTest public function printPlanBlockTest(object $block) { ob_start(); - $this->invokeArgs('printPlanBlock', array($block)); + $this->invokeArgs('printPlanBlock', [$block]); ob_end_clean(); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->productsCount = isset($view->products) ? count($view->products) : 0; - $result->plansCount = isset($view->plans) ? count($view->plans) : 0; + $result->plansCount = isset($view->plans) ? count($view->plans) : 0; if(isset($view->plans)) { foreach($view->plans as $index => $plan) @@ -394,14 +413,16 @@ class blockZenTest extends baseTest public function printProductDocBlockTest(object $block, array $params = array()) { ob_start(); - $this->invokeArgs('printProductDocBlock', array($block, $params)); + $this->invokeArgs('printProductDocBlock', [$block, $params]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->type = isset($view->type) ? $view->type : ''; - $result->usersCount = isset($view->users) ? count($view->users) : 0; + $result->type = isset($view->type) ? $view->type : ''; + $result->usersCount = isset($view->users) ? count($view->users) : 0; $result->productsCount = isset($view->products) ? count($view->products) : 0; $result->docGroupCount = isset($view->docGroup) ? count($view->docGroup) : 0; if(isset($view->products)) @@ -424,15 +445,17 @@ class blockZenTest extends baseTest public function printProductListBlockTest(object $block) { ob_start(); - $this->invokeArgs('printProductListBlock', array($block)); + $this->invokeArgs('printProductListBlock', [$block]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->productStatsCount = isset($view->productStats) ? count($view->productStats) : 0; - $result->usersCount = isset($view->users) ? count($view->users) : 0; - $result->avatarListCount = isset($view->avatarList) ? count($view->avatarList) : 0; + $result->usersCount = isset($view->users) ? count($view->users) : 0; + $result->avatarListCount = isset($view->avatarList) ? count($view->avatarList) : 0; if(isset($view->productStats)) { foreach($view->productStats as $index => $product) @@ -452,10 +475,11 @@ class blockZenTest extends baseTest */ public function printProductStatisticBlockTest(object $block) { - $this->invokeArgs('printProductStatisticBlock', array($block)); + $this->invokeArgs('printProductStatisticBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->productsCount = isset($view->products) ? count($view->products) : 0; if(isset($view->products)) @@ -477,10 +501,11 @@ class blockZenTest extends baseTest */ public function printProjectOverviewBlockTest(object $block) { - $this->invokeArgs('printProjectOverviewBlock', array($block)); + $this->invokeArgs('printProjectOverviewBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->groupsCount = isset($view->groups) ? count($view->groups) : 0; @@ -500,7 +525,7 @@ class blockZenTest extends baseTest if(isset($group->type) && $group->type == 'barChart' && isset($group->bars)) { $result->$groupKey->barsCount = count($group->bars); - $result->$groupKey->title = isset($group->title) ? $group->title : ''; + $result->$groupKey->title = isset($group->title) ? $group->title : ''; } } } @@ -517,14 +542,16 @@ class blockZenTest extends baseTest public function printProjectStatisticBlockTest(object $block) { ob_start(); - $this->invokeArgs('printProjectStatisticBlock', array($block)); + $this->invokeArgs('printProjectStatisticBlock', [$block]); ob_get_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->projectCount = isset($view->projects) ? count($view->projects) : 0; - $result->userCount = isset($view->users) ? count($view->users) : 0; + $result->userCount = isset($view->users) ? count($view->users) : 0; if(isset($view->projects)) { @@ -532,8 +559,8 @@ class blockZenTest extends baseTest { $projectKey = 'project' . $index; $result->$projectKey = new stdClass(); - $result->$projectKey->id = isset($project->id) ? $project->id : 0; - $result->$projectKey->name = isset($project->name) ? $project->name : ''; + $result->$projectKey->id = isset($project->id) ? $project->id : 0; + $result->$projectKey->name = isset($project->name) ? $project->name : ''; $result->$projectKey->status = isset($project->status) ? $project->status : ''; } } @@ -549,24 +576,26 @@ class blockZenTest extends baseTest public function printScrumOverviewBlockTest() { ob_start(); - $this->invokeArgs('printScrumOverviewBlock', array()); + $this->invokeArgs('printScrumOverviewBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->projectID = isset($view->projectID) ? $view->projectID : 0; - $result->hasProject = isset($view->project) ? 1 : 0; + $result->projectID = isset($view->projectID) ? $view->projectID : 0; + $result->hasProject = isset($view->project) ? 1 : 0; if(isset($view->project)) { $project = $view->project; - $result->projectName = isset($project->name) ? $project->name : ''; - $result->projectModel = isset($project->model) ? $project->model : ''; - $result->executionsCount = isset($project->executions) ? count($project->executions) : 0; - $result->storyPoints = isset($project->storyPoints) ? $project->storyPoints : 0; - $result->tasks = isset($project->tasks) ? $project->tasks : 0; - $result->bugs = isset($project->bugs) ? $project->bugs : 0; + $result->projectName = isset($project->name) ? $project->name : ''; + $result->projectModel = isset($project->model) ? $project->model : ''; + $result->executionsCount = isset($project->executions) ? count($project->executions) : 0; + $result->storyPoints = isset($project->storyPoints) ? $project->storyPoints : 0; + $result->tasks = isset($project->tasks) ? $project->tasks : 0; + $result->bugs = isset($project->bugs) ? $project->bugs : 0; } return $result; @@ -581,14 +610,15 @@ class blockZenTest extends baseTest */ public function printScrumProductBlockTest(object $block) { - $this->invokeArgs('printScrumProductBlock', array($block)); + $this->invokeArgs('printScrumProductBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->productsCount = isset($view->products) ? count($view->products) : 0; - $result->storiesCount = isset($view->stories) ? count($view->stories) : 0; - $result->bugsCount = isset($view->bugs) ? count($view->bugs) : 0; + $result->storiesCount = isset($view->stories) ? count($view->stories) : 0; + $result->bugsCount = isset($view->bugs) ? count($view->bugs) : 0; $result->releasesCount = isset($view->releases) ? count($view->releases) : 0; if(isset($view->products)) @@ -596,10 +626,11 @@ class blockZenTest extends baseTest foreach($view->products as $productID => $productName) { $productKey = 'product' . $productID; + $result->$productKey = new stdClass(); - $result->$productKey->name = $productName; - $result->$productKey->storyTotal = isset($view->stories[$productID]) ? $view->stories[$productID] : 0; - $result->$productKey->bugTotal = isset($view->bugs[$productID]) ? $view->bugs[$productID] : 0; + $result->$productKey->name = $productName; + $result->$productKey->storyTotal = isset($view->stories[$productID]) ? $view->stories[$productID] : 0; + $result->$productKey->bugTotal = isset($view->bugs[$productID]) ? $view->bugs[$productID] : 0; $result->$productKey->releaseTotal = isset($view->releases[$productID]) ? $view->releases[$productID] : 0; } } @@ -617,17 +648,19 @@ class blockZenTest extends baseTest public function printScrumRoadMapBlockTest(int $productID = 0, int $roadMapID = 0) { ob_start(); - $this->invokeArgs('printScrumRoadMapBlock', array($productID, $roadMapID)); + $this->invokeArgs('printScrumRoadMapBlock', [$productID, $roadMapID]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->productsCount = isset($view->products) ? count($view->products) : 0; - $result->roadmapsCount = isset($view->roadmaps) ? count($view->roadmaps) : 0; - $result->productID = isset($view->productID) ? $view->productID : 0; - $result->roadMapID = isset($view->roadMapID) ? $view->roadMapID : 0; - $result->sync = isset($view->sync) ? $view->sync : 0; + $result->productsCount = isset($view->products) ? count($view->products) : 0; + $result->roadmapsCount = isset($view->roadmaps) ? count($view->roadmaps) : 0; + $result->productID = isset($view->productID) ? $view->productID : 0; + $result->roadMapID = isset($view->roadMapID) ? $view->roadMapID : 0; + $result->sync = isset($view->sync) ? $view->sync : 0; if(isset($view->roadmaps)) { @@ -652,14 +685,15 @@ class blockZenTest extends baseTest */ public function printScrumTestBlockTest(object $block) { - $this->invokeArgs('printScrumTestBlock', array($block)); + $this->invokeArgs('printScrumTestBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->projectID = (isset($view->project) && $view->project) ? $view->project->id : 0; + $result->projectID = (isset($view->project) && $view->project) ? $view->project->id : 0; $result->projectName = (isset($view->project) && $view->project) ? $view->project->name : ''; - $result->type = isset($block->params->type) ? $block->params->type : ''; + $result->type = isset($block->params->type) ? $block->params->type : ''; if(isset($view->testtasks)) { $result->count = count($view->testtasks); @@ -684,19 +718,20 @@ class blockZenTest extends baseTest */ public function printSingleBugStatisticBlockTest(object $block) { - $this->invokeArgs('printSingleBugStatisticBlock', array($block)); + $this->invokeArgs('printSingleBugStatisticBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->productID = isset($view->productID) ? $view->productID : 0; - $result->totalBugs = isset($view->totalBugs) ? $view->totalBugs : 0; - $result->closedBugs = isset($view->closedBugs) ? $view->closedBugs : 0; - $result->unresovledBugs = isset($view->unresovledBugs) ? $view->unresovledBugs : 0; - $result->resolvedRate = isset($view->resolvedRate) ? $view->resolvedRate : 0; - $result->monthsCount = isset($view->months) ? count($view->months) : 0; - $result->activateBugsCount = isset($view->activateBugs) ? count($view->activateBugs) : 0; - $result->closeBugsCount = isset($view->closeBugs) ? count($view->closeBugs) : 0; + $result->productID = isset($view->productID) ? $view->productID : 0; + $result->totalBugs = isset($view->totalBugs) ? $view->totalBugs : 0; + $result->closedBugs = isset($view->closedBugs) ? $view->closedBugs : 0; + $result->unresovledBugs = isset($view->unresovledBugs) ? $view->unresovledBugs : 0; + $result->resolvedRate = isset($view->resolvedRate) ? $view->resolvedRate : 0; + $result->monthsCount = isset($view->months) ? count($view->months) : 0; + $result->activateBugsCount = isset($view->activateBugs) ? count($view->activateBugs) : 0; + $result->closeBugsCount = isset($view->closeBugs) ? count($view->closeBugs) : 0; return $result; } @@ -709,15 +744,17 @@ class blockZenTest extends baseTest public function printSingleDynamicBlockTest() { ob_start(); - $this->invokeArgs('printSingleDynamicBlock', array()); + $this->invokeArgs('printSingleDynamicBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->productID = isset($view->productID) ? $view->productID : 0; - $result->actionsCount = isset($view->actions) ? count($view->actions) : 0; - $result->usersCount = isset($view->users) ? count($view->users) : 0; + $result->productID = isset($view->productID) ? $view->productID : 0; + $result->actionsCount = isset($view->actions) ? count($view->actions) : 0; + $result->usersCount = isset($view->users) ? count($view->users) : 0; if(isset($view->actions)) { @@ -738,28 +775,28 @@ class blockZenTest extends baseTest */ public function printSingleMonthlyProgressBlockTest($productID = 1) { - global $tester; - // 设置session中的产品ID - $tester->session->product = $productID; + $this->instance->session->product = $productID; // 调用方法 ob_start(); - $this->invokeArgs('printSingleMonthlyProgressBlock', array()); + $this->invokeArgs('printSingleMonthlyProgressBlock'); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->productID = $productID; // 获取view中设置的数据 - $result->doneStoryEstimate = isset($view->doneStoryEstimate) ? $view->doneStoryEstimate : array(); - $result->doneStoryCount = isset($view->doneStoryCount) ? $view->doneStoryCount : array(); - $result->createStoryCount = isset($view->createStoryCount) ? $view->createStoryCount : array(); - $result->fixedBugCount = isset($view->fixedBugCount) ? $view->fixedBugCount : array(); - $result->createBugCount = isset($view->createBugCount) ? $view->createBugCount : array(); - $result->releaseCount = isset($view->releaseCount) ? $view->releaseCount : array(); + $result->doneStoryEstimate = isset($view->doneStoryEstimate) ? $view->doneStoryEstimate : []; + $result->doneStoryCount = isset($view->doneStoryCount) ? $view->doneStoryCount : []; + $result->createStoryCount = isset($view->createStoryCount) ? $view->createStoryCount : []; + $result->fixedBugCount = isset($view->fixedBugCount) ? $view->fixedBugCount : []; + $result->createBugCount = isset($view->createBugCount) ? $view->createBugCount : []; + $result->releaseCount = isset($view->releaseCount) ? $view->releaseCount : []; // 统计数据 $result->doneStoryEstimateCount = count($result->doneStoryEstimate); @@ -782,20 +819,20 @@ class blockZenTest extends baseTest */ public function printSinglePlanBlockTest(object $block, int $productID = 1) { - global $tester; - // 设置session中的产品ID - $tester->session->product = $productID; + $this->instance->session->product = $productID; // 调用方法 ob_start(); - $this->invokeArgs('printSinglePlanBlock', array($block)); + $this->invokeArgs('printSinglePlanBlock', [$block]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->plansCount = isset($view->plans) ? count($view->plans) : 0; + $result->plansCount = isset($view->plans) ? count($view->plans) : 0; $result->productsCount = isset($view->products) ? count($view->products) : 0; if(isset($view->plans)) @@ -824,21 +861,21 @@ class blockZenTest extends baseTest */ public function printSingleReleaseBlockTest(object $block, int $productID = 1) { - global $tester; - // 设置session中的产品ID - $tester->session->product = $productID; + $this->instance->session->product = $productID; // 调用方法 ob_start(); - $this->invokeArgs('printSingleReleaseBlock', array($block)); + $this->invokeArgs('printSingleReleaseBlock', [$block]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->releasesCount = isset($view->releases) ? count($view->releases) : 0; - $result->buildsCount = isset($view->builds) ? count($view->builds) : 0; + $result->buildsCount = isset($view->builds) ? count($view->builds) : 0; if(isset($view->releases)) { @@ -865,21 +902,22 @@ class blockZenTest extends baseTest */ public function printSingleStatisticBlockTest(object $block) { - $this->invokeArgs('printSingleStatisticBlock', array($block)); + $this->invokeArgs('printSingleStatisticBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->productID = isset($view->product) && isset($view->product->id) ? $view->product->id : 0; - $result->productName = isset($view->product) && isset($view->product->name) ? $view->product->name : ''; + $result->productID = isset($view->product) && isset($view->product->id) ? $view->product->id : 0; + $result->productName = isset($view->product) && isset($view->product->name) ? $view->product->name : ''; $result->storyDeliveryRate = isset($view->product) && isset($view->product->storyDeliveryRate) ? $view->product->storyDeliveryRate : 0; - $result->totalStories = isset($view->product) && isset($view->product->totalStories) ? $view->product->totalStories : 0; - $result->closedStories = isset($view->product) && isset($view->product->closedStories) ? $view->product->closedStories : 0; - $result->unclosedStories = isset($view->product) && isset($view->product->unclosedStories) ? $view->product->unclosedStories : 0; - $result->hasNewPlan = isset($view->product) && isset($view->product->newPlan) && $view->product->newPlan ? 1 : 0; - $result->hasNewExecution = isset($view->product) && isset($view->product->newExecution) && $view->product->newExecution ? 1 : 0; - $result->hasNewRelease = isset($view->product) && isset($view->product->newRelease) && $view->product->newRelease ? 1 : 0; - $result->monthFinishCount = isset($view->product) && isset($view->product->monthFinish) ? count($view->product->monthFinish) : 0; + $result->totalStories = isset($view->product) && isset($view->product->totalStories) ? $view->product->totalStories : 0; + $result->closedStories = isset($view->product) && isset($view->product->closedStories) ? $view->product->closedStories : 0; + $result->unclosedStories = isset($view->product) && isset($view->product->unclosedStories) ? $view->product->unclosedStories : 0; + $result->hasNewPlan = isset($view->product) && isset($view->product->newPlan) && $view->product->newPlan ? 1 : 0; + $result->hasNewExecution = isset($view->product) && isset($view->product->newExecution) && $view->product->newExecution ? 1 : 0; + $result->hasNewRelease = isset($view->product) && isset($view->product->newRelease) && $view->product->newRelease ? 1 : 0; + $result->monthFinishCount = isset($view->product) && isset($view->product->monthFinish) ? count($view->product->monthFinish) : 0; $result->monthCreatedCount = isset($view->product) && isset($view->product->monthCreated) ? count($view->product->monthCreated) : 0; return $result; } @@ -894,11 +932,13 @@ class blockZenTest extends baseTest public function printStoryBlockTest(object $block) { ob_start(); - $this->invokeArgs('printStoryBlock', array($block)); + $this->invokeArgs('printStoryBlock', [$block]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->storiesCount = isset($view->stories) ? count($view->stories) : 0; @@ -923,11 +963,13 @@ class blockZenTest extends baseTest public function printSingleStoryBlockTest(object $block) { ob_start(); - $this->invokeArgs('printSingleStoryBlock', array($block)); + $this->invokeArgs('printSingleStoryBlock', [$block]); ob_end_clean(); + if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->storiesCount = isset($view->stories) ? count($view->stories) : 0; @@ -951,10 +993,11 @@ class blockZenTest extends baseTest */ public function printTaskBlockTest(object $block) { - $this->invokeArgs('printTaskBlock', array($block)); + $this->invokeArgs('printTaskBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->tasksCount = isset($view->tasks) ? count($view->tasks) : 0; @@ -978,14 +1021,15 @@ class blockZenTest extends baseTest */ public function printTesttaskBlockTest(object $block) { - $this->invokeArgs('printTesttaskBlock', array($block)); + $this->invokeArgs('printTesttaskBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); $result->testtasksCount = isset($view->testtasks) ? count($view->testtasks) : 0; - $result->type = $block->params->type ?? ''; - $result->count = $block->params->count ?? 0; + $result->type = $block->params->type ?? ''; + $result->count = $block->params->count ?? 0; if(isset($view->testtasks)) { @@ -1011,21 +1055,22 @@ class blockZenTest extends baseTest */ public function printTeamAchievementBlockTest() { - $this->invokeArgs('printTeamAchievementBlock', array()); + $this->invokeArgs('printTeamAchievementBlock'); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->finishedTasks = isset($view->finishedTasks) ? $view->finishedTasks : 0; - $result->yesterdayTasks = isset($view->yesterdayTasks) ? $view->yesterdayTasks : 0; - $result->createdStories = isset($view->createdStories) ? $view->createdStories : 0; + $result->finishedTasks = isset($view->finishedTasks) ? $view->finishedTasks : 0; + $result->yesterdayTasks = isset($view->yesterdayTasks) ? $view->yesterdayTasks : 0; + $result->createdStories = isset($view->createdStories) ? $view->createdStories : 0; $result->yesterdayStories = isset($view->yesterdayStories) ? $view->yesterdayStories : 0; - $result->closedBugs = isset($view->closedBugs) ? $view->closedBugs : 0; - $result->yesterdayBugs = isset($view->yesterdayBugs) ? $view->yesterdayBugs : 0; - $result->runCases = isset($view->runCases) ? $view->runCases : 0; - $result->yesterdayCases = isset($view->yesterdayCases) ? $view->yesterdayCases : 0; - $result->consumedHours = isset($view->consumedHours) ? $view->consumedHours : 0; - $result->yesterdayHours = isset($view->yesterdayHours) ? $view->yesterdayHours : 0; + $result->closedBugs = isset($view->closedBugs) ? $view->closedBugs : 0; + $result->yesterdayBugs = isset($view->yesterdayBugs) ? $view->yesterdayBugs : 0; + $result->runCases = isset($view->runCases) ? $view->runCases : 0; + $result->yesterdayCases = isset($view->yesterdayCases) ? $view->yesterdayCases : 0; + $result->consumedHours = isset($view->consumedHours) ? $view->consumedHours : 0; + $result->yesterdayHours = isset($view->yesterdayHours) ? $view->yesterdayHours : 0; return $result; } @@ -1038,23 +1083,24 @@ class blockZenTest extends baseTest */ public function printWaterfallEstimateBlockTest() { - $this->invokeArgs('printWaterfallEstimateBlock', array()); + $this->invokeArgs('printWaterfallEstimateBlock'); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->people = isset($view->people) ? $view->people : 0; - $result->members = isset($view->members) ? $view->members : 0; - $result->consumed = isset($view->consumed) ? $view->consumed : 0; + $result->people = isset($view->people) ? $view->people : 0; + $result->members = isset($view->members) ? $view->members : 0; + $result->consumed = isset($view->consumed) ? $view->consumed : 0; $result->totalLeft = isset($view->totalLeft) ? $view->totalLeft : 0; - $result->hasBudget = isset($view->budget) ? 1 : 0; + $result->hasBudget = isset($view->budget) ? 1 : 0; if(isset($view->budget)) { - $result->budgetScale = isset($view->budget->scale) ? $view->budget->scale : 0; - $result->budgetProductivity = isset($view->budget->productivity) ? $view->budget->productivity : 0; - $result->budgetDuration = isset($view->budget->duration) ? $view->budget->duration : 0; - $result->budgetUnitLaborCost = isset($view->budget->unitLaborCost) ? $view->budget->unitLaborCost : 0; + $result->budgetScale = isset($view->budget->scale) ? $view->budget->scale : 0; + $result->budgetProductivity = isset($view->budget->productivity) ? $view->budget->productivity : 0; + $result->budgetDuration = isset($view->budget->duration) ? $view->budget->duration : 0; + $result->budgetUnitLaborCost = isset($view->budget->unitLaborCost) ? $view->budget->unitLaborCost : 0; $result->budgetTotalLaborCost = isset($view->budget->totalLaborCost) ? $view->budget->totalLaborCost : 0; } @@ -1069,16 +1115,17 @@ class blockZenTest extends baseTest */ public function printWaterfallGeneralReportBlockTest() { - $this->invokeArgs('printWaterfallGeneralReportBlock', array()); + $this->invokeArgs('printWaterfallGeneralReportBlock'); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->pv = isset($view->pv) ? $view->pv : 0; - $result->ev = isset($view->ev) ? $view->ev : 0; - $result->ac = isset($view->ac) ? $view->ac : 0; - $result->sv = isset($view->sv) ? $view->sv : 0; - $result->cv = isset($view->cv) ? $view->cv : 0; + $result->pv = isset($view->pv) ? $view->pv : 0; + $result->ev = isset($view->ev) ? $view->ev : 0; + $result->ac = isset($view->ac) ? $view->ac : 0; + $result->sv = isset($view->sv) ? $view->sv : 0; + $result->cv = isset($view->cv) ? $view->cv : 0; $result->progress = isset($view->progress) ? $view->progress : 0; return $result; @@ -1093,21 +1140,21 @@ class blockZenTest extends baseTest */ public function printWaterfallProgressBlockTest(int $projectID = 1) { - global $tester; - $tester->session->project = $projectID; + $this->instance->session->project = $projectID; - $this->invokeArgs('printWaterfallProgressBlock', array()); + $this->invokeArgs('printWaterfallProgressBlock'); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); - $result->hasCharts = isset($view->charts) ? 1 : 0; - $result->hasPV = isset($view->charts['pv']) ? 1 : 0; - $result->hasEV = isset($view->charts['ev']) ? 1 : 0; - $result->hasAC = isset($view->charts['ac']) ? 1 : 0; - $result->pvCount = isset($view->charts['pv']) ? count($view->charts['pv']) : 0; - $result->evCount = isset($view->charts['ev']) ? count($view->charts['ev']) : 0; - $result->acCount = isset($view->charts['ac']) ? count($view->charts['ac']) : 0; + $result->hasCharts = isset($view->charts) ? 1 : 0; + $result->hasPV = isset($view->charts['pv']) ? 1 : 0; + $result->hasEV = isset($view->charts['ev']) ? 1 : 0; + $result->hasAC = isset($view->charts['ac']) ? 1 : 0; + $result->pvCount = isset($view->charts['pv']) ? count($view->charts['pv']) : 0; + $result->evCount = isset($view->charts['ev']) ? count($view->charts['ev']) : 0; + $result->acCount = isset($view->charts['ac']) ? count($view->charts['ac']) : 0; return $result; } @@ -1121,17 +1168,18 @@ class blockZenTest extends baseTest */ public function printWaterfallRiskBlockTest(object $block) { - global $tester; - $tester->session->project = $block->params->projectID ?? 1; + $this->instance->session->project = $block->params->projectID ?? 1; - $this->invokeArgs('printWaterfallRiskBlock', array($block)); + $this->invokeArgs('printWaterfallRiskBlock', [$block]); if(dao::isError()) return dao::getError(); - $view = $this->instance->view; + $view = $this->getProperty('view'); + $result = new stdClass(); if(isset($view->risks)) { $result->count = count($view->risks); + $index = 1; foreach($view->risks as $risk) { @@ -1144,7 +1192,7 @@ class blockZenTest extends baseTest $result->count = 0; } - $result->hasUsers = isset($view->users) ? 1 : 0; + $result->hasUsers = isset($view->users) ? 1 : 0; $result->usersCount = isset($view->users) ? count($view->users) : 0; return $result; @@ -1160,8 +1208,8 @@ class blockZenTest extends baseTest */ public function processBlockForRenderTest(array $blocks, int $projectID = 0) { - $result = $this->invokeArgs('processBlockForRender', array($blocks, $projectID)); + $result = $this->invokeArgs('processBlockForRender', [$blocks, $projectID]); if(dao::isError()) return dao::getError(); return $result; } -} \ No newline at end of file +} diff --git a/module/block/test/model/checkapi.php b/module/block/test/model/checkapi.php deleted file mode 100755 index 3f044e855b..0000000000 --- a/module/block/test/model/checkapi.php +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env php -id->range('1'); - $config->owner->range('system'); - $config->module->range('sso'); - $config->key->range('key'); - $config->value->range('858640a724c2c981983935eb2bbc4ad8'); - $config->gen(1); -} - -function initEmptyConfig() -{ - $config = zenData('config'); - $config->gen(0); -} - -su('admin'); - -$blockTest = new blockModelTest(); - -// 步骤1:测试空字符串哈希值情况 -initValidConfig(); -r($blockTest->checkAPITest('')) && p('') && e('0'); - -// 步骤2:测试正确哈希值匹配情况 -initValidConfig(); -r($blockTest->checkAPITest('858640a724c2c981983935eb2bbc4ad8')) && p('') && e('1'); - -// 步骤3:测试错误哈希值不匹配情况 -initValidConfig(); -r($blockTest->checkAPITest('858640a724c2c98198wrong')) && p('') && e('0'); - -// 步骤4:测试单个字符哈希值情况 -initValidConfig(); -r($blockTest->checkAPITest('a')) && p('') && e('0'); - -// 步骤5:测试数字字符哈希值情况 -initValidConfig(); -r($blockTest->checkAPITest('123456789')) && p('') && e('0'); - -// 步骤6:测试数据库配置不存在情况 -initEmptyConfig(); -r($blockTest->checkAPITest('858640a724c2c981983935eb2bbc4ad8')) && p('') && e('0'); - -// 步骤7:测试超长哈希值输入情况 -initValidConfig(); -r($blockTest->checkAPITest('858640a724c2c981983935eb2bbc4ad8858640a724c2c981983935eb2bbc4ad8858640a724c2c981983935eb2bbc4ad8')) && p('') && e('0'); \ No newline at end of file diff --git a/module/block/test/model/updatelayout.php b/module/block/test/model/updatelayout.php index e539e70dec..60b03885e7 100755 --- a/module/block/test/model/updatelayout.php +++ b/module/block/test/model/updatelayout.php @@ -20,7 +20,7 @@ function initData() $block->params->range('{"count":10}{3},{"type":"list"}{3},{}{4}'); $block->hidden->range('0{8},1{2}'); $block->vision->range('rnd{8},lite{2}'); - + $block->gen(10); } @@ -47,4 +47,4 @@ r($tester->block->updateLayout(array(1 => array('left' => 1, 'top' => 0)))) && p r($tester->block->updateLayout(array(1 => array('left' => 2, 'top' => 3), 2 => array('left' => 0, 'top' => 6)))) && p() && e('1'); r($tester->block->updateLayout(array())) && p() && e('1'); r($tester->block->updateLayout(array(999 => array('left' => 1, 'top' => 0)))) && p() && e('1'); -r($tester->block->updateLayout(array(1 => array('left' => 1, 'top' => 0, 'invalid' => 'test')))) && p() && e('1'); \ No newline at end of file +r($tester->block->updateLayout(array(1 => array('left' => 1, 'top' => 0, 'invalid' => 'test')))) && p() && e('1'); diff --git a/module/branch/test/lib/model.class.php b/module/branch/test/lib/model.class.php index 1d2f9c2740..7965ecfa25 100644 --- a/module/branch/test/lib/model.class.php +++ b/module/branch/test/lib/model.class.php @@ -20,9 +20,7 @@ class branchModelTest extends baseTest public function getByIdTest($branchID, $productID = 0, $field = 'name') { $object = $this->instance->getById($branchID, $productID, $field); - if(dao::isError()) return dao::getError(); - return $object; } @@ -39,12 +37,9 @@ class branchModelTest extends baseTest public function getListTest($productID, $executionID = 0, $browseType = 'active', $withMainBranch = true) { $objects = $this->instance->getList($productID, $executionID, $browseType, 'order', null, $withMainBranch); - if(dao::isError()) return dao::getError(); - $ids = ''; - foreach($objects as $object) $ids .= ',' . $object->id; - return $ids; + return implode(',', array_column($objects, 'id')); } /** @@ -60,12 +55,9 @@ class branchModelTest extends baseTest public function getPairsTest($productID, $params = '', $executionID = 0, $mergedBranches = '') { $objects = $this->instance->getPairs($productID, $params, $executionID, $mergedBranches); - if(dao::isError()) return dao::getError(); - $ids = ''; - foreach($objects as $id => $object) $ids .= ',' . $id; - return $ids; + return implode(',', array_keys($objects)); } /** @@ -78,9 +70,7 @@ class branchModelTest extends baseTest public function getAllPairsTest($params = '') { $objects = $this->instance->getAllPairs($params); - if(dao::isError()) return dao::getError(); - return $objects; } @@ -94,9 +84,7 @@ class branchModelTest extends baseTest public function getStatusListTest($productID) { $result = $this->instance->getStatusList($productID); - if(dao::isError()) return dao::getError(); - return $result; } @@ -113,9 +101,7 @@ class branchModelTest extends baseTest $objectID = $this->instance->create($productID, (object) $param); if(dao::isError()) return dao::getError(); - global $tester; - $object = $tester->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($objectID)->fetch(); - return $object; + return $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($objectID)->fetch(); } /** @@ -138,9 +124,7 @@ class branchModelTest extends baseTest foreach($param as $key => $value) $newBranch->$key = $value; $objects = $this->instance->update($branchID, $newBranch); - if(dao::isError()) return dao::getError(); - return $objects; } @@ -153,10 +137,8 @@ class branchModelTest extends baseTest */ public function batchUpdateTest($param = array()) { - global $tester; - $productID = 6; - $branches = $tester->dao->select('*')->from(TABLE_BRANCH)->where('product')->eq($productID)->fetchAll('id'); + $branches = $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('product')->eq($productID)->fetchAll('id'); $newBranches = array(); foreach($branches as $branch) @@ -181,7 +163,6 @@ class branchModelTest extends baseTest } $objects = $this->instance->batchUpdate($productID, $newBranches); - if(dao::isError()) return dao::getError(); return $objects; } @@ -196,12 +177,9 @@ class branchModelTest extends baseTest public function closeTest($branchID) { $this->instance->close($branchID); - if(dao::isError()) return dao::getError(); - global $tester; - $object = $tester->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); - return $object; + return $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); } /** @@ -214,12 +192,9 @@ class branchModelTest extends baseTest public function activateTest($branchID) { $this->instance->activate($branchID); - if(dao::isError()) return dao::getError(); - global $tester; - $object = $tester->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); - return $object; + return $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); } /** @@ -232,11 +207,9 @@ class branchModelTest extends baseTest public function unlinkBranch4ProjectTest(array $productIDList): array|int { $this->instance->unlinkBranch4Project($productIDList); - if(dao::isError()) return dao::getError(); - $objects = $this->instance->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productIDList)->andWhere('branch')->gt(0)->fetchAll(); - return count($objects); + return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productIDList)->andWhere('branch')->gt(0)->fetch('count'); } /** @@ -250,11 +223,9 @@ class branchModelTest extends baseTest public function linkBranch4ProjectTest(int|array $productID): array|int { $this->instance->linkBranch4Project($productID); - if(dao::isError()) return dao::getError(); - $objects = $this->instance->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productID)->andWhere('branch')->gt(0)->fetchAll(); - return count($objects); + return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productIDList)->andWhere('branch')->gt(0)->fetch('count'); } /** @@ -270,7 +241,6 @@ class branchModelTest extends baseTest public function getByProductsTest(array $productIdList, string $params = '', array $appendBranch = array()): array|string { $objects = $this->instance->getByProducts($productIdList, $params, $appendBranch); - if(dao::isError()) return dao::getError(); $ids = ''; @@ -293,9 +263,7 @@ class branchModelTest extends baseTest public function getProductTypeTest($branchID) { $type = $this->instance->getProductType($branchID); - if(dao::isError()) return dao::getError(); - return $type; } @@ -310,12 +278,12 @@ class branchModelTest extends baseTest public function sortTest(array $branchOrderList): array|string { $branchIdList = array_keys($branchOrderList); - $this->instance->sort($branchOrderList); + $this->instance->sort($branchOrderList); if(dao::isError()) return dao::getError(); - $objects = $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('id')->in($branchIdList)->orderBy('order asc')->fetchAll('id'); - return implode(',', array_keys($objects)); + $idList = $this->instance->dao->select('id')->from(TABLE_BRANCH)->where('id')->in($branchIdList)->orderBy('`order`')->fetchPairs(); + return implode(',', $idList); } /** @@ -328,9 +296,7 @@ class branchModelTest extends baseTest public function checkBranchDataTest($branchID) { $objects = $this->instance->checkBranchData($branchID); - if(dao::isError()) return dao::getError(); - return $objects ? 1 : 2; } @@ -344,12 +310,9 @@ class branchModelTest extends baseTest public function setDefaultTest(int $productID, int $branchID) { $this->instance->setDefault($productID, $branchID); - if(dao::isError()) return dao::getError(); - $object = $this->instance->getById($branchID, $productID, ''); - - return $object; + return $this->instance->getById($branchID, $productID, ''); } /** @@ -363,7 +326,6 @@ class branchModelTest extends baseTest public function getPairsByProjectProductTest($projectID, $productID) { $objects = $this->instance->getPairsByProjectProduct($projectID, $productID); - if(dao::isError()) return dao::getError(); $names = ''; @@ -383,9 +345,7 @@ class branchModelTest extends baseTest public function showBranchTest($productID, $moduleID = 0, $executionID = 0) { $show = $this->instance->showBranch($productID, $moduleID = 0, $executionID = 0); - if(dao::isError()) return dao::getError(); - return $show ? 1 : 2; } @@ -398,20 +358,12 @@ class branchModelTest extends baseTest */ public function changeBranchLanguageTest($productID) { - global $tester; - global $app; - - $app::$loadedLangs = array(); - $app->loadLang('branch'); - $result = $this->instance->changeBranchLanguage($productID); - if(dao::isError()) return dao::getError(); if($result === false) return '0'; - $createLang = $tester->lang->branch->create; - return $createLang; + return $this->instance->lang->branch->create; } /** @@ -432,28 +384,7 @@ class branchModelTest extends baseTest if(dao::isError()) return dao::getError(); - return $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetchAll(); - } - - /** - * 合并分支后的其他数据处理。 - * other data process after merge branch. - * - * @param int $productID - * @param string $mergedBranches - * @param object $data - * @access public - * @return array|int - */ - public function afterMergeTest(int $productID, string $mergedBranches, object $data): array|int - { - $targetBranch = $data->targetBranch; - $objectID = $this->instance->afterMerge($productID, $targetBranch, $mergedBranches, $data); - - if(dao::isError()) return dao::getError(); - - $releases = $this->instance->dao->select('*')->from(TABLE_RELEASE)->where('deleted')->eq(0)->andWhere('branch')->in($data->mergedBranchIDList)->fetchAll(); - return count($releases); + return $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetchAll('', false); } /** @@ -464,7 +395,7 @@ class branchModelTest extends baseTest * @access public * @return bool */ - public function testIsClickable(int $branchID, string $status): bool + 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); @@ -481,18 +412,13 @@ class branchModelTest extends baseTest */ public function manageTest(int $productID, array $branchData = array(), array $newBranches = array()) { - global $tester; - - // 清空之前的POST数据 - $_POST = array(); - // 设置POST数据以模拟实际提交 - $_POST['branch'] = $branchData; // 确保branch总是存在,即使是空数组 + $_POST = []; + $_POST['branch'] = $branchData; // 确保branch总是存在,即使是空数组 $_POST['newbranch'] = $newBranches; // 确保newbranch总是存在 // 调用被测方法 $result = $this->instance->manage($productID); - if(dao::isError()) return dao::getError(); // 如果返回false,表示DAO错误或其他问题 diff --git a/module/branch/test/lib/tao.class.php b/module/branch/test/lib/tao.class.php index d9af59b862..7253dcfba0 100644 --- a/module/branch/test/lib/tao.class.php +++ b/module/branch/test/lib/tao.class.php @@ -8,433 +8,6 @@ class branchTaoTest extends baseTest protected $moduleName = 'branch'; protected $className = 'tao'; - /** - * Test get name by id. - * - * @param int $branchID - * @param int $productID - * @param string $field - * @access public - * @return object - */ - public function getByIdTest($branchID, $productID = 0, $field = 'name') - { - $object = $this->objectModel->getById($branchID, $productID, $field); - - if(dao::isError()) return dao::getError(); - - return $object; - } - - /** - * Test get branch list. - * - * @param int $productID - * @param int $executionID - * @param string $browseType - * @param bool $withMainBranch - * @access public - * @return string - */ - public function getListTest($productID, $executionID = 0, $browseType = 'active', $withMainBranch = true) - { - $objects = $this->objectModel->getList($productID, $executionID, $browseType, 'order', null, $withMainBranch); - - if(dao::isError()) return dao::getError(); - - $ids = ''; - foreach($objects as $object) $ids .= ',' . $object->id; - return $ids; - } - - /** - * Test get pairs. - * - * @param int $productID - * @param string $params - * @param int $executionID - * @param string $mergedBranches - * @access public - * @return string - */ - public function getPairsTest($productID, $params = '', $executionID = 0, $mergedBranches = '') - { - $objects = $this->objectModel->getPairs($productID, $params, $executionID, $mergedBranches); - - if(dao::isError()) return dao::getError(); - - $ids = ''; - foreach($objects as $id => $object) $ids .= ',' . $id; - return $ids; - } - - /** - * Test get all pairs. - * - * @param string $params - * @access public - * @return int - */ - public function getAllPairsTest($params = '') - { - $objects = $this->objectModel->getAllPairs($params); - - if(dao::isError()) return dao::getError(); - - return $objects; - } - - /** - * Test get status list. - * - * @param int $productID - * @access public - * @return array - */ - public function getStatusListTest($productID) - { - $result = $this->objectModel->getStatusList($productID); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test create a branch. - * - * @param int $productID - * @param array $param - * @access public - * @return object - */ - public function createTest($productID, $param = array()) - { - $objectID = $this->objectModel->create($productID, (object) $param); - if(dao::isError()) return dao::getError(); - - global $tester; - $object = $tester->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($objectID)->fetch(); - return $object; - } - - /** - * Test update branch. - * - * @param array $param - * @access public - * @return array - */ - public function updateTest($param) - { - $branchID = 1; - $branch = $this->objectModel->getByID((string)$branchID, 0, ''); - - $newBranch = new stdclass(); - $newBranch->name = $branch->name; - $newBranch->status = $branch->status; - $newBranch->desc = $branch->desc; - - foreach($param as $key => $value) $newBranch->$key = $value; - - $objects = $this->objectModel->update($branchID, $newBranch); - - if(dao::isError()) return dao::getError(); - - return $objects; - } - - /** - * Test batch update branch. - * - * @param array $param - * @access public - * @return object - */ - public function batchUpdateTest($param = array()) - { - global $tester; - - $productID = 6; - $branches = $tester->dao->select('*')->from(TABLE_BRANCH)->where('product')->eq($productID)->fetchAll('id'); - - $newBranches = array(); - foreach($branches as $branch) - { - $newBranch = new stdclass(); - $newBranch->branchID = $branch->id; - $newBranch->name = $branch->name; - $newBranch->desc = $branch->desc; - $newBranch->status = $branch->status; - - foreach($param as $key => $setting) - { - foreach($setting as $id => $value) - { - if($id != $branch->id) continue; - - $newBranch->$key = $value; - } - } - - $newBranches[$branch->id] = $newBranch; - } - - $objects = $this->objectModel->batchUpdate($productID, $newBranches); - - if(dao::isError()) return dao::getError(); - return $objects; - } - - /** - * Test close a branch. - * - * @param int $branchID - * @access public - * @return object - */ - public function closeTest($branchID) - { - $this->objectModel->close($branchID); - - if(dao::isError()) return dao::getError(); - - global $tester; - $object = $tester->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); - return $object; - } - - /** - * Test activate a branch. - * - * @param int $branchID - * @access public - * @return object - */ - public function activateTest($branchID) - { - $this->objectModel->activate($branchID); - - if(dao::isError()) return dao::getError(); - - global $tester; - $object = $tester->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); - return $object; - } - - /** - * Test unlink branches for projects when product type is normal. - * - * @param array $productIDList - * @access public - * @return array|int - */ - public function unlinkBranch4ProjectTest(array $productIDList): array|int - { - $this->objectModel->unlinkBranch4Project($productIDList); - - if(dao::isError()) return dao::getError(); - - $objects = $this->objectModel->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productIDList)->andWhere('branch')->gt(0)->fetchAll(); - return count($objects); - } - - /** - * 产品改为多分支类型时,处理分支关联项目。 - * Test link branches for projects when product type is not normal. - * - * @param int|array $productID - * @access public - * @return int|array - */ - public function linkBranch4ProjectTest(int|array $productID): array|int - { - $this->objectModel->linkBranch4Project($productID); - - if(dao::isError()) return dao::getError(); - - $objects = $this->objectModel->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productID)->andWhere('branch')->gt(0)->fetchAll(); - return count($objects); - } - - /** - * 按照产品分组获取分支数据。 - * Test get branch group by products. - * - * @param array $productIdList - * @param string $params - * @param array $appendBranch - * @access public - * @return array|string - */ - public function getByProductsTest(array $productIdList, string $params = '', array $appendBranch = array()): array|string - { - $objects = $this->objectModel->getByProducts($productIdList, $params, $appendBranch); - - if(dao::isError()) return dao::getError(); - - $ids = ''; - foreach($objects as $productID => $branches) - { - $ids .= "$productID:"; - foreach($branches as $branchID => $branchName) $ids .= "|$branchID"; - $ids .= ';'; - } - return $ids; - } - - /** - * Test get product bype by branch. - * - * @param int $branchID - * @access public - * @return string - */ - public function getProductTypeTest($branchID) - { - $type = $this->objectModel->getProductType($branchID); - - if(dao::isError()) return dao::getError(); - - return $type; - } - - /** - * 分支排序。 - * Test sort branch. - * - * @param array $branchOrderList - * @access public - * @return array|string - */ - public function sortTest(array $branchOrderList): array|string - { - $branchIdList = array_keys($branchOrderList); - $this->objectModel->sort($branchOrderList); - - if(dao::isError()) return dao::getError(); - - $objects = $this->objectModel->dao->select('*')->from(TABLE_BRANCH)->where('id')->in($branchIdList)->orderBy('order asc')->fetchAll('id'); - return implode(',', array_keys($objects)); - } - - /** - * Test check branch data. - * - * @param int $branchID - * @access public - * @return int - */ - public function checkBranchDataTest($branchID) - { - $objects = $this->objectModel->checkBranchData($branchID); - - if(dao::isError()) return dao::getError(); - - return $objects ? 1 : 2; - } - - /** - * Test check branch data. - * - * @param int $branchID - * @access public - * @return int - */ - public function setDefaultTest(int $productID, int $branchID) - { - $this->objectModel->setDefault($productID, $branchID); - - if(dao::isError()) return dao::getError(); - - $object = $this->objectModel->getById($branchID, $productID, ''); - - return $object; - } - - /** - * Test get branches of product which linked project. - * - * @param int $projectID - * @param int $productID - * @access public - * @return string - */ - public function getPairsByProjectProductTest($projectID, $productID) - { - $objects = $this->objectModel->getPairsByProjectProduct($projectID, $productID); - - if(dao::isError()) return dao::getError(); - - $names = ''; - foreach($objects as $id => $name) $names .= "$id:$name;"; - return $names; - } - - /** - * Test display of branch label. - * - * @param int $productID - * @param int $moduleID - * @param int $executionID - * @access public - * @return int - */ - public function showBranchTest($productID, $moduleID = 0, $executionID = 0) - { - $show = $this->objectModel->showBranch($productID, $moduleID = 0, $executionID = 0); - - if(dao::isError()) return dao::getError(); - - return $show ? 1 : 2; - } - - /** - * Test change branch language. - * - * @param int $productID - * @access public - * @return string - */ - public function changeBranchLanguageTest($productID) - { - global $tester; - global $app; - - $app::$loadedLangs = array(); - $app->loadLang('branch'); - - $result = $this->objectModel->changeBranchLanguage($productID); - - if(dao::isError()) return dao::getError(); - - if($result === false) return '0'; - - $createLang = $tester->lang->branch->create; - return $createLang; - } - - /** - * 将多个分支合并到一个分支。 - * Test merge multiple branches into one branch. - * - * @param int $productID - * @param string $mergedBranches - * @param object $data - * @access public - * @return array - */ - public function mergeBranchTest(int $productID, string $mergedBranches, object $data): array - { - $data->status = 'active'; - $data->createdDate = helper::today(); - $objectID = $this->objectModel->mergeBranch($productID, $mergedBranches, $data); - - if(dao::isError()) return dao::getError(); - - return $this->objectModel->dao->select('*')->from(TABLE_BRANCH)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetchAll(); - } - /** * 合并分支后的其他数据处理。 * other data process after merge branch. @@ -448,60 +21,10 @@ class branchTaoTest extends baseTest public function afterMergeTest(int $productID, string $mergedBranches, object $data): array|int { $targetBranch = $data->targetBranch; - $objectID = $this->objectModel->afterMerge($productID, $targetBranch, $mergedBranches, $data); + $objectID = $this->instance->afterMerge($productID, $targetBranch, $mergedBranches, $data); if(dao::isError()) return dao::getError(); - $releases = $this->objectModel->dao->select('*')->from(TABLE_RELEASE)->where('deleted')->eq(0)->andWhere('branch')->in($data->mergedBranchIDList)->fetchAll(); - return count($releases); - } - - /** - * Test for judge a action is clickable. - * - * @param int $branchID - * @param string $status - * @access public - * @return bool - */ - public function testIsClickable(int $branchID, string $status): bool - { - $branch = $this->objectModel->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch(); - return $this->objectModel->isClickable($branch, $status); - } - - /** - * Test manage branch. - * - * @param int $productID - * @param array $branchData - * @param array $newBranches - * @access public - * @return mixed - */ - public function manageTest(int $productID, array $branchData = array(), array $newBranches = array()) - { - global $tester; - - // 清空之前的POST数据 - $_POST = array(); - - // 设置POST数据以模拟实际提交 - $_POST['branch'] = $branchData; // 确保branch总是存在,即使是空数组 - $_POST['newbranch'] = $newBranches; // 确保newbranch总是存在 - - // 调用被测方法 - $result = $this->objectModel->manage($productID); - - if(dao::isError()) return dao::getError(); - - // 如果返回false,表示DAO错误或其他问题 - if($result === false) return false; - - // 如果结果包含JavaScript代码(空分支名错误),返回错误标识 - if(!is_array($result)) return 'error'; - - // 返回新创建分支的数量 - return count($result); + return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_RELEASE)->where('deleted')->eq(0)->andWhere('branch')->in($data->mergedBranchIDList)->fetch('count'); } } diff --git a/module/branch/test/model/isclickable.php b/module/branch/test/model/isclickable.php index aabd42d72f..bcaa649a2b 100755 --- a/module/branch/test/model/isclickable.php +++ b/module/branch/test/model/isclickable.php @@ -13,15 +13,15 @@ timeout=0 cid=15332 */ -$branch = new branchTest('admin'); +$branch = new branchModelTest('admin'); $idList = array(0, 2, 3, 30); -r($branch->testIsClickable($idList[0], 'activate')) && p() && e('0'); // 分支为空 -r($branch->testIsClickable($idList[1], 'activate')) && p() && e('0'); // 分支2状态为为activate,action为activate -r($branch->testIsClickable($idList[2], 'activate')) && p() && e('1'); // 分支3状态为为close,action为activate -r($branch->testIsClickable($idList[3], 'activate')) && p() && e('0'); // 分支不存在 +r($branch->isClickableTest($idList[0], 'activate')) && p() && e('0'); // 分支为空 +r($branch->isClickableTest($idList[1], 'activate')) && p() && e('0'); // 分支2状态为为activate,action为activate +r($branch->isClickableTest($idList[2], 'activate')) && p() && e('1'); // 分支3状态为为close,action为activate +r($branch->isClickableTest($idList[3], 'activate')) && p() && e('0'); // 分支不存在 -r($branch->testIsClickable($idList[0], 'close')) && p() && e('0'); // 分支为空 -r($branch->testIsClickable($idList[1], 'close')) && p() && e('1'); // 分支2状态为为activate,action为close -r($branch->testIsClickable($idList[2], 'close')) && p() && e('0'); // 分支3状态为为close,action为close -r($branch->testIsClickable($idList[3], 'close')) && 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'); // 分支不存在 diff --git a/module/bug/model.php b/module/bug/model.php index 8fc1187f1e..c25042819d 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -718,7 +718,7 @@ class bugModel extends model $staticData = array(); foreach($dateFields as $field) { - $bugCount = $this->dao->select("count(id) as num, date_format($field, '%m/%d') as date")->from(TABLE_BUG) + $bugCount = $this->dao->select("COUNT(id) AS num, DATE_FORMAT($field, '%m/%d') AS date")->from(TABLE_BUG) ->where('product')->eq($productID) ->andWhere('deleted')->eq(0) ->andWhere($field)->between($startDate, $endDate . ' 23:50:59') diff --git a/module/bug/test/lib/model.class.php b/module/bug/test/lib/model.class.php index e349ffaa4a..43a4c26139 100644 --- a/module/bug/test/lib/model.class.php +++ b/module/bug/test/lib/model.class.php @@ -35,15 +35,9 @@ class bugModelTest extends baseTest foreach($param as $key => $value) $bug->$key = $value; $objectID = $this->instance->create($bug); - if(dao::isError()) - { - return dao::getError(); - } - else - { - $object = $this->instance->getByID($objectID); - return $object; - } + if(dao::isError()) return dao::getError(); + + return $this->instance->getByID($objectID); } /** @@ -58,79 +52,10 @@ class bugModelTest extends baseTest public function createBugFromGitlabIssueTest(object $bug, int $executionID): object|int|array { $objectID = $this->instance->createBugFromGitlabIssue($bug, $executionID); + if(dao::isError()) return dao::getError(); - if(dao::isError()) - { - return dao::getError(); - } - else - { - $object = $objectID ? $this->instance->getById($objectID) : 0; - return $object; - } - } - - /** - * 测试添加bug->delay字段,内容为延期的时长(天),不延期则为0 - * Test if the bug is delayed, add the bug->delay field to show the delay time (day). - * - * @param string $deadline - * @param string $resolvedDate - * @param string $status - * @access public - * @return object|array - */ - public function appendDelayedDaysTest(string $deadline, string $resolvedDate , string $status): object|array - { - $bug = new stdclass(); - $bug->status = $status; - $bug->deadline = $deadline ? date('Y-m-d', strtotime("{$deadline} day")) : '0000-00-00'; - $bug->resolvedDate = $resolvedDate ? date('Y-m-d', strtotime("{$resolvedDate} day")) : '0000-00-00'; - - $object = $this->instance->appendDelayedDays($bug); - if(!isset($object->delay)) $object->delay = 0; - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $object; - } - } - - /** - * 测试为 bugs 批量添加延期天数。 - * Test call checkDelayBug in foreach to check if the bug is delay. - * - * @param int $productID - * @access public - * @return string|array - */ - public function batchAppendDelayedDaysTest($productID): array|string - { - global $tester; - - $tester->app->tab = 'qa'; - $bugs = $this->instance->getListByBrowseType('all', array($productID), 0, array(), 'all', array(), 0, 'id_asc', null); - $bugs = $this->instance->batchAppendDelayedDays($bugs); - - $delay = ''; - foreach($bugs as $bug) - { - $delay .= ',' . (!isset($bug->delay) ? 0 : $bug->delay); - } - $delay = trim($delay, ','); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $delay; - } + $object = $objectID ? $this->instance->getById($objectID) : 0; + return $object; } /** @@ -142,16 +67,9 @@ class bugModelTest extends baseTest */ public function getBySonarqubeIDTest($sonarqubeID) { - $array = $this->instance->getBySonarqubeID($sonarqubeID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return count($array); - } + $result = $this->instance->getBySonarqubeID($sonarqubeID); + if(dao::isError()) return dao::getError(); + return count($result); } /** @@ -165,6 +83,7 @@ class bugModelTest extends baseTest public function getPlanBugsTest(int $planID, string $status): string|array { $bugs = $this->instance->getPlanBugs($planID, $status, 'id_desc', null); + if(dao::isError()) return dao::getError(); $title = ''; foreach($bugs as $bug) @@ -174,14 +93,7 @@ class bugModelTest extends baseTest $title = trim($title, ','); $title = str_replace(array("'", '@', '$', '%', ';'), '', $title); - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -194,16 +106,10 @@ class bugModelTest extends baseTest public function getByIdTest($bugID) { $object = $this->instance->getById($bugID); - if(isset($object->title)) $object->title = str_replace("'", '', $object->title); + if(dao::isError()) return dao::getError(); - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $object; - } + if(isset($object->title)) $object->title = str_replace("'", '', $object->title); + return $object; } /** @@ -218,21 +124,15 @@ class bugModelTest extends baseTest public function getByIdListTest(string $bugIDList, string $fields, string $orderBy = ''): array|string { $bugs = $this->instance->getByIdList($bugIDList, $fields, $orderBy); + if(dao::isError()) return dao::getError(); + + if($orderBy) return implode(',', array_keys($bugs)); foreach($bugs as $bug) { if(isset($bug->title)) $bug->title = str_replace("'", '', $bug->title); } - - if(dao::isError()) - { - return dao::getError(); - } - else - { - if($orderBy) return implode(',', array_keys($bugs)); - return $bugs; - } + return $bugs; } /** @@ -246,6 +146,7 @@ class bugModelTest extends baseTest public function getActiveBugsTest($products, $excludeBugs) { $bugs = $this->instance->getActiveBugs($products, 'all', '', $excludeBugs); + if(dao::isError()) return dao::getError(); $title = ''; foreach($bugs as $bug) @@ -256,14 +157,7 @@ class bugModelTest extends baseTest $title = str_replace("'", '', $title); $title = str_replace("@", '', $title); - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -278,9 +172,7 @@ class bugModelTest extends baseTest public function getActiveAndPostponedBugsTest(array $products, int $executionID): array { $bugs = $this->instance->getActiveAndPostponedBugs($products, $executionID); - if(dao::isError()) return dao::getError(); - return $bugs; } @@ -296,9 +188,7 @@ class bugModelTest extends baseTest public function getModuleOwnerTest(int $moduleID, int $productID): array { $owner = $this->instance->getModuleOwner($moduleID, $productID); - if(dao::isError()) return dao::getError(); - return $owner; } @@ -312,11 +202,12 @@ class bugModelTest extends baseTest */ public function updateObject($bugID, $param = array()) { - global $tester; - $object = $tester->app->dbQuery("SELECT * FROM " . TABLE_BUG ." WHERE id = $bugID")->fetch(); + $oldBug = $this->instance->dao->select('*')->from(TABLE_BUG)->where('id')->eq($bugID)->fetch(); $bug = new stdclass(); - foreach($object as $field => $value) + $bug->deleteFiles = array(); + $bug->comment = ''; + foreach($oldBug as $field => $value) { if(in_array($field, array_keys($param))) { @@ -327,20 +218,12 @@ class bugModelTest extends baseTest $bug->$field = $value; } } - $bug->deleteFiles = array(); - $bug->comment = ''; - $change = $this->instance->update($bug, 'Edit'); - if($change == array()) $change = '没有数据更新'; + $result = $this->instance->update($bug, 'Edit'); + if(dao::isError()) return dao::getError(); - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $change; - } + if($result == array()) $result = '没有数据更新'; + return $result; } /** @@ -353,19 +236,13 @@ class bugModelTest extends baseTest */ public function assignTest(object $bug): array|object { - $oldBug = $this->instance->getByID($bug->id); $_SERVER['HTTP_HOST'] = ''; + + $oldBug = $this->instance->getByID($bug->id); $this->instance->assign($bug, $oldBug); - if(dao::isError()) - { - return dao::getError(); - } - else - { - global $tester; - $bug = $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); - return $bug; - } + if(dao::isError()) return dao::getError(); + + return $this->instance->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); } /** @@ -383,11 +260,9 @@ class bugModelTest extends baseTest $bug['comment'] = ''; $this->instance->confirm((object)$bug, array()); - if(dao::isError()) return dao::getError(); $newBug = $this->instance->getByID($bug['id']); - return common::createChanges($oldBug, $newBug); } @@ -426,24 +301,9 @@ class bugModelTest extends baseTest foreach($param as $key => $value) $bug->{$key} = $value; $this->instance->resolve($bug, $output); + if(dao::isError()) return str_replace('\n', '', dao::getError(true)); - if(dao::isError()) - { - $return = ''; - $errors = dao::getError(); - foreach($errors as $key => $value) - { - if(is_string($value)) $return .= "{$value}"; - if(is_array($value)) $return .= implode('', $value); - } - return $return; - } - else - { - global $tester; - $bug = $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); - return $bug; - } + return $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); } /** @@ -465,28 +325,26 @@ class bugModelTest extends baseTest $bug->activatedCount = 1; $result = $this->instance->activate($bug, $kanbanParams); - if(dao::isError()) return str_replace('\n', '', dao::getError(true)); - global $tester; - if($returnType == 'build') return $tester->loadModel('build')->getByID($buildID); + if($returnType == 'build') return $this->instance->loadModel('build')->getByID($buildID); if($returnType == 'action') { - $actionID = $tester->dao->select('id')->from(TABLE_ACTION) + $actionID = $this->instance->dao->select('id')->from(TABLE_ACTION) ->where('objectType')->eq('bug') ->andWhere('objectID')->eq($bugID) ->andWhere('action')->eq('activated') ->orderBy('id_desc') ->limit(1) ->fetch('id'); - return $tester->dao->select('*')->from(TABLE_HISTORY)->where('action')->eq($actionID)->fetchAll(); + return $this->instance->dao->select('*')->from(TABLE_HISTORY)->where('action')->eq($actionID)->fetchAll('', false); } if($returnType == 'kanban') { $bug = $this->instance->fetchByID($bugID); - return $tester->dao->select('t3.type')->from(TABLE_KANBANLANE)->alias('t1') + return $this->instance->dao->select('t3.type')->from(TABLE_KANBANLANE)->alias('t1') ->leftJoin(TABLE_KANBANCELL)->alias('t2')->on('t1.id=t2.lane AND t1.execution=t2.kanban') ->leftJoin(TABLE_KANBANCOLUMN)->alias('t3')->on('t2.column=t3.id') ->where('t1.type')->eq('bug') @@ -521,16 +379,9 @@ class bugModelTest extends baseTest $bug->comment = ''; $this->instance->close($bug, $output); + if(dao::isError()) return dao::getError(); - if(dao::isError()) - { - return dao::getError(); - } - else - { - $bug = $this->instance->fetchBugInfo($bugID); - return $bug; - } + return $this->instance->fetchBugInfo($bugID); } /** @@ -543,17 +394,10 @@ class bugModelTest extends baseTest */ public function processBuildForBugsTest(array $bugIDList): array { - $bugs = $this->instance->getByIdList($bugIDList); - $array = $this->instance->processBuildForBugs($bugs); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $array; - } + $bugs = $this->instance->getByIdList($bugIDList); + $bugs = $this->instance->processBuildForBugs($bugs); + if(dao::isError()) return dao::getError(); + return $bugs; } /** @@ -572,25 +416,17 @@ class bugModelTest extends baseTest */ public function getUserBugsTest(string $account, string $type = 'assignedTo', int $limit = 0, int $executionID = 0, int $queryID = 0, string $rawMethod = 'work', string|bool $query = false): array|int { - global $tester; if($type == 'bySearch') { $moduleName = $rawMethod == 'work' ? 'workBug' : 'contributeBug'; $queryName = $moduleName . 'Query'; $formName = $moduleName . 'Form'; - if($query) $tester->session->set($queryName, $query); + if($query) $this->instance->session->set($queryName, $query); } - $array = $this->instance->getUserBugs($account, $type, 'id_desc', $limit, null, $executionID, $queryID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return count($array); - } + $bugs = $this->instance->getUserBugs($account, $type, 'id_desc', $limit, null, $executionID, $queryID); + if(dao::isError()) return dao::getError(); + return count($bugs); } /** @@ -608,16 +444,9 @@ class bugModelTest extends baseTest */ public function getUserBugPairsTest(string $account, bool $appendProduct = true, int $limit = 0, array $skipProductIdList = array(), array $skipExecutionIdList = array(), array|int $appendBugID = 0): array|int { - $array = $this->instance->getUserBugPairs($account, $appendProduct, $limit, $skipProductIdList, $skipExecutionIdList, $appendBugID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return count($array); - } + $bugs = $this->instance->getUserBugPairs($account, $appendProduct, $limit, $skipProductIdList, $skipExecutionIdList, $appendBugID); + if(dao::isError()) return dao::getError(); + return count($bugs); } /** @@ -631,11 +460,9 @@ class bugModelTest extends baseTest public function getProjectBugsTest(int $projectID, int $productID = 0, int|string $branchID = 0, int $build = 0, string $type = '', int $param = 0, string $excludeBugs = ''): array { $bugs = $this->instance->getProjectBugs($projectID, $productID, $branchID, $build, $type, $param, $orderBy = 'id_desc', $excludeBugs); - - foreach($bugs as $bug) $bug->title = str_replace("'", '', $bug->title); - if(dao::isError()) return dao::getError(); + foreach($bugs as $bug) $bug->title = str_replace("'", '', $bug->title); return $bugs; } @@ -656,9 +483,7 @@ class bugModelTest extends baseTest public function getExecutionBugsTest(int $executionID, int $productID = 0, string|int $branchID = 'all', string|array $builds = '0', string $type = '', int $param = 0, string $excludeBugs = ''): array { $bugs = $this->instance->getExecutionBugs($executionID, $productID, $branchID, $builds, $type, $param, 'id_desc', $excludeBugs); - if(dao::isError()) return dao::getError(); - return array_values($bugs); } @@ -675,21 +500,12 @@ class bugModelTest extends baseTest */ public function getProductLeftBugsTest(array $buildIdList, int $productID, int|string $branch = '', string $linkedBugs = ''): array|string { - $array = $this->instance->getProductLeftBugs($buildIdList, $productID, $branch, $linkedBugs); + $bugs = $this->instance->getProductLeftBugs($buildIdList, $productID, $branch, $linkedBugs); + if(dao::isError()) return dao::getError(); - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); + $title = implode(',', array_column($bugs, 'title')); $title = str_replace(array("'", '@', '$', '%'), '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -703,21 +519,12 @@ class bugModelTest extends baseTest */ public function getProductBugPairsTest(int $productID, int|string $branch = ''): array|string { - $array = $this->instance->getProductBugPairs($productID, $branch); + $bugs = $this->instance->getProductBugPairs($productID, $branch); + if(dao::isError()) return dao::getError(); - $title = ''; - foreach($array as $bug) $title .= ',' . $bug; - $title = trim($title, ','); + $title = implode(',', $bugs); $title = str_replace(array("'", '@', '$', '%'), '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -729,21 +536,12 @@ class bugModelTest extends baseTest */ public function getProductMemberPairsTest(int $productID): string|array { - $array = $this->instance->getProductMemberPairs($productID); + $bugs = $this->instance->getProductMemberPairs($productID); + if(dao::isError()) return dao::getError(); - $title = ''; - foreach($array as $bug) $title .= ',' . $bug; - $title = trim($title, ','); + $title = implode(',', $bugs); $title = str_replace("'", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -757,21 +555,12 @@ class bugModelTest extends baseTest */ public function getReleaseBugsTest(int $buildID, int $productID): string|array { - $array = $this->instance->getReleaseBugs(array($buildID), $productID); + $bugs = $this->instance->getReleaseBugs(array($buildID), $productID); + if(dao::isError()) return dao::getError(); - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); + $title = implode(',', array_column($bugs, 'title')); $title = str_replace("'", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -784,22 +573,12 @@ class bugModelTest extends baseTest */ public function getStoryBugsTest(int $storyID): array|string { - $array = $this->instance->getStoryBugs($storyID); + $bugs = $this->instance->getStoryBugs($storyID); + if(dao::isError()) return dao::getError(); - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); - $title = str_replace("'", '', $title); - $title = str_replace("@", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + $title = implode(',', array_column($bugs, 'title')); + $title = str_replace(["'", '@'], '', $title); + return $title; } /** @@ -814,21 +593,12 @@ class bugModelTest extends baseTest */ public function getCaseBugsTest(int $runID, int $caseID = 0, int $version = 0): string|array { - $array = $this->instance->getCaseBugs($runID, $caseID, $version); + $bugs = $this->instance->getCaseBugs($runID, $caseID, $version); + if(dao::isError()) return dao::getError(); - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); + $title = implode(',', array_column($bugs, 'title')); $title = str_replace("'", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } + return $title; } /** @@ -842,16 +612,9 @@ class bugModelTest extends baseTest */ public function getStoryBugCountsTest(array $storyIDList, int $executionID = 0): array { - $array = $this->instance->getStoryBugCounts($storyIDList, $executionID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $array; - } + $bugs = $this->instance->getStoryBugCounts($storyIDList, $executionID); + if(dao::isError()) return dao::getError(); + return $bugs; } /** @@ -865,16 +628,9 @@ class bugModelTest extends baseTest */ public function getBugInfoFromResultTest(int $resultID, int $caseID = 0): string|int|array { - $array = $this->instance->getBugInfoFromResult($resultID, $caseID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return isset($array['title']) ? $array['title'] : 0; - } + $bug = $this->instance->getBugInfoFromResult($resultID, $caseID); + if(dao::isError()) return dao::getError(); + return $bug['title'] ?? 0; } /** @@ -886,14 +642,11 @@ class bugModelTest extends baseTest */ public function getDataOfBugsPerExecutionTest(): array { - global $tester; - $tester->loadModel('report'); - $tester->session->set('project', 0); + $this->instance->loadModel('report'); + $this->instance->session->set('project', 0); $datas = $this->instance->getDataOfBugsPerExecution(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -907,9 +660,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerBuildTest(): array { $datas = $this->instance->getDataOfBugsPerBuild(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -923,9 +674,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerModuleTest() { $datas = $this->instance->getDataOfBugsPerModule(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -939,9 +688,7 @@ class bugModelTest extends baseTest public function getDataOfOpenedBugsPerDayTest(): array { $datas = $this->instance->getDataOfOpenedBugsPerDay(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -955,9 +702,7 @@ class bugModelTest extends baseTest public function getDataOfResolvedBugsPerDayTest(): array { $datas = $this->instance->getDataOfResolvedBugsPerDay(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -971,9 +716,7 @@ class bugModelTest extends baseTest public function getDataOfClosedBugsPerDayTest(): array { $datas = $this->instance->getDataOfClosedBugsPerDay(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -987,9 +730,7 @@ class bugModelTest extends baseTest public function getDataOfOpenedBugsPerUserTest(): array { $datas = $this->instance->getDataOfOpenedBugsPerUser(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1003,9 +744,7 @@ class bugModelTest extends baseTest public function getDataOfResolvedBugsPerUserTest(): array { $datas = $this->instance->getDataOfResolvedBugsPerUser(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1018,19 +757,15 @@ class bugModelTest extends baseTest */ public function getDataOfResolvedBugsPerUserTestWithEmptyData(): array { - global $tester; - $originalBugs = $tester->dao->select('*')->from(TABLE_BUG)->where('resolvedBy')->ne('')->fetchAll(); - $tester->dao->update(TABLE_BUG)->set('resolvedBy')->eq('')->where('resolvedBy')->ne('')->exec(); + $originalBugs = $this->instance->dao->select('*')->from(TABLE_BUG)->where('resolvedBy')->ne('')->fetchAll('', false); + $this->instance->dao->update(TABLE_BUG)->set('resolvedBy')->eq('')->where('resolvedBy')->ne('')->exec(); $datas = $this->instance->getDataOfResolvedBugsPerUser(); - foreach($originalBugs as $bug) { - $tester->dao->update(TABLE_BUG)->set('resolvedBy')->eq($bug->resolvedBy)->where('id')->eq($bug->id)->exec(); + $this->instance->dao->update(TABLE_BUG)->set('resolvedBy')->eq($bug->resolvedBy)->where('id')->eq($bug->id)->exec(); } - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1044,9 +779,7 @@ class bugModelTest extends baseTest public function getDataOfClosedBugsPerUserTest(): array { $datas = $this->instance->getDataOfClosedBugsPerUser(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1060,9 +793,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerSeverityTest(): array { $datas = $this->instance->getDataOfBugsPerSeverity(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1076,9 +807,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerResolutionTest(): array { $datas = $this->instance->getDataOfBugsPerResolution(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1092,9 +821,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerStatusTest(): array { $datas = $this->instance->getDataOfBugsPerStatus(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1108,9 +835,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerPriTest(): array { $datas = $this->instance->getDataOfBugsPerPri(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1124,9 +849,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerActivatedCountTest() { $datas = $this->instance->getDataOfBugsPerActivatedCount(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1140,9 +863,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerTypeTest(): array { $datas = $this->instance->getDataOfBugsPerType(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1156,9 +877,7 @@ class bugModelTest extends baseTest public function getDataOfBugsPerAssignedToTest(): array { $datas = $this->instance->getDataOfBugsPerAssignedTo(); - if(dao::isError()) return dao::getError(); - return $datas; } @@ -1188,18 +907,9 @@ class bugModelTest extends baseTest public function linkBugToBuildTest(int $bugID, int|string $resolvedBuild): array|object|bool { $this->instance->linkBugToBuild($bugID, $resolvedBuild); + if(dao::isError()) return dao::getError(); - global $tester; - $release = $tester->dao->select('id,bugs')->from(TABLE_RELEASE)->where('build')->eq($resolvedBuild)->andWhere('deleted')->eq('0')->fetch(); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $release; - } + return $this->instance->dao->select('id,bugs')->from(TABLE_RELEASE)->where('build')->eq($resolvedBuild)->andWhere('deleted')->eq('0')->fetch(); } /** @@ -1212,21 +922,10 @@ class bugModelTest extends baseTest */ public function getToAndCcListTest(int $bugID): array|string { - $bug = $this->instance->getByID($bugID); - $array = $this->instance->getToAndCcList($bug); - - $account = ''; - foreach($array as $value) $account .= ',' . $value; - $account = trim($account, ','); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $account; - } + $bug = $this->instance->getByID($bugID); + $result = $this->instance->getToAndCcList($bug); + if(dao::isError()) return dao::getError(); + return implode(',', $result); } /** @@ -1239,16 +938,9 @@ class bugModelTest extends baseTest */ public function getBugQueryTest(string $bugQuery): string|array { - $array = $this->instance->getBugQuery($bugQuery); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $array; - } + $query = $this->instance->getBugQuery($bugQuery); + if(dao::isError()) return dao::getError(); + return $query; } /** @@ -1260,22 +952,16 @@ class bugModelTest extends baseTest */ public function getStatisticTest($productID = 0) { - $dates = $this->instance->getStatistic($productID); - $returns = array(); - $today = date('m/d', time()); - foreach($dates as $dateType => $dateList) - { - $returns[$dateType] = $dateList[$today]; - } + $staticData = $this->instance->getStatistic($productID); + if(dao::isError()) return dao::getError(); - if(dao::isError()) + $result = array(); + $today = date('m/d', time()); + foreach($staticData as $dateField => $dateData) { - return dao::getError(); - } - else - { - return $returns; + $result[$dateField] = $dateData[$today]; } + return $result; } /** @@ -1291,6 +977,7 @@ class bugModelTest extends baseTest public function updateRelatedBugTest(int $bugID, string $relatedBug, string $oldRelatedBug): array|bool { $this->instance->updateRelatedBug($bugID, $relatedBug, $oldRelatedBug); + if(dao::isError()) return dao::getError(); $relatedBugs = explode(',', $relatedBug); $oldRelatedBugs = explode(',', $oldRelatedBug); @@ -1298,14 +985,10 @@ class bugModelTest extends baseTest $removedRelatedBugs = array_diff($oldRelatedBugs, $relatedBugs); $allRelatedRelatedBugs = array_merge($addedRelatedBugs, $removedRelatedBugs, array($bugID)); - global $tester; - $relatedBugPairs = $tester->dao->select('id, relatedBug')->from(TABLE_BUG) + return $this->instance->dao->select('id, relatedBug')->from(TABLE_BUG) ->where('id')->in(array_filter($allRelatedRelatedBugs)) ->andWhere('deleted')->eq('0') ->fetchPairs(); - - if(dao::isError()) return dao::getError(); - return $relatedBugPairs; } /** @@ -1317,26 +1000,12 @@ class bugModelTest extends baseTest */ public function createBuildTest(object $bug, int $bugID) { - global $tester; - $oldBug = $tester->dao->findByID($bugID)->from(TABLE_BUG)->fetch(); - $this->instance->createBuild($bug, $oldBug); + $oldBug = $this->instance->dao->findByID($bugID)->from(TABLE_BUG)->fetch(); - if(dao::isError()) - { - $errors = dao::getError(); - $return = ''; - foreach($errors as $key => $value) - { - if(is_string($value)) $return .= "{$value}"; - if(is_array($value)) $return .= implode('', $value); - } - return $return; - } - else - { - $build = $tester->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch(); - return $build; - } + $this->instance->createBuild($bug, $oldBug); + if(dao::isError()) return dao::getError(true); + + return $tester->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch(); } /** @@ -1350,20 +1019,9 @@ class bugModelTest extends baseTest public function getLinkedExecutionByIdListTest(string $buildIdList): array|string { $buildIdList = explode(',', $buildIdList); - $array = $this->instance->getLinkedExecutionByIdList($buildIdList); - - $idList = ''; - foreach($array as $execution) $idList .= ',' . $execution; - $idList = trim($idList, ','); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $idList; - } + $executions = $this->instance->getLinkedExecutionByIdList($buildIdList); + if(dao::isError()) return dao::getError(); + return implode(',', $executions); } /** @@ -1376,7 +1034,7 @@ class bugModelTest extends baseTest */ public function summaryTest(string $bugIdList): string { - $bugs = $this->instance->getByIdList($bugIdList); + $bugs = $this->instance->getByIdList($bugIdList); if(empty($bugs)) $bugs = array(); $summary = $this->instance->summary($bugs); return $summary; @@ -1392,9 +1050,8 @@ class bugModelTest extends baseTest */ public function reportConditionTest(string|bool $bugQueryCondition, bool $bugOnlyCondition): string { - global $tester; - if($bugQueryCondition) $tester->session->set('bugQueryCondition', $bugQueryCondition); - if($bugOnlyCondition) $tester->session->set('bugOnlyCondition', $bugOnlyCondition); + if($bugQueryCondition) $this->instance->session->set('bugQueryCondition', $bugQueryCondition); + if($bugOnlyCondition) $this->instance->session->set('bugOnlyCondition', $bugOnlyCondition); $reportCondition = $this->instance->reportCondition(); unset($_SESSION['bugQueryCondition']); unset($_SESSION['bugOnlyCondition']); @@ -1418,6 +1075,7 @@ class bugModelTest extends baseTest if($begin == 'lastweek') $begin = date('Y-m-d', strtotime('-7 days')); if($end == 'today') $end = date('Y-m-d', time()); if($end == 'nextweek') $end = date('Y-m-d', strtotime('+7 days')); + $bugs = $this->instance->getProductBugs(explode(',', $productIdList), $type, $begin, $end); if(dao::isError()) return dao::getError(); return implode(',', array_column($bugs, 'id')); @@ -1441,6 +1099,7 @@ class bugModelTest extends baseTest if($begin == 'lastmonth') $begin = date('Y-m-d', strtotime($date . '-30 days')); if($end == 'nextweek') $end = date('Y-m-d', strtotime($date . '+7 days')); if($end == 'nextmonth') $end = date('Y-m-d', strtotime($date . '+30 days')); + $bugs = $this->instance->getActivatedBugs(explode(',', $productIdList), $begin, $end, explode(',', $buildIdList)); if(dao::isError()) return dao::getError(); return implode(',', array_column($bugs, 'id')); @@ -1456,13 +1115,14 @@ class bugModelTest extends baseTest */ public function getLinkedBugsByTaskIDTest(int $taskID): array|string|false { - $bugs = $this->instance->getLinkedBugsByTaskID($taskID); + $bugs = $this->instance->getLinkedBugsByTaskID($taskID); + if(dao::isError()) return dao::getError(); $result = ''; foreach($bugs as $bug) $result .= "{$bug->id}:{$bug->title},"; $result = trim($result, ','); - return dao::isError() ? dao::getError() : $result; + return $result; } /** @@ -1478,44 +1138,20 @@ class bugModelTest extends baseTest */ public function buildSearchFormTest(int $productID, array $products, int $queryID, string $actionURL, string $branch = '0'): array|string { - global $tester; - // 模拟必要的session设置 - if(!isset($tester->session->project)) $tester->session->set('project', 0); + if(!$this->instance->session->project) $this->instance->session->set('project', 0); // 模拟语言配置 - if(!isset($tester->lang->all)) $tester->lang->all = 'All'; - if(!isset($tester->lang->bug->allProject)) $tester->lang->bug->allProject = 'All Projects'; - if(!isset($tester->lang->navGroup->bug)) $tester->lang->navGroup->bug = 'qa'; + if(!isset($this->instance->lang->all)) $this->instance->lang->all = 'All'; + if(!isset($this->instance->lang->bug->allProject)) $this->instance->lang->bug->allProject = 'All Projects'; + if(!isset($this->instance->lang->navGroup->bug)) $this->instance->lang->navGroup->bug = 'qa'; // 如果是教程模式,直接返回简单结果 if(defined('TUTORIAL') && TUTORIAL) return array('actionURL' => $actionURL, 'queryID' => $queryID, 'hasProductParams' => 1); - try { - $this->instance->buildSearchForm($productID, $products, $queryID, $actionURL, $branch); - } catch(Exception $e) { - // 如果调用失败,返回模拟结果 - return array('actionURL' => $actionURL, 'queryID' => $queryID, 'hasProductParams' => 1); - } - + $this->instance->buildSearchForm($productID, $products, $queryID, $actionURL, $branch); if(dao::isError()) return dao::getError(); - - $result = array(); - if(isset($tester->config->bug->search)) - { - $searchConfig = $tester->config->bug->search; - $result['actionURL'] = $searchConfig['actionURL'] ?? $actionURL; - $result['queryID'] = $searchConfig['queryID'] ?? $queryID; - $result['hasProjectParams'] = isset($searchConfig['params']['project']['values']) ? 1 : 0; - $result['hasProductParams'] = isset($searchConfig['params']['product']['values']) ? 1 : 0; - $result['hasModuleParams'] = isset($searchConfig['params']['module']['values']) ? 1 : 0; - $result['hasBranchField'] = isset($searchConfig['fields']['branch']) ? 1 : 0; - } else { - // 如果配置未设置,返回基本结果 - $result = array('actionURL' => $actionURL, 'queryID' => $queryID, 'hasProductParams' => 1); - } - - return $result; + return $this->instance->config->bug->search; } /** @@ -1528,9 +1164,7 @@ class bugModelTest extends baseTest public function buildSearchConfigTest(int $productID): array { $result = $this->instance->buildSearchConfig($productID); - if(dao::isError()) return dao::getError(); - return $result; } @@ -1544,25 +1178,22 @@ class bugModelTest extends baseTest */ public function getRelatedObjectsTest(string $object, string $pairs = ''): object { - global $tester; - /* 设置bugQueryCondition来模拟有查询条件的情况 */ $_SESSION['bugQueryCondition'] = "SELECT * FROM " . TABLE_BUG . " WHERE deleted = '0'"; - $_SESSION['bugOnlyCondition'] = true; - - $result = $this->instance->getRelatedObjects($object, $pairs); + $_SESSION['bugOnlyCondition'] = true; + $objects = $this->instance->getRelatedObjects($object, $pairs); if(dao::isError()) return (object)array('error' => dao::getError()); /* 返回详细的测试结果 */ - $testResult = new stdClass(); - $testResult->count = count($result); - $testResult->hasEmpty = isset($result['']) ? 1 : 0; - $testResult->hasZero = isset($result[0]) ? 1 : 0; - $testResult->hasTrunk = isset($result['trunk']) ? 1 : 0; - $testResult->data = $result; + $result = new stdClass(); + $result->count = count($objects); + $result->hasEmpty = isset($objects['']) ? 1 : 0; + $result->hasZero = isset($objects[0]) ? 1 : 0; + $result->hasTrunk = isset($objects['trunk']) ? 1 : 0; + $result->data = $objects; - return $testResult; + return $result; } /** @@ -1575,9 +1206,7 @@ class bugModelTest extends baseTest public function getDatatableModulesTest(int $productID): array { $result = $this->instance->getDatatableModules($productID); - if(dao::isError()) return dao::getError(); - return $result; } @@ -1593,9 +1222,7 @@ class bugModelTest extends baseTest public function updateLinkedCommitsTest(int $bugID, int $repoID, array $revisions): bool { $result = $this->instance->updateLinkedCommits($bugID, $repoID, $revisions); - if(dao::isError()) return dao::getError(); - return $result; } @@ -1606,2135 +1233,14 @@ class bugModelTest extends baseTest * @param array $revisions * @access public * @return array - */ + */ public function getLinkedCommitsTest(int $repoID, array $revisions): array { // 处理空数组情况,避免SQL语法错误 if(empty($revisions)) return array(); $result = $this->instance->getLinkedCommits($repoID, $revisions); - if(dao::isError()) return dao::getError(); - return $result; } - - /** - * Test getBatchResolveVars method. - * - * @param array $bugIDList - * @access public - * @return array|int - */ - public function getBatchResolveVarsTest(array $bugIDList): array|int - { - global $tester; - - if(empty($bugIDList)) return 0; - - $oldBugs = array(); - foreach($bugIDList as $bugID) - { - $bug = $tester->dao->select('*')->from(TABLE_BUG)->where('id')->eq($bugID)->fetch(); - if($bug) $oldBugs[] = $bug; - } - - if(empty($oldBugs)) return 0; - - $bug = reset($oldBugs); - $productID = $bug->product; - $product = $this->instance->loadModel('product')->getByID($productID); - if(!$product) return 0; - - $stmt = $tester->dao->query($this->instance->loadModel('tree')->buildMenuQuery($productID, 'bug')); - $modules = array(); - while($module = $stmt->fetch()) $modules[$module->id] = $module; - - if(dao::isError()) return dao::getError(); - - return array(count($modules), 'modules'); - } - - /** - * Test setBrowseCookie method. - * - * @param object $product - * @param string $branch - * @param string $browseType - * @param int $param - * @param string $orderBy - * @access public - * @return bool - */ - public function setBrowseCookieTest(object $product, string $branch, string $browseType, int $param, string $orderBy): bool - { - global $app; - - $app->rawModule = 'bug'; - $app->rawMethod = 'browse'; - - $zen = initReference('bug'); - $method = $zen->getMethod('setBrowseCookie'); - - $result = $method->invokeArgs($zen->newInstance(), array($product, $branch, $browseType, $param, $orderBy)); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test setCreateMenu method. - * - * @param int $productID - * @param string $branch - * @param array $output - * @access public - * @return bool - */ - public function setCreateMenuTest(int $productID, string $branch, array $output): bool - { - global $tester, $app; - - // 设置app属性 - if(isset($output['executionID'])) - { - $app->tab = 'execution'; - $tester->session->set('execution', $output['executionID']); - } - elseif(isset($output['projectID'])) - { - $app->tab = 'project'; - } - else - { - $app->tab = 'qa'; - } - - $zen = initReference('bug'); - $method = $zen->getMethod('setCreateMenu'); - - $zenInstance = $zen->newInstance(); - - // 模拟products属性避免重定向 - $products = $tester->loadModel('product')->getPairs('noclosed', 0, '', 'all'); - $zenInstance->products = $products; - - $result = $method->invokeArgs($zenInstance, array($productID, $branch, $output)); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test setEditMenu method. - * - * @param int $bugID - * @param string $tab - * @access public - * @return int - */ - public function setEditMenuTest(int $bugID, string $tab): int - { - global $tester, $app; - - // 获取bug对象 - $bug = $this->instance->getById($bugID); - if(!$bug) return 0; - - // 设置app tab - $app->tab = $tab; - - $zen = initReference('bug'); - $method = $zen->getMethod('setEditMenu'); - - $zenInstance = $zen->newInstance(); - - $result = $method->invokeArgs($zenInstance, array($bug)); - - if(dao::isError()) return 0; - - return $result ? 1 : 0; - } - - /** - * Test setViewMenu method. - * - * @param object $bug - * @param string $tab - * @access public - * @return bool - */ - public function setViewMenuTest(object $bug, string $tab): bool - { - global $tester, $app; - - // 设置app tab - $app->tab = $tab; - - try { - // 使用反射调用受保护的方法 - $zenClass = initReference('bug'); - $method = $zenClass->getMethod('setViewMenu'); - $zenInstance = $zenClass->newInstance(); - - $result = $method->invokeArgs($zenInstance, array($bug)); - - if(dao::isError()) return dao::getError(); - - return $result; - } catch (Exception $e) { - // 如果调用失败,模拟返回true(因为setViewMenu总是返回true) - return true; - } - } - - /** - * Test prepareBrowseParams method. - * - * @param string $browseType - * @param int $param - * @param string $orderBy - * @param int $recTotal - * @param int $recPerPage - * @param int $pageID - * @access public - * @return array - */ - public function prepareBrowseParamsTest(string $browseType, int $param, string $orderBy, int $recTotal, int $recPerPage, int $pageID): array - { - global $tester; - - // 设置cookie模拟 - if(!isset($_COOKIE['bugModule'])) $_COOKIE['bugModule'] = 1; - - // 创建zen实例 - $zen = initReference('bug'); - $method = $zen->getMethod('prepareBrowseParams'); - $zenInstance = $zen->newInstance(); - - // 设置必要的属性 - $zenInstance->cookie = (object)array('bugModule' => 1); - $zenInstance->app = $tester->app; - - $result = $method->invokeArgs($zenInstance, array($browseType, $param, $orderBy, $recTotal, $recPerPage, $pageID)); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test buildBrowseView method. - * - * @param array $bugs - * @param object $product - * @param string $branch - * @param string $browseType - * @param int $moduleID - * @param array $executions - * @param int $param - * @param string $orderBy - * @param object $pager - * @access public - * @return array - */ - public function buildBrowseViewTest(array $bugs, object $product, string $branch, string $browseType, int $moduleID, array $executions, int $param, string $orderBy, object $pager): array - { - global $tester; - - // 由于buildBrowseView方法主要是设置视图变量,我们模拟其主要逻辑 - // 验证参数的有效性和基本逻辑处理 - - $result = array(); - - // 验证基础参数处理 - $result['bugCount'] = count($bugs); - $result['productType'] = $product->type ?? 'normal'; - $result['branchValid'] = is_string($branch) ? 1 : 0; - $result['browseTypeValid'] = is_string($browseType) ? 1 : 0; - $result['moduleIDValid'] = is_int($moduleID) ? 1 : 0; - $result['executionCount'] = count($executions); - $result['paramValid'] = is_int($param) ? 1 : 0; - $result['orderByValid'] = is_string($orderBy) ? 1 : 0; - $result['pagerValid'] = is_object($pager) ? 1 : 0; - - // 验证bugs数组中story和task的提取逻辑 - $storyCount = 0; - $taskCount = 0; - foreach($bugs as $bug) { - if(isset($bug->story) && $bug->story > 0) $storyCount++; - if(isset($bug->task) && $bug->task > 0) $taskCount++; - if(isset($bug->toTask) && $bug->toTask > 0) $taskCount++; - } - $result['storyCount'] = $storyCount; - $result['taskCount'] = $taskCount; - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test getProductsForCreate method. - * - * @param object $bug - * @access public - * @return object|array - */ - public function getProductsForCreateTest(object $bug): object|array - { - global $tester; - - try { - // 直接模拟方法的核心逻辑,因为反射可能失败 - $productID = (int)$bug->productID; - $projectID = (int)$bug->projectID; - $executionID = (int)$bug->executionID; - - // 模拟获取产品列表 - $products = $this->instance->loadModel('product')->getPairs('noclosed', 0, '', 'all'); - $productID = isset($products[$productID]) ? $productID : key($products); - - // 根据不同tab处理产品列表 - global $app; - if($app->tab == 'project' && $projectID) - { - $products = array(); - $linkedProducts = $this->instance->loadModel('product')->getOrderedProducts('normal', 40, $projectID); - foreach($linkedProducts as $product) $products[$product->id] = $product->name; - } - elseif($app->tab == 'execution' && $executionID) - { - $products = array(); - $linkedProducts = $this->instance->loadModel('product')->getProducts($executionID); - foreach($linkedProducts as $product) $products[$product->id] = $product->name; - - $execution = $this->instance->loadModel('execution')->getByID($executionID); - if($execution) $projectID = $execution->project; - } - - // 创建返回对象 - $result = clone $bug; - $result->products = $products; - $result->productID = $productID; - $result->projectID = $projectID; - - if(dao::isError()) return dao::getError(); - - return $result; - } catch (Exception $e) { - // 如果失败,返回基本的bug对象 - $result = clone $bug; - $result->productID = $bug->productID; - return $result; - } - } - - /** - * Test getBranchesForCreate method. - * - * @param object $bug - * @access public - * @return object|array|string - */ - public function getBranchesForCreateTest(object $bug): object|array|string - { - global $tester; - - try { - // 模拟方法的核心逻辑 - $productID = (int)$bug->productID; - $branch = (string)$bug->branch; - $product = $this->instance->loadModel('product')->getByID($productID); - - if(!$product) return 'product not found'; - - global $app; - $branches = array(); - - if($app->tab == 'execution' || $app->tab == 'project') - { - $objectID = $app->tab == 'project' ? (int)$bug->projectID : (int)$bug->executionID; - if($product->type != 'normal') - { - $productBranches = $this->instance->loadModel('execution')->getBranchByProduct(array($productID), $objectID, 'noclosed|withMain'); - $branches = isset($productBranches[$productID]) ? $productBranches[$productID] : array(''); - } - else - { - $branches = array(''); - } - $branch = empty($branch) ? key($branches) : $branch; - } - else - { - if($product->type != 'normal') - { - $branches = $this->instance->loadModel('branch')->getPairs($productID, 'active'); - } - else - { - $branches = array(''); - } - $branch = isset($branches[$branch]) ? $branch : ''; - } - - $result = clone $bug; - $result->branches = $branches; - $result->branch = $branch; - - if(dao::isError()) return dao::getError(); - - return $result; - } catch (Exception $e) { - return 'error: ' . $e->getMessage(); - } - } - - /** - * Test getProjectsForCreate method. - * - * @param object $bug - * @access public - * @return object|array - */ - public function getProjectsForCreateTest(object $bug): object|array - { - global $tester; - - // 模拟方法的核心逻辑,因为反射可能不稳定 - $projectID = (int)$bug->projectID; - $productID = (int)$bug->productID; - $branch = (string)$bug->branch; - $executionID = (int)$bug->executionID; - - // 模拟获取产品信息 - $product = new stdclass(); - $product->shadow = ($productID == 5) ? 1 : 0; // 产品5为影子产品 - - // 模拟获取项目列表 - $projects = array(); - for($i = 11; $i <= 15; $i++) { - $projects[$i] = "项目{$i}"; - } - - // 检查项目ID是否有效,如果无效则选择第一个 - if(!isset($projects[$projectID])) { - $projectID = key($projects); // 选择第一个项目ID (11) - } - - // 处理执行环境下的项目获取逻辑 - if($tester->app->tab == 'execution' && $executionID && !$projectID) { - // 根据执行ID获取项目ID - if($executionID >= 101 && $executionID <= 105) { - $projectID = $executionID - 90; // 101->11, 102->12... - } - } - - // 处理影子产品逻辑 - if($product->shadow && !$projectID) { - $projectID = key($projects); - } - - // 模拟项目信息 - $project = array(); - if($projectID) { - $project = new stdclass(); - $project->id = $projectID; - $project->name = "项目{$projectID}"; - $project->model = ($projectID == 13) ? 'waterfall' : 'scrum'; - $project->multiple = ($projectID <= 13) ? 1 : 0; - - if($project->model == 'waterfall') { - // 模拟瀑布模式处理 - } - - if(!$project->multiple) { - // 模拟获取非多迭代执行ID - $executionID = $projectID + 90; // 简单映射 - } - } - - // 创建结果对象 - $result = clone $bug; - $result->projects = $projects; - $result->projectID = $projectID; - $result->project = $project; - $result->executionID = $executionID; - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Get config fields for testing. - * - * @access public - * @return string - */ - public function getConfigFields(): string - { - global $config; - return isset($config->bug->list->customCreateFields) ? $config->bug->list->customCreateFields : ''; - } - - /** - * Test getStoriesForCreate method. - * - * @param object $bug - * @access public - * @return int - */ - public function getStoriesForCreateTest(object $bug): int - { - // 模拟getStoriesForCreate方法的逻辑,因为它是私有方法 - // 这里模拟该方法的主要业务逻辑来进行测试 - - $productID = (int)$bug->productID; - $branch = (string)$bug->branch; - $moduleID = (int)$bug->moduleID; - $projectID = (int)$bug->projectID; - $executionID = (int)$bug->executionID; - - $stories = array(); - - // 模拟根据不同条件获取需求 - if($executionID || $projectID) - { - // 模拟从项目或执行获取需求 - $stories = array( - 1 => '需求标题1', - 2 => '需求标题2', - 3 => '需求标题3', - 4 => '需求标题4' - ); - } - else - { - if($moduleID) - { - // 模拟从指定模块获取需求 - $stories = array( - 1 => '需求标题1', - 6 => '需求标题6' - ); - } - else - { - // 模拟获取产品所有需求 - if($productID == 1) { - $stories = array( - 11 => '需求标题11', - 15 => '需求标题15' - ); - } else { - $stories = array( - 16 => '需求标题16', - 20 => '需求标题20' - ); - } - } - } - - // 返回需求的数量 - return count($stories); - } - - /** - * Test getTasksForCreate method. - * - * @param object $bug - * @access public - * @return object - */ - public function getTasksForCreateTest(object $bug): object - { - // 模拟getTasksForCreate方法的业务逻辑 - // 因为该方法是私有的,我们直接实现其逻辑进行测试 - - $executionID = (int)$bug->executionID; - - $tasks = null; - if($executionID) - { - // 从数据库获取执行的任务 - global $tester; - $taskModel = $tester->loadModel('task'); - $tasks = $taskModel->getExecutionTaskPairs($executionID); - } - - // 模拟updateBug方法的效果 - $result = clone $bug; - $result->tasks = $tasks; - - // 为了方便测试,我们返回tasks的数量或null状态 - if($tasks === null) - { - $result->tasksCount = 0; - } - else - { - $result->tasksCount = is_array($tasks) ? count($tasks) : 0; - } - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test buildEditForm method. - * - * @param object $bug - * @access public - * @return array - */ - public function buildEditFormTest(object $bug): array - { - global $tester; - - // 简化测试:检查传入的bug对象是否有效 - if(empty($bug) || !isset($bug->id)) { - return array('hasBug' => 0, 'hasProduct' => 0, 'hasExecutions' => 0); - } - - // 模拟buildEditForm方法的关键逻辑验证 - $result = array(); - $result['hasBug'] = !empty($bug->id) ? 1 : 0; - $result['hasProduct'] = !empty($bug->product) ? 1 : 0; - $result['hasProjects'] = !empty($bug->project) ? 1 : 0; - $result['hasExecutions'] = !empty($bug->execution) ? 1 : 0; - $result['hasModuleOptionMenu'] = !empty($bug->module) ? 1 : 0; - $result['hasBranchTagOption'] = !empty($bug->branch) ? 1 : 0; - $result['hasOpenedBuilds'] = !empty($bug->openedBuild) ? 1 : 0; - $result['hasAssignedToList'] = !empty($bug->assignedTo) ? 1 : 0; - $result['hasStories'] = !empty($bug->story) ? 1 : 0; - $result['hasCases'] = 1; // 总是返回1,因为用例总是会被查询 - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test assignVarsForEdit method. - * - * 由于assignVarsForEdit是protected方法且主要设置视图变量, - * 我们通过模拟其主要业务逻辑来测试。 - * - * @param object $bug - * @param object $product - * @access public - * @return mixed - */ - public function assignVarsForEditTest($bug = null, $product = null) - { - if(is_null($bug)) - { - $bug = new stdclass(); - $bug->id = 1; - $bug->product = 1; - $bug->execution = 101; - $bug->project = 11; - $bug->branch = 'main'; - $bug->assignedTo = 'admin'; - $bug->openedBuild = '1'; - $bug->story = 1; - $bug->module = 1; - } - - if(is_null($product)) - { - $product = new stdclass(); - $product->id = 1; - $product->name = 'Test Product'; - $product->shadow = 0; - $product->type = 'normal'; - } - - // 模拟assignVarsForEdit方法的主要逻辑验证 - $result = array(); - - // 验证bug对象的基本属性 - if(!empty($bug->id) && !empty($bug->product)) - { - $result['hasBugAndProduct'] = 1; - } - else - { - $result['hasBugAndProduct'] = 0; - } - - // 验证产品处理逻辑 - if(!empty($product->shadow)) - { - $result['isShadowProduct'] = 1; - } - else - { - $result['isShadowProduct'] = 0; - } - - // 验证执行相关逻辑 - if(!empty($bug->execution)) - { - $result['hasExecution'] = 1; - } - else if(!empty($bug->project)) - { - $result['hasProject'] = 1; - } - else - { - $result['hasDefault'] = 1; - } - - // 验证指派人员 - if(!empty($bug->assignedTo)) - { - $result['hasAssignedTo'] = 1; - } - else - { - $result['hasAssignedTo'] = 0; - } - - $result['executedSuccessfully'] = 1; - - return $result; - } - - /** - * Test buildBugForResolve method. - * - * @param object $oldBug - * @access public - * @return mixed - */ - public function buildBugForResolveTest($oldBug) - { - if(empty($oldBug)) return false; - - // 模拟buildBugForResolve方法的主要逻辑 - $bug = new stdclass(); - - // 设置基本字段 - $bug->id = $oldBug->id; - $bug->execution = $oldBug->execution; - $bug->status = 'resolved'; - $bug->confirmed = 1; - - // 设置默认值 - $bug->assignedTo = $oldBug->openedBy; - $bug->resolvedDate = helper::now(); - - // 处理resolution逻辑 - if(isset($_POST['resolution']) && $_POST['resolution'] != 'duplicate') - { - // 非重复bug不包含duplicateBug字段 - $bug->noDuplicateBug = true; - } - else - { - // 重复bug包含duplicateBug字段 - $bug->duplicateBug = isset($_POST['duplicateBug']) ? $_POST['duplicateBug'] : 0; - } - - // 处理resolvedBuild逻辑 - if(isset($_POST['resolvedBuild']) && $_POST['resolvedBuild'] != 'trunk') - { - // 非trunk构建时设置testtask - $bug->testtask = 1; // 模拟找到的testtask ID - } - - return $bug; - } - - /** - * Test buildBugsForBatchCreate method. - * - * @param int $productID - * @param string $branch - * @param array $bugImagesFile - * @access public - * @return mixed - */ - public function buildBugsForBatchCreateTest(int $productID, string $branch = '', array $bugImagesFile = array()) - { - // 模拟buildBugsForBatchCreate方法的核心逻辑 - global $app; - - // 模拟表单数据提取 - $bugs = array(); - if(!empty($_POST['title'])) { - foreach($_POST['title'] as $index => $title) { - if(empty($title)) continue; - - $bug = new stdclass(); - $bug->title = $title; - $bug->type = isset($_POST['type'][$index]) ? $_POST['type'][$index] : 'codeerror'; - $bug->severity = isset($_POST['severity'][$index]) ? $_POST['severity'][$index] : 3; - $bug->pri = isset($_POST['pri'][$index]) ? $_POST['pri'][$index] : 3; - $bug->module = isset($_POST['module'][$index]) ? $_POST['module'][$index] : 0; - $bug->steps = isset($_POST['steps'][$index]) ? $_POST['steps'][$index] : ''; - - // 设置创建者和时间 - $bug->openedBy = $app->user->account ?? 'admin'; - $bug->openedDate = helper::now(); - $bug->product = $productID; - $bug->steps = nl2br($bug->steps); - - // 模拟模块负责人分配 - if(!empty($bug->module)) { - $bug->assignedTo = $app->user->account ?? 'admin'; - $bug->assignedDate = helper::now(); - } - - // 处理图片上传 - $bug->uploadImage = isset($_POST['uploadImage'][$index]) ? $_POST['uploadImage'][$index] : ''; - $bug->imageFile = array(); - - $bugs[] = $bug; - } - } - - return $bugs; - } - - /** - * Test assignBatchCreateVars method. - * - * @param int $executionID - * @param object $product - * @param string $branch - * @param array $output - * @param array $bugImagesFile - * @access public - * @return mixed - */ - public function assignBatchCreateVarsTest(int $executionID = 0, ?object $product = null, string $branch = '', array $output = array(), array $bugImagesFile = array()) - { - global $tester; - - if($product === null) $product = new stdclass(); - - // 模拟assignBatchCreateVars方法的关键逻辑验证 - $result = array(); - $result['executionID'] = $executionID; - $result['hasProduct'] = !empty($product) ? 1 : 0; - $result['productType'] = isset($product->type) ? $product->type : 'normal'; - $result['hasBranch'] = !empty($branch) ? 1 : 0; - $result['hasOutput'] = !empty($output) ? 1 : 0; - $result['hasImages'] = !empty($bugImagesFile) ? 1 : 0; - - // 根据executionID判断是否需要设置执行相关变量 - if($executionID > 0) - { - $result['hasExecution'] = 1; - $result['executionBased'] = 1; - } - else - { - $result['hasExecution'] = 0; - $result['executionBased'] = 0; - } - - // 根据产品类型判断是否有分支 - if(isset($product->type) && $product->type != 'normal') - { - $result['hasBranches'] = 1; - } - else - { - $result['hasBranches'] = 0; - } - - // 如果有图片文件,验证标题提取 - if(!empty($bugImagesFile)) - { - $result['imageCount'] = count($bugImagesFile); - $result['hasTitles'] = 1; - } - else - { - $result['imageCount'] = 0; - $result['hasTitles'] = 0; - } - - return $result; - } - - /** - * Test assignVarsForBatchCreate method. - * - * @param object $product - * @param object $project - * @param array $bugImagesFile - * @access public - * @return mixed - */ - public function assignVarsForBatchCreateTest(object $product, object $project, array $bugImagesFile): mixed - { - // 模拟assignVarsForBatchCreate方法的关键逻辑验证 - $result = array(); - - // 根据配置设置自定义字段 - $customFields = array(); - $customBatchCreateFields = 'project,execution,plan,steps,type,pri,deadline,severity,os,browser,keywords'; - foreach(explode(',', $customBatchCreateFields) as $field) - { - $customFields[$field] = ucfirst($field); - } - - // 根据产品类型添加分支字段 - if($product->type != 'normal') - { - $customFields['branch'] = 'Branch'; - } - - // 根据项目模式添加执行字段 - if(isset($project->model) && $project->model == 'kanban') - { - $customFields['execution'] = 'Execution'; - } - - // 处理图片文件标题 - $titles = array(); - if(!empty($bugImagesFile)) - { - foreach($bugImagesFile as $fileName => $file) - { - if(isset($file['title'])) - { - $title = $file['title']; - $titles[$title] = $fileName; - } - } - } - - // 设置显示字段 - $showFields = 'project,execution,deadline,steps,type,pri,severity,os,browser,' . ($product->type != 'normal' ? 'branch' : ''); - $showFields = trim($showFields, ','); - - return (object) array( - 'customFields' => $customFields, - 'showFields' => $showFields, - 'titles' => $titles, - 'hasCustomFields' => !empty($customFields) ? '1' : '0', - 'hasTitles' => !empty($titles) ? '1' : '0', - 'hasBranch' => isset($customFields['branch']) ? '1' : '0', - 'hasExecution' => isset($customFields['execution']) ? '1' : '0', - 'productType' => $product->type, - 'projectModel' => isset($project->model) ? $project->model : '' - ); - } - - /** - * Test buildSearchFormForLinkBugs method. - * - * @param object $bug - * @param string $excludeBugs - * @param int $queryID - * @access public - * @return mixed - */ - public function buildSearchFormForLinkBugsTest($bug = null, $excludeBugs = '', $queryID = 0) - { - if(is_null($bug)) - { - $bug = new stdClass(); - $bug->id = 1; - $bug->project = 1; - $bug->product = 1; - $bug->title = 'Test Bug'; - } - - // 简化测试,直接模拟方法的逻辑 - $hasProduct = '1'; - $hasExecution = '1'; - $hasPlan = '1'; - - // 模拟方法内部的逻辑判断 - if($bug->project && $bug->id != 4) // 不是QA tab - { - // 模拟project.hasProduct为false的情况(如bug id为2或3) - if($bug->id == 2 || $bug->id == 3) - { - $hasProduct = '0'; - $hasExecution = '0'; - $hasPlan = '0'; - } - } - - return array( - 'hasProduct' => $hasProduct, - 'hasExecution' => $hasExecution, - 'hasPlan' => $hasPlan - ); - } - - /** - * Test buildBugsForBatchEdit method. - * - * @param array $oldBugs - * @access public - * @return mixed - */ - public function buildBugsForBatchEditTest($oldBugs = array()) - { - global $tester; - - if(empty($oldBugs)) return array(); - - // 模拟 form::batchData 返回的数据 - $bugs = array(); - foreach($oldBugs as $oldBug) - { - $bug = new stdclass(); - $bug->id = $oldBug->id; - $bug->os = isset($oldBug->os) ? $oldBug->os : 'linux'; - $bug->browser = isset($oldBug->browser) ? $oldBug->browser : 'chrome'; - $bug->assignedTo = isset($oldBug->assignedTo) ? $oldBug->assignedTo : ''; - $bug->resolution = isset($oldBug->resolution) ? $oldBug->resolution : ''; - $bug->resolvedBy = isset($oldBug->resolvedBy) ? $oldBug->resolvedBy : ''; - $bug->duplicateBug = isset($oldBug->duplicateBug) ? $oldBug->duplicateBug : 0; - $bug->project = isset($oldBug->project) ? $oldBug->project : 0; - $bugs[] = $bug; - } - - $now = helper::now(); - - // 模拟 buildBugsForBatchEdit 方法的主要逻辑 - foreach($bugs as $index => $bug) - { - $oldBug = $oldBugs[$bug->id - 1]; // 调整索引 - - // 处理数组类型的 os 和 browser - if(is_array($bug->os)) $bug->os = implode(',', $bug->os); - if(is_array($bug->browser)) $bug->browser = implode(',', $bug->browser); - - // 如果bug已关闭,指派人员不变 - if(isset($oldBug->status) && $oldBug->status == 'closed') - { - $bug->assignedTo = $oldBug->assignedTo; - } - - // 如果解决方案不是duplicate,duplicateBug设为0 - if($bug->resolution != 'duplicate') $bug->duplicateBug = 0; - - // 如果指派人员变更,设置指派日期 - if($bug->assignedTo != $oldBug->assignedTo) $bug->assignedDate = $now; - - // 如果有解决方案,设置确认状态 - if($bug->resolution != '') $bug->confirmed = 1; - - // 如果bug被解决,设置解决日期和状态 - if(($bug->resolvedBy != '' || $bug->resolution != '') && - isset($oldBug->status) && - strpos(',resolved,closed,', ",{$oldBug->status},") === false) - { - $bug->resolvedDate = $now; - $bug->status = 'resolved'; - } - - // 如果有解决方案但没有解决人,设置解决人 - if($bug->resolution != '' && $bug->resolvedBy == '') - { - $bug->resolvedBy = 'admin'; // 模拟当前用户 - } - - // 如果有解决方案但没有指派人,设置指派人和指派日期 - if($bug->resolution != '' && $bug->assignedTo == '') - { - $bug->assignedTo = isset($oldBug->openedBy) ? $oldBug->openedBy : 'admin'; - $bug->assignedDate = $now; - } - } - - return $bugs; - } - - /** - * Test assignBatchEditVars method. - * - * @param int $productID - * @param string $branch - * @access public - * @return mixed - */ - public function assignBatchEditVarsTest(int $productID = 0, string $branch = ''): mixed - { - // 模拟 assignBatchEditVars 方法的核心逻辑验证 - $result = array(); - - // 模拟 POST 数据中的 bugIdList - $bugIdList = array(1, 2, 3, 1, 2); // 包含重复项用于测试 array_unique - $uniqueBugIds = array_unique($bugIdList); - - // 获取bug数据(模拟) - $bugs = array(); - foreach($uniqueBugIds as $bugId) { - $bugs[] = (object)array( - 'id' => $bugId, - 'title' => "Bug标题{$bugId}", - 'product' => $productID > 0 ? $productID : ($bugId % 2 + 1), - 'branch' => $branch ?: '0', - 'status' => 'active' - ); - } - - // 根据产品ID获取产品ID列表 - if($productID > 0) { - $productIdList = array($productID => $productID); - } else { - // 从bugs中获取产品列表 - $productIdList = array(); - foreach($bugs as $bug) { - $productIdList[$bug->product] = $bug->product; - } - } - - // 获取自定义字段(模拟) - $customFields = array(); - $customBatchEditFields = 'type,severity,pri,assignedTo,deadline,os,browser'; - foreach(explode(',', $customBatchEditFields) as $field) { - $customFields[$field] = ucfirst($field); - } - - // 构建标题 - $title = ''; - if($productID > 0) { - $productName = "产品{$productID}"; - $title = "{$productName}-BUG批量编辑"; - } else { - $title = "BUG批量编辑"; - } - - // 模拟用户数据 - $users = array( - 'admin' => '管理员', - 'user1' => '用户1', - 'user2' => '用户2', - 'user3' => '用户3', - 'user4' => '用户4', - 'user5' => '用户5' - ); - - // 返回验证数据 - $result = array( - 'productID' => $productID, - 'branch' => $branch, - 'title' => $title, - 'customFields' => count($customFields), - 'bugs' => count($bugs), - 'users' => count($users), - 'productIdList' => count($productIdList) - ); - - return $result; - } - - /** - * Test assignProductRelatedVars method. - * - * @param mixed $bugs 参数描述 - * @param mixed $products 参数描述 - * @access public - * @return mixed - */ - public function assignProductRelatedVarsTest($bugs = null, $products = null) - { - // 处理测试参数 - if($bugs === 'normal') { - $bugs = array( - (object)array('id' => 1, 'product' => 1, 'branch' => 0, 'module' => 1), - (object)array('id' => 2, 'product' => 2, 'branch' => 0, 'module' => 2), - (object)array('id' => 3, 'product' => 3, 'branch' => 0, 'module' => 3) - ); - } elseif($bugs === 'mixed') { - $bugs = array( - (object)array('id' => 1, 'product' => 6, 'branch' => 1, 'module' => 1), - (object)array('id' => 2, 'product' => 7, 'branch' => 2, 'module' => 2), - (object)array('id' => 3, 'product' => 1, 'branch' => 0, 'module' => 3) - ); - } elseif(!is_array($bugs)) { - $bugs = array(); - } - - if($products === 'normal') { - $products = array( - (object)array('id' => 1, 'name' => '产品1', 'type' => 'normal'), - (object)array('id' => 2, 'name' => '产品2', 'type' => 'normal'), - (object)array('id' => 3, 'name' => '产品3', 'type' => 'normal') - ); - } elseif($products === 'mixed') { - $products = array( - (object)array('id' => 1, 'name' => '产品1', 'type' => 'normal'), - (object)array('id' => 6, 'name' => '产品6', 'type' => 'branch'), - (object)array('id' => 7, 'name' => '产品7', 'type' => 'branch') - ); - } elseif(!is_array($products)) { - $products = array(); - } - - // 由于assignProductRelatedVars是private方法,我们需要模拟其行为 - // 该方法主要功能是设置view变量并返回$branchTagOption数组 - $branchTagOption = array(); - - // 如果没有产品,返回空数组 - if(empty($products)) { - return count($branchTagOption); - } - - // 处理产品相关变量 - foreach($products as $product) { - if($product->type != 'normal') { - // 分支产品会有分支标签选项 - $branchTagOption[$product->id] = array(); - $branchTagOption[$product->id][1] = "/{$product->name}/branch1"; - $branchTagOption[$product->id][2] = "/{$product->name}/branch2"; - } - } - - // 返回数组大小用于验证 - return count($branchTagOption); - } - - /** - * Test assignProjectRelatedVars method. - * - * @param mixed $bugs - * @param mixed $products - * @access public - * @return mixed - */ - public function assignProjectRelatedVarsTest($bugs = null, $products = null) - { - // 由于assignProjectRelatedVars是private方法,我们需要使用反射或模拟其行为 - // 该方法主要功能是为view分配项目相关的变量 - - // 处理输入参数 - 模拟真实数据结构 - if($bugs === 'normal') { - $bugs = array( - (object)array('id' => 1, 'product' => 1, 'project' => 1, 'execution' => 101, 'branch' => 0), - (object)array('id' => 2, 'product' => 2, 'project' => 2, 'execution' => 102, 'branch' => 1), - (object)array('id' => 3, 'product' => 1, 'project' => 3, 'execution' => 0, 'branch' => 0) - ); - } elseif($bugs === 'mixed') { - $bugs = array( - (object)array('id' => 1, 'product' => 6, 'project' => 1, 'execution' => 101, 'branch' => 1), - (object)array('id' => 2, 'product' => 7, 'project' => 0, 'execution' => 0, 'branch' => 2), - (object)array('id' => 3, 'product' => 1, 'project' => 3, 'execution' => 103, 'branch' => 0) - ); - } elseif($bugs === 'empty') { - $bugs = array(); - } elseif(!is_array($bugs)) { - $bugs = array(); - } - - if($products === 'normal') { - $products = array( - 1 => (object)array('id' => 1, 'name' => '产品1', 'shadow' => 0), - 2 => (object)array('id' => 2, 'name' => '产品2', 'shadow' => 0), - 3 => (object)array('id' => 3, 'name' => '产品3', 'shadow' => 0) - ); - } elseif($products === 'shadow') { - $products = array( - 6 => (object)array('id' => 6, 'name' => '影子产品1', 'shadow' => 1), - 7 => (object)array('id' => 7, 'name' => '影子产品2', 'shadow' => 1) - ); - } elseif($products === 'mixed') { - $products = array( - 1 => (object)array('id' => 1, 'name' => '产品1', 'shadow' => 0), - 6 => (object)array('id' => 6, 'name' => '影子产品1', 'shadow' => 1) - ); - } elseif(!is_array($products)) { - $products = array(); - } - - // 模拟assignProjectRelatedVars方法的核心逻辑 - if(empty($bugs)) return 0; - - $result = array( - 'productProjects' => array(), - 'productExecutions' => array(), - 'productOpenedBuilds' => array(), - 'projectOpenedBuilds' => array(), - 'executionOpenedBuilds' => array(), - 'deletedProjects' => array(), - 'deletedExecutions' => array() - ); - - $processedProducts = array(); - $processedProjectExecutions = array(); - - foreach($bugs as $bug) { - // 为每个产品处理项目信息 - if(!isset($processedProducts[$bug->product])) { - $result['productProjects'][$bug->product] = array(); - $processedProducts[$bug->product] = true; - } - - // 为每个产品-项目组合处理执行信息 - if($bug->project > 0 && !isset($processedProjectExecutions[$bug->product][$bug->project])) { - $result['productExecutions'][$bug->product][$bug->project] = array(); - $processedProjectExecutions[$bug->product][$bug->project] = true; - } - - // 处理构建信息 - if($bug->execution > 0) { - if(!isset($result['executionOpenedBuilds'][$bug->execution])) { - $result['executionOpenedBuilds'][$bug->execution] = array(); - } - } elseif($bug->project > 0) { - if(!isset($result['projectOpenedBuilds'][$bug->project])) { - $result['projectOpenedBuilds'][$bug->project] = array(); - } - } else { - if(!isset($result['productOpenedBuilds'][$bug->product])) { - $result['productOpenedBuilds'][$bug->product] = array(); - } - } - } - - // 返回处理的产品数量用于验证 - return count($processedProducts); - } - - /** - * Test assignUsersForBatchEdit method. - * - * @param string $bugsType - * @param string $tabType - * @access public - * @return mixed - */ - public function assignUsersForBatchEditTest($bugsType = 'normal', $tabType = 'product') - { - global $app; - $oldTab = $app->tab; - $app->tab = $tabType; - - // 模拟不同类型的bugs数据 - $bugs = array(); - $productIdList = array(); - $branchTagOption = array(); - - if($bugsType == 'normal') { - $bugs = array( - (object)array('id' => 1, 'product' => 1, 'project' => 1, 'execution' => 101), - (object)array('id' => 2, 'product' => 2, 'project' => 2, 'execution' => 102) - ); - $productIdList = array(1, 2); - } elseif($bugsType == 'empty') { - $bugs = array(); - $productIdList = array(); - } elseif($bugsType == 'branch') { - $bugs = array( - (object)array('id' => 3, 'product' => 2, 'project' => 1, 'execution' => 101) - ); - $productIdList = array(2); - $branchTagOption = array(2 => array(0 => '/Product 2/main', 1 => '/Product 2/branch1', 2 => '/Product 2/branch2')); - } elseif($bugsType == 'single_project') { - $bugs = array( - (object)array('id' => 4, 'product' => 1, 'project' => 2, 'execution' => 102) - ); - $productIdList = array(1); - } elseif($bugsType == 'multi_branch') { - $bugs = array( - (object)array('id' => 5, 'product' => 2, 'project' => 1, 'execution' => 101), - (object)array('id' => 6, 'product' => 4, 'project' => 1, 'execution' => 103) - ); - $productIdList = array(2, 4); - $branchTagOption = array( - 2 => array(1 => '/Product 2/branch1', 2 => '/Product 2/branch2'), - 4 => array(4 => '/Product 4/branch4', 5 => '/Product 4/branch5') - ); - } elseif($bugsType == 'no_execution') { - $bugs = array( - (object)array('id' => 7, 'product' => 1, 'project' => 1, 'execution' => 0), - (object)array('id' => 8, 'product' => 3, 'project' => 2, 'execution' => 0) - ); - $productIdList = array(1, 3); - } - - // 模拟assignUsersForBatchEdit的核心逻辑 - $result = array(); - - // 总是返回基础用户列表 - $userModel = $this->instance->loadModel('user'); - $result['users'] = $userModel->getPairs('devfirst|noclosed|nodeleted'); - if(empty($result['users'])) $result['users'] = array('admin' => '管理员', 'user1' => '用户1'); - - // 根据tab类型决定是否获取团队成员 - if($tabType == 'execution' || $tabType == 'project') { - $result['productMembers'] = array(); - $result['projectMembers'] = array(); - $result['executionMembers'] = array(); - - // 为每个产品获取成员 - foreach($productIdList as $productId) { - $branches = isset($branchTagOption[$productId]) ? array_keys($branchTagOption[$productId]) : array(0); - foreach($branches as $branchId) { - $result['productMembers'][$productId][$branchId] = array( - 'admin' => '管理员', - 'user1' => '用户1' - ); - } - } - - // 获取项目成员 - $projectIds = array_unique(array_column($bugs, 'project')); - foreach($projectIds as $projectId) { - if($projectId > 0) { - $result['projectMembers'][$projectId] = array( - 'admin' => '管理员', - 'user1' => '用户1' - ); - } - } - - // 获取执行成员 - $executionIds = array_unique(array_column($bugs, 'execution')); - foreach($executionIds as $executionId) { - if($executionId > 0) { - $result['executionMembers'][$executionId] = array( - 'admin' => '管理员', - 'user1' => '用户1' - ); - } - } - } else { - // 非项目/执行页面,不返回团队成员信息 - $result['productMembers'] = array(); - $result['projectMembers'] = array(); - $result['executionMembers'] = array(); - } - - // 处理单项目模式的特殊逻辑 - if($bugsType == 'single_project' && ($tabType == 'project' || $tabType == 'execution')) { - // 在单项目模式下,应该隐藏产品计划字段 - $result['hiddenPlan'] = true; - } - - // 恢复原始tab - $app->tab = $oldTab; - - if(dao::isError()) return dao::getError(); - - // 返回用于验证的信息 - if($bugsType == 'empty') { - return count($result['users']); // 返回用户数量 - } elseif($tabType == 'product') { - return empty($result['productMembers']) && empty($result['projectMembers']) && empty($result['executionMembers']) ? 1 : 0; - } elseif($bugsType == 'single_project') { - return isset($result['hiddenPlan']) ? 1 : 0; - } elseif($bugsType == 'multi_branch') { - // 验证多分支产品的成员是否正确设置 - return (count($result['productMembers']) == 2 && isset($result['productMembers'][2]) && isset($result['productMembers'][4])) ? 1 : 0; - } elseif($bugsType == 'no_execution') { - // 无执行时只有项目成员 - return (!empty($result['projectMembers']) && empty($result['executionMembers'][0])) ? 1 : 0; - } else { - return (!empty($result['users']) && ($tabType == 'product' || (!empty($result['productMembers']) && - !empty($result['projectMembers']) && !empty($result['executionMembers'])))) ? 1 : 0; - } - } - - /** - * Test processImageForBatchCreate method. - * - * @param object $bug - * @param string $uploadImage - * @param array $bugImagesFiles - * @access public - * @return array - */ - public function processImageForBatchCreateTest(object $bug, string|null $uploadImage, array $bugImagesFiles): array - { - // 模拟processImageForBatchCreate方法的逻辑验证 - $result = array(); - - // 如果uploadImage为空,返回空数组 - if(empty($uploadImage)) - { - return array(); - } - - // 检查bugImagesFiles中是否存在指定的uploadImage - if(!isset($bugImagesFiles[$uploadImage])) - { - return array(); - } - - $file = $bugImagesFiles[$uploadImage]; - - // 检查文件是否存在必要的属性 - if(!isset($file['realpath']) || !isset($file['pathname']) || !isset($file['extension'])) - { - return array(); - } - - // 模拟文件移动成功的情况(在测试环境中) - $moveSuccess = true; // 在测试中假设文件移动成功 - - if($moveSuccess) - { - // 检查是否是图片文件 - $imageExtensions = array('png', 'jpg', 'jpeg', 'gif', 'bmp'); - if(in_array(strtolower($file['extension']), $imageExtensions)) - { - // 模拟图片文件处理成功 - $file['addedBy'] = 'admin'; - $file['addedDate'] = '2023-09-13 19:20:00'; - $file['id'] = 123; // 模拟文件ID - - // 模拟在bug步骤中添加图片 - if(!isset($bug->steps)) $bug->steps = ''; - $bug->steps .= '
'; - - return $file; - } - else - { - // 非图片文件,文件移动成功但不添加到步骤中 - return $file; - } - } - else - { - // 文件移动失败 - return array(); - } - - return array(); - } - - /** - * Test updateTodoAfterCreate method. - * - * @param int $bugID - * @param int $todoID - * @access public - * @return mixed - */ - public function updateTodoAfterCreateTest(int $bugID, int $todoID) - { - // 简化实现:直接测试方法调用是否能正常执行 - if($bugID > 0 && $todoID > 0) return 1; - return 1; // 所有情况都返回1,表示方法调用成功 - } - - /** - * Test updateBug method. - * - * @param object $bug - * @param array $fields - * @access public - * @return object - */ - public function updateBugTest(object $bug, array $fields) - { - // updateBug方法是一个简单的工具方法,直接实现其逻辑进行测试 - foreach($fields as $field => $value) $bug->$field = $value; - return $bug; - } - - /** - * Test afterCreate method. - * - * @param object $bug - * @param array $params - * @param string $from - * @access public - * @return bool - */ - public function afterCreateTest(object $bug, array $params = array(), string $from = ''): bool - { - // 模拟afterCreate方法的逻辑,避免复杂的依赖问题 - - // 1. 将 bug 的模块保存到 cookie - if(isset($bug->module)) { - // 模拟cookie设置(在测试中只是简单检查) - $cookieSet = true; - } - - // 2. 处理文件列表(如果存在) - if(!empty($_POST['fileList'])) { - $fileList = $_POST['fileList']; - if($fileList) { - $fileList = json_decode($fileList, true); - // 模拟文件处理 - $filesProcessed = true; - } - } - - // 3. 获取看板变量 - $laneID = isset($params['laneID']) ? $params['laneID'] : 0; - if(!empty($_POST['lane'])) $laneID = $_POST['lane']; - - // 简单的列ID逻辑 - $columnID = isset($params['columnID']) ? $params['columnID'] : 0; - - // 4. 模拟更新看板逻辑 - if($bug->execution ?? 0) { - $kanbanUpdated = true; - } - - // 5. 处理todo更新 - $todoID = isset($params['todoID']) ? $params['todoID'] : 0; - if($todoID) { - // 模拟todo状态更新 - $todoUpdated = true; - } - - // 模拟dao检查 - if(dao::isError()) return dao::getError(); - - return true; - } - - /** - * Test responseAfterOperate method. - * - * @param int $bugID - * @param array $changes - * @param string $message - * @param bool $isInKanban - * @access public - * @return array - */ - public function responseAfterOperateTest(int $bugID, array $changes = array(), string $message = '', bool $isInKanban = false): array - { - // 模拟responseAfterOperate方法的核心逻辑 - if(!$message) $message = '保存成功'; - - // 模拟正常情况下的响应 - $response = array( - 'result' => 'success', - 'message' => $message - ); - - // 如果有bugID,添加到响应中 - if($bugID) $response['bugID'] = $bugID; - - // 如果在看板模式 - if($isInKanban) $response['kanban'] = true; - - // 如果有变更信息 - if(!empty($changes)) $response['changes'] = $changes; - - return $response; - } - - /** - * Test responseInModal method. - * - * @param string $message - * @param bool $isInKanban - * @param string $tab - * @access public - * @return array - */ - public function responseInModalTest(string $message = '', bool $isInKanban = false, string $tab = 'qa'): array - { - global $app, $lang; - - // 设置应用tab - $originalTab = $app->tab ?? ''; - $app->tab = $tab; - - // 模拟语言设置 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 模拟responseInModal方法的逻辑,避免调用send方法 - if($app->tab == 'execution' && $isInKanban) { - $result = array('result' => 'success', 'closeModal' => true, 'callback' => "refreshKanban()"); - } else { - $result = array('result' => 'success', 'message' => $message, 'closeModal' => true, 'load' => true); - } - - // 恢复原始tab - $app->tab = $originalTab; - - return $result; - } - - /** - * Test responseAfterCreate method. - * - * @param object $bug - * @param array $params - * @param string $message - * @access public - * @return array - */ - public function responseAfterCreateTest(object $bug, array $params = array(), string $message = ''): array - { - global $app, $lang; - - // 模拟executionID获取逻辑 - $executionID = $bug->execution ? $bug->execution : (int)(zget($params, 'executionID', 0)); - - // 设置默认消息 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 模拟JSON视图响应 - if(isset($params['viewType']) && $params['viewType'] == 'json') { - return array('result' => 'success', 'message' => $message, 'id' => $bug->id); - } - - // 模拟API模式响应 - if(isset($params['runMode']) && $params['runMode'] == 'api') { - return array('status' => 'success', 'data' => $bug->id); - } - - // 模拟模态框响应 - if(isset($params['isInModal']) && $params['isInModal']) { - return array('result' => 'success', 'message' => $message, 'closeModal' => true); - } - - // 根据不同tab构建跳转链接 - $location = ''; - $tab = $params['tab'] ?? 'product'; - - if($tab == 'execution') { - $location = "execution-bug-executionID-{$executionID}"; - } elseif($tab == 'project') { - $projectID = zget($params, 'projectID', 0); - $location = "project-bug-projectID-{$projectID}"; - } else { - $location = "bug-browse-productID-{$bug->product}-branch-{$bug->branch}"; - } - - // 模拟xhtml视图 - if(isset($params['viewType']) && $params['viewType'] == 'xhtml') { - $location = "bug-view-bugID-{$bug->id}"; - } - - return array('result' => 'success', 'message' => $message, 'load' => $location); - } - - /** - * Test responseAfterDelete method. - * - * @param object $bug - * @param string $from - * @param string $message - * @param array $params - * @access public - * @return array - */ - public function responseAfterDeleteTest(object $bug, string $from, string $message = '', array $params = array()): array - { - global $app, $lang, $session; - - // 设置默认消息 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 模拟JSON视图响应 - if(isset($params['viewType']) && $params['viewType'] == 'json') { - return array('result' => 'success', 'message' => $message); - } - - // 模拟bug转任务的确认逻辑 - if(isset($bug->toTask) && $bug->toTask) { - // 模拟任务数据 - $task = new stdClass(); - $task->deleted = isset($params['taskDeleted']) ? $params['taskDeleted'] : false; - - if(!$task->deleted) { - $confirmedURL = "task-view-taskID-{$bug->toTask}"; - $canceledURL = "bug-view-bugID-{$bug->id}"; - $message = sprintf("Bug #%s 已转为任务 #%s,是否同时更新任务状态?", $bug->id, $bug->toTask); - - return array( - 'result' => 'success', - 'load' => array( - 'confirm' => $message, - 'confirmed' => $confirmedURL, - 'canceled' => $canceledURL - ) - ); - } - } - - // 模拟弹窗模式响应 - if(isset($params['isInModal']) && $params['isInModal']) { - return array('result' => 'success', 'load' => true); - } - - // 模拟任务看板删除响应 - if($from == 'taskkanban') { - return array('result' => 'success', 'closeModal' => true, 'callback' => "refreshKanban()"); - } - - // 默认响应 - 模拟session->bugList - $defaultLocation = "bug-browse-productID-{$bug->product}"; - $bugListLocation = isset($params['bugListLocation']) ? $params['bugListLocation'] : $defaultLocation; - - return array( - 'result' => 'success', - 'message' => $message, - 'load' => $bugListLocation, - 'closeModal' => true - ); - } - - /** - * Test responseAfterBatchCreate method. - * - * @param int $productID - * @param string $branch - * @param int $executionID - * @param array $bugIdList - * @param string $message - * @param string $viewType - * @access public - * @return mixed - */ - public function responseAfterBatchCreateTest(int $productID = 1, string $branch = '', int $executionID = 0, array $bugIdList = array(), string $message = '', string $viewType = 'html') - { - // 模拟zen对象 - $zen = new stdClass(); - $zen->viewType = $viewType; - $zen->lang = new stdClass(); - $zen->lang->saveSuccess = '保存成功'; - $zen->app = new stdClass(); - - // 清空会话变量,模拟方法行为 - unset($_SESSION['bugImagesFile']); - $_POST = array(); - - // 模拟默认消息 - if(!$message) $message = $zen->lang->saveSuccess; - - // 根据视图类型返回不同结果 - if($viewType == 'json') { - return array('result' => 'success', 'message' => $message, 'idList' => $bugIdList); - } - - // 模拟模态框响应 - if($viewType == 'modal') { - if($executionID) { - // 模拟responseInModal响应 - return array('result' => 'success', 'load' => true); - } - return array('result' => 'success', 'message' => $message, 'closeModal' => true); - } - - // 普通视图响应 - 跳转到bug浏览页面 - $load = "bug-browse-productID-{$productID}&branch={$branch}&browseType=unclosed¶m=0&orderBy=id_desc"; - return array('result' => 'success', 'message' => $message, 'load' => $load); - } - - /** - * Test operateAfterBatchEdit method. - * - * @param object $bug - * @param object $oldBug - * @access public - * @return string - */ - public function operateAfterBatchEditTest(object $bug, object $oldBug): string - { - global $tester, $app, $config; - - // 模拟 operateAfterBatchEdit 的逻辑,避免复杂的依赖和实际操作 - - $operations = array(); - - // 1. 检查是否需要记录积分奖励 - if(isset($bug->status) && $bug->status == 'resolved' && $oldBug->status == 'active') { - $operations[] = 'score_recorded'; - } - - // 2. 检查是否需要更新反馈状态(仅非开源版本) - if($config->edition != 'open' && isset($oldBug->feedback) && $oldBug->feedback) { - $operations[] = 'feedback_updated'; - } - - // 如果没有任何操作,返回'0' - if(empty($operations)) return '0'; - - return implode(',', $operations); - } - - /** - * Test getToBeProcessedData method. - * - * @param object $bug - * @param object $oldBug - * @access public - * @return array - */ - public function getToBeProcessedDataTest(object $bug, object $oldBug): array - { - try { - $zen = initReference('bug'); - $method = $zen->getMethod('getToBeProcessedData'); - $method->setAccessible(true); - - $zenInstance = $zen->newInstance(); - $result = $method->invokeArgs($zenInstance, array($bug, $oldBug)); - - if(dao::isError()) return dao::getError(); - - // 转换结果为可测试的格式 - $toTaskCount = count($result[0]); - $unlinkPlanCount = count($result[1]); - $link2PlanCount = count($result[2]); - - return array($toTaskCount, $unlinkPlanCount, $link2PlanCount, $result[0], $result[1], $result[2]); - } catch (Exception $e) { - return array('error' => $e->getMessage()); - } - } - - /** - * Test responseAfterBatchEdit method. - * - * @param array $toTaskIdList - * @param string $message - * @param string $testCase - * @access public - * @return string - */ - public function responseAfterBatchEditTest(array $toTaskIdList, string $message = '', string $testCase = ''): string - { - // 模拟responseAfterBatchEdit方法的逻辑 - global $lang, $session; - - // 设置默认消息 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 根据测试用例返回不同的结果用于断言 - if($testCase == 'result') { - return 'success'; - } - - if($testCase == 'message') { - return $message; - } - - if($testCase == 'confirm') { - if(!empty($toTaskIdList)) { - $taskID = key($toTaskIdList); - return "提醒:有Bug转为了任务 #{$taskID},请确认是否需要查看?"; - } - return ''; - } - - if($testCase == 'load') { - if(empty($toTaskIdList)) { - return $session->bugList ?? 'bug-browse'; - } - return 'confirm_dialog'; - } - - // 默认情况:返回success表示方法调用成功 - return 'success'; - } - - /** - * Test initBug method. - * - * @param array $fields - * @access public - * @return object - */ - public function initBugTest(array $fields = array()) - { - // initBug是一个内部工具方法,直接实现其逻辑进行测试 - $bug = new stdclass(); - $bug->projectID = 0; - $bug->moduleID = 0; - $bug->executionID = 0; - $bug->productID = 0; - $bug->taskID = 0; - $bug->storyID = 0; - $bug->buildID = 0; - $bug->caseID = 0; - $bug->runID = 0; - $bug->testtask = 0; - $bug->version = 0; - $bug->title = ''; - $bug->steps = ''; // 简化测试,不使用lang - $bug->os = ''; - $bug->browser = ''; - $bug->assignedTo = ''; - $bug->deadline = ''; - $bug->mailto = ''; - $bug->keywords = ''; - $bug->severity = 3; - $bug->type = 'codeerror'; - $bug->pri = 3; - $bug->color = ''; - $bug->feedbackBy = ''; - $bug->notifyEmail = ''; - - $bug->project = ''; - $bug->branch = ''; - $bug->execution = ''; - $bug->projectModel = ''; - $bug->projects = array(); - $bug->executions = array(); - $bug->products = array(); - $bug->stories = array(); - $bug->builds = array(); - $bug->branches = array(); - - if(!empty($fields)) - { - foreach($fields as $field => $value) $bug->$field = $value; - } - - return $bug; - } - - /** - * Test extractObjectFromExtras method. - * - * @param object $bug - * @param array $output - * @access public - * @return object - */ - public function extractObjectFromExtrasTest($bug, $output) - { - if(dao::isError()) return dao::getError(); - - // 模拟extractObjectFromExtras方法的核心逻辑,避免复杂的框架依赖 - extract($output); - - // 从resultID和caseID获取信息的模拟 - if(isset($runID) && $runID && isset($resultID) && $resultID) { - // 模拟从result获取信息的逻辑 - $bug->title = 'Test Bug From Result'; - $bug->steps = 'Steps from result'; - } - - // 从现有bugID复制信息的模拟 - if(isset($bugID) && $bugID) { - // 模拟从现有bug获取信息的逻辑 - $bug->title = 'Bug ' . $bugID; - $bug->steps = 'Steps from bug ' . $bugID; - $bug->severity = 3; - $bug->pri = 3; - $bug->assignedTo = 'admin'; - } - - // 从testtask获取buildID的模拟 - if(isset($testtask) && $testtask) { - // 模拟从testtask获取buildID的逻辑 - $bug->buildID = 'trunk'; - } - - // 从todoID获取信息的模拟 - if(isset($todoID) && $todoID) { - // 模拟从todo获取信息的逻辑 - $bug->title = 'Todo Task ' . $todoID; - $bug->steps = 'Todo description ' . $todoID; - $bug->pri = 2; - } - - return $bug; - } - - /** - * Test mergeChartOption method. - * - * @param string $chartCode - * @param string $chartType - * @access public - * @return object - */ - public function mergeChartOptionTest($chartCode, $chartType = 'default') - { - // 模拟mergeChartOption方法的核心逻辑 - $result = new stdclass(); - - // 模拟默认配置 - $commonOptions = new stdclass(); - $commonOptions->type = 'pie'; - $commonOptions->width = 500; - $commonOptions->height = 140; - $commonOptions->graph = new stdclass(); - - // 模拟图表配置 - $chartOption = new stdclass(); - $chartOption->graph = new stdclass(); - - // 设置图表标题 - $chartTitles = array( - 'bugsPerExecution' => '执行Bug数量', - 'bugsPerBuild' => '版本Bug数量', - 'bugsPerModule' => '模块Bug数量', - 'openedBugsPerDay' => '每天新增Bug数', - 'bugsPerSeverity' => '按Bug严重程度统计' - ); - - $chartOption->graph->caption = isset($chartTitles[$chartCode]) ? $chartTitles[$chartCode] : 'Unknown Chart'; - - // 设置类型 - if(!empty($chartType) && $chartType != 'default') { - $chartOption->type = $chartType; - } else { - // 某些图表有自己的默认类型 - if($chartCode == 'openedBugsPerDay') { - $chartOption->type = 'bar'; - } else { - $chartOption->type = $commonOptions->type; - } - } - - // 设置宽度和高度 - if(!isset($chartOption->width)) $chartOption->width = $commonOptions->width; - if(!isset($chartOption->height)) $chartOption->height = $commonOptions->height; - - // 合并图表选项 - foreach($commonOptions->graph as $key => $value) { - if(!isset($chartOption->graph->$key)) { - $chartOption->graph->$key = $value; - } - } - - if(dao::isError()) return dao::getError(); - - return $chartOption; - } - - /** - * Test processRepoIssueActions method. - * - * @param int $repoID - * @access public - * @return mixed - */ - public function processRepoIssueActionsTest($repoID = null) - { - try { - // 使用反射调用受保护的方法 - $zenClass = initReference('bug'); - $method = $zenClass->getMethod('processRepoIssueActions'); - $zenInstance = $zenClass->newInstance(); - - $result = $method->invokeArgs($zenInstance, array($repoID)); - - if(dao::isError()) return dao::getError(); - - // 返回相关配置以供断言 - return array( - 'repoID' => $zenInstance->view->repoID ?? null, - 'mainActions' => $zenInstance->config->bug->actions->view['mainActions'] ?? null, - 'suffixActions' => $zenInstance->config->bug->actions->view['suffixActions'] ?? null - ); - } catch (Exception $e) { - return array('error' => $e->getMessage()); - } - } - } diff --git a/module/bug/test/lib/tao.class.php b/module/bug/test/lib/tao.class.php index 23a44c3a18..26db711326 100644 --- a/module/bug/test/lib/tao.class.php +++ b/module/bug/test/lib/tao.class.php @@ -1,4 +1,4 @@ -title = 'add bug'; - $bug->type = 'codeerror'; - $bug->product = 1; - $bug->execution = 101; - $bug->openedBuild = 'trunk'; - $bug->pri = 3; - $bug->severity = 3; - $bug->status = 'active'; - $bug->deadline = '2023-03-20'; - $bug->openedBy = 'admin'; - $bug->openedDate = '2023-04-20'; - $bug->notifyEmail = ''; - $bug->steps = ''; - - foreach($param as $key => $value) $bug->$key = $value; - - $objectID = $this->objectModel->create($bug); - if(dao::isError()) - { - return dao::getError(); - } - else - { - $object = $this->objectModel->getByID($objectID); - return $object; - } - } - - /** - * 测试gitlab问题转bug。 - * Test create bug from gitlab issue. - * - * @param object $bug - * @param int $executionID - * @access public - * @return object|int|array - */ - public function createBugFromGitlabIssueTest(object $bug, int $executionID): object|int|array - { - $objectID = $this->objectModel->createBugFromGitlabIssue($bug, $executionID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - $object = $objectID ? $this->objectModel->getById($objectID) : 0; - return $object; - } - } - /** * 测试添加bug->delay字段,内容为延期的时长(天),不延期则为0 * Test if the bug is delayed, add the bug->delay field to show the delay time (day). @@ -87,17 +25,11 @@ class bugTaoTest extends baseTest $bug->deadline = $deadline ? date('Y-m-d', strtotime("{$deadline} day")) : '0000-00-00'; $bug->resolvedDate = $resolvedDate ? date('Y-m-d', strtotime("{$resolvedDate} day")) : '0000-00-00'; - $object = $this->objectModel->appendDelayedDays($bug); - if(!isset($object->delay)) $object->delay = 0; + $object = $this->instance->appendDelayedDays($bug); + if(dao::isError()) return dao::getError(); - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $object; - } + if(!isset($object->delay)) $object->delay = 0; + return $object; } /** @@ -110,11 +42,10 @@ class bugTaoTest extends baseTest */ public function batchAppendDelayedDaysTest($productID): array|string { - global $tester; - - $tester->app->tab = 'qa'; - $bugs = $this->objectModel->getListByBrowseType('all', array($productID), 0, array(), 'all', array(), 0, 'id_asc', null); - $bugs = $this->objectModel->batchAppendDelayedDays($bugs); + $this->instance->app->tab = 'qa'; + $bugs = $this->instance->getListByBrowseType('all', array($productID), 0, array(), 'all', array(), 0, 'id_asc', null); + $bugs = $this->instance->batchAppendDelayedDays($bugs); + if(dao::isError()) return dao::getError(); $delay = ''; foreach($bugs as $bug) @@ -123,3618 +54,6 @@ class bugTaoTest extends baseTest } $delay = trim($delay, ','); - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $delay; - } + return $delay; } - - /** - * Test get by Sonarqube id. - * - * @param int $sonarqubeID - * @access public - * @return int - */ - public function getBySonarqubeIDTest($sonarqubeID) - { - $array = $this->objectModel->getBySonarqubeID($sonarqubeID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return count($array); - } - } - - /** - * Test get bug list of a plan. - * - * @param int $planID - * @param string $status - * @access public - * @return string|array - */ - public function getPlanBugsTest(int $planID, string $status): string|array - { - $bugs = $this->objectModel->getPlanBugs($planID, $status, 'id_desc', null); - - $title = ''; - foreach($bugs as $bug) - { - $title .= ',' . $bug->title; - } - $title = trim($title, ','); - $title = str_replace(array("'", '@', '$', '%', ';'), '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * Test get bug by id. - * - * @param int $bugID - * @access public - * @return object - */ - public function getByIdTest($bugID) - { - $object = $this->objectModel->getById($bugID); - if(isset($object->title)) $object->title = str_replace("'", '', $object->title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $object; - } - } - - /** - * Test get bug by id list. - * - * @param string $bugIDList - * @param string $fields - * @param string $orderBy - * @access public - * @return array|string - */ - public function getByIdListTest(string $bugIDList, string $fields, string $orderBy = ''): array|string - { - $bugs = $this->objectModel->getByIdList($bugIDList, $fields, $orderBy); - - foreach($bugs as $bug) - { - if(isset($bug->title)) $bug->title = str_replace("'", '', $bug->title); - } - - if(dao::isError()) - { - return dao::getError(); - } - else - { - if($orderBy) return implode(',', array_keys($bugs)); - return $bugs; - } - } - - /** - * Test get active bugs. - * - * @param string $products - * @param string $excludeBugs - * @access public - * @return string - */ - public function getActiveBugsTest($products, $excludeBugs) - { - $bugs = $this->objectModel->getActiveBugs($products, 'all', '', $excludeBugs); - - $title = ''; - foreach($bugs as $bug) - { - $title .= ',' . $bug->title; - } - $title = trim($title, ','); - $title = str_replace("'", '', $title); - $title = str_replace("@", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * 获取激活和延期处理的 bug 列表。 - * Test get active and postponed bugs. - * - * @param array $products - * @param int $executionID - * @access public - * @return array - */ - public function getActiveAndPostponedBugsTest(array $products, int $executionID): array - { - $bugs = $this->objectModel->getActiveAndPostponedBugs($products, $executionID); - - if(dao::isError()) return dao::getError(); - - return $bugs; - } - - /** - * 获取模块的负责人的测试用例。 - * Test get module owner. - * - * @param int $moduleID - * @param int $productID - * @access public - * @return array - */ - public function getModuleOwnerTest(int $moduleID, int $productID): array - { - $owner = $this->objectModel->getModuleOwner($moduleID, $productID); - - if(dao::isError()) return dao::getError(); - - return $owner; - } - - /** - * Test update a bug. - * - * @param int $bugID - * @param array $param - * @access public - * @return void - */ - public function updateObject($bugID, $param = array()) - { - global $tester; - $object = $tester->app->dbQuery("SELECT * FROM " . TABLE_BUG ." WHERE id = $bugID")->fetch(); - - $bug = new stdclass(); - foreach($object as $field => $value) - { - if(in_array($field, array_keys($param))) - { - $bug->$field = $param[$field]; - } - elseif(strpos($field, 'Date') === false) - { - $bug->$field = $value; - } - } - $bug->deleteFiles = array(); - $bug->comment = ''; - - $change = $this->objectModel->update($bug, 'Edit'); - if($change == array()) $change = '没有数据更新'; - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $change; - } - } - - /** - * 测试指派一个bug。 - * Test assign a bug to a user again. - * - * @param object $bug - * @access public - * @return array|object - */ - public function assignTest(object $bug): array|object - { - $oldBug = $this->objectModel->getByID($bug->id); - $_SERVER['HTTP_HOST'] = ''; - $this->objectModel->assign($bug, $oldBug); - if(dao::isError()) - { - return dao::getError(); - } - else - { - global $tester; - $bug = $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); - return $bug; - } - } - - /** - * Test confirm a bug. - * - * @param array $bug - * @access public - * @return array - */ - public function confirmTest(array $bug): array - { - $oldBug = $this->objectModel->getByID($bug['id']); - - $bug['confirmed'] = 1; - $bug['comment'] = ''; - - $this->objectModel->confirm((object)$bug, array()); - - if(dao::isError()) return dao::getError(); - - $newBug = $this->objectModel->getByID($bug['id']); - - return common::createChanges($oldBug, $newBug); - } - - /** - * Test confirm a bug. - * - * @param object $bug - * @param array $param - * @param array $output - * @access public - * @return object|string - */ - public function resolveTest(int $bugID, array $param = array(), array $output = array()): object|string - { - $_SERVER['HTTP_HOST'] = ''; - - $bug = new stdclass(); - $bug->id = $bugID; - $bug->status = 'resolved'; - $bug->execution = 11; - $bug->resolution = ''; - $bug->resolvedBy = 'admin'; - $bug->resolvedBuild = 0; - $bug->resolvedDate = helper::now(); - $bug->assignedTo = 'user99'; - $bug->assignedDate = helper::now(); - $bug->lastEditedBy = 'user99'; - $bug->lastEditedDate = helper::now(); - $bug->duplicateBug = 0; - $bug->buildName = ''; - $bug->createBuild = 0; - $bug->buildExecution = 0; - $bug->uid = ''; - $bug->comment = ''; - - foreach($param as $key => $value) $bug->{$key} = $value; - - $this->objectModel->resolve($bug, $output); - - if(dao::isError()) - { - $return = ''; - $errors = dao::getError(); - foreach($errors as $key => $value) - { - if(is_string($value)) $return .= "{$value}"; - if(is_array($value)) $return .= implode('', $value); - } - return $return; - } - else - { - global $tester; - $bug = $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch(); - return $bug; - } - } - - /** - * Test activate a bug. - * - * @param int $bugID - * @param int $buildID - * @param array $kanbanParams - * @param string $returnType bug|build|action|kanban - * @access public - * @return string|array|object - */ - public function activateTest(int $bugID, int $buildID = 0, array $kanbanParams = array(), string $returnType = 'bug'): string|array|object - { - $bug = new stdclass(); - $bug->id = $bugID; - $bug->status = 'active'; - $bug->comment = "Activate bug{$bugID}"; - $bug->activatedCount = 1; - - $result = $this->objectModel->activate($bug, $kanbanParams); - - if(dao::isError()) return str_replace('\n', '', dao::getError(true)); - - global $tester; - if($returnType == 'build') return $tester->loadModel('build')->getByID($buildID); - - if($returnType == 'action') - { - $actionID = $tester->dao->select('id')->from(TABLE_ACTION) - ->where('objectType')->eq('bug') - ->andWhere('objectID')->eq($bugID) - ->andWhere('action')->eq('activated') - ->orderBy('id_desc') - ->limit(1) - ->fetch('id'); - return $tester->dao->select('*')->from(TABLE_HISTORY)->where('action')->eq($actionID)->fetchAll(); - } - - if($returnType == 'kanban') - { - $bug = $this->objectModel->fetchByID($bugID); - return $tester->dao->select('t3.type')->from(TABLE_KANBANLANE)->alias('t1') - ->leftJoin(TABLE_KANBANCELL)->alias('t2')->on('t1.id=t2.lane AND t1.execution=t2.kanban') - ->leftJoin(TABLE_KANBANCOLUMN)->alias('t3')->on('t2.column=t3.id') - ->where('t1.type')->eq('bug') - ->andWhere('t1.execution')->eq($bug->execution) - ->andWhere("FIND_IN_SET($bugID, t2.cards)") - ->fetch('type'); - } - - return $this->objectModel->fetchByID($bugID); - } - - /** - * Test close a bug. - * - * @param int $bugID - * @access public - * @return array - */ - public function closeObject(int $bugID, array $output = array()) - { - $now = helper::now(); - - $bug = new stdclass(); - $bug->id = $bugID; - $bug->status = 'closed'; - $bug->confirmed = 1; - $bug->assignedDate = $now; - $bug->lastEditedBy = 'admin'; - $bug->lastEditedDate = $now; - $bug->closedBy = 'admin'; - $bug->closedDate = $now; - $bug->comment = ''; - - $this->objectModel->close($bug, $output); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - $bug = $this->objectModel->fetchBugInfo($bugID); - return $bug; - } - } - - /** - * 测试获取 bugs 的影响版本和解决版本。 - * Test process the openedBuild and resolvedBuild fields for bugs. - * - * @param array $bugIDList - * @access public - * @return array - */ - public function processBuildForBugsTest(array $bugIDList): array - { - $bugs = $this->objectModel->getByIdList($bugIDList); - $array = $this->objectModel->processBuildForBugs($bugs); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $array; - } - } - - /** - * 测试获取用户的 bugs。 - * Test get user bugs. - * - * @param string $account - * @param string $type - * @param int $limit - * @param int $executionID - * @param int $queryID - * @param string $rawMethod - * @param string|bool $query - * @access public - * @return array - */ - public function getUserBugsTest(string $account, string $type = 'assignedTo', int $limit = 0, int $executionID = 0, int $queryID = 0, string $rawMethod = 'work', string|bool $query = false): array|int - { - global $tester; - if($type == 'bySearch') - { - $moduleName = $rawMethod == 'work' ? 'workBug' : 'contributeBug'; - $queryName = $moduleName . 'Query'; - $formName = $moduleName . 'Form'; - if($query) $tester->session->set($queryName, $query); - } - - $array = $this->objectModel->getUserBugs($account, $type, 'id_desc', $limit, null, $executionID, $queryID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return count($array); - } - } - - /** - * 测试获取取用户的bugs的 id => title 数组。 - * Test get bug pairs of a user. - * - * @param string $account - * @param bool $appendProduct - * @param int $limit - * @param array $skipProductIdList - * @param array $skipExecutionIdList - * @param int|array $appendBugID - * @access public - * @return array - */ - public function getUserBugPairsTest(string $account, bool $appendProduct = true, int $limit = 0, array $skipProductIdList = array(), array $skipExecutionIdList = array(), array|int $appendBugID = 0): array|int - { - $array = $this->objectModel->getUserBugPairs($account, $appendProduct, $limit, $skipProductIdList, $skipExecutionIdList, $appendBugID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return count($array); - } - } - - /** - * 测试获取项目的 bug。 - * Test get bugs of a project. - * - * @param int $projectID - * @access public - * @return array - */ - public function getProjectBugsTest(int $projectID, int $productID = 0, int|string $branchID = 0, int $build = 0, string $type = '', int $param = 0, string $excludeBugs = ''): array - { - $bugs = $this->objectModel->getProjectBugs($projectID, $productID, $branchID, $build, $type, $param, $orderBy = 'id_desc', $excludeBugs); - - foreach($bugs as $bug) $bug->title = str_replace("'", '', $bug->title); - - if(dao::isError()) return dao::getError(); - - return $bugs; - } - - /** - * 测试获取执行的 bug。 - * Test get bugs of a execution. - * - * @param int $executionID - * @param int $productID - * @param string|int $branchID - * @param string|array $builds - * @param string $type - * @param int $param - * @param string $excludeBugs - * @access public - * @return string - */ - public function getExecutionBugsTest(int $executionID, int $productID = 0, string|int $branchID = 'all', string|array $builds = '0', string $type = '', int $param = 0, string $excludeBugs = ''): array - { - $bugs = $this->objectModel->getExecutionBugs($executionID, $productID, $branchID, $builds, $type, $param, 'id_desc', $excludeBugs); - - if(dao::isError()) return dao::getError(); - - return array_values($bugs); - } - - /** - * 测试获取产品未关联版本的bug。 - * Test get product left bugs. - * - * @param array $buildIdList - * @param int $productID - * @param int|string $branch - * @param string $linkedBugs - * @access public - * @return array|string - */ - public function getProductLeftBugsTest(array $buildIdList, int $productID, int|string $branch = '', string $linkedBugs = ''): array|string - { - $array = $this->objectModel->getProductLeftBugs($buildIdList, $productID, $branch, $linkedBugs); - - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); - $title = str_replace(array("'", '@', '$', '%'), '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * 测试获取产品的bug键对。 - * Test get bug pairs of a product. - * - * @param int $productID - * @param int|string $branch - * @access public - * @return string - */ - public function getProductBugPairsTest(int $productID, int|string $branch = ''): array|string - { - $array = $this->objectModel->getProductBugPairs($productID, $branch); - - $title = ''; - foreach($array as $bug) $title .= ',' . $bug; - $title = trim($title, ','); - $title = str_replace(array("'", '@', '$', '%'), '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * Test get bug member of a product. - * - * @param int $productID - * @access public - * @return string|array - */ - public function getProductMemberPairsTest(int $productID): string|array - { - $array = $this->objectModel->getProductMemberPairs($productID); - - $title = ''; - foreach($array as $bug) $title .= ',' . $bug; - $title = trim($title, ','); - $title = str_replace("'", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * 测试通过版本 id 和产品 id 获取 bugs。 - * Test get bugs according to buildID and productID. - * - * @param int $buildID - * @param int $productID - * @access public - * @return string|array - */ - public function getReleaseBugsTest(int $buildID, int $productID): string|array - { - $array = $this->objectModel->getReleaseBugs(array($buildID), $productID); - - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); - $title = str_replace("'", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * 测试获取需求产生的bug。 - * Test get bugs of a story. - * - * @param int $storyID - * @access public - * @return string - */ - public function getStoryBugsTest(int $storyID): array|string - { - $array = $this->objectModel->getStoryBugs($storyID); - - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); - $title = str_replace("'", '', $title); - $title = str_replace("@", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * 测试获取用例关联的bugs。 - * Test get case bugs. - * - * @param int $runID - * @param int $caseID - * @param int $version - * @access public - * @return string - */ - public function getCaseBugsTest(int $runID, int $caseID = 0, int $version = 0): string|array - { - $array = $this->objectModel->getCaseBugs($runID, $caseID, $version); - - $title = ''; - foreach($array as $bug) $title .= ',' . $bug->title; - $title = trim($title, ','); - $title = str_replace("'", '', $title); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $title; - } - } - - /** - * 测试获取需求关联的 bug 数量。 - * Test get counts of some stories' bugs. - * - * @param array $storyIDList - * @param int $executionID - * @access public - * @return array - */ - public function getStoryBugCountsTest(array $storyIDList, int $executionID = 0): array - { - $array = $this->objectModel->getStoryBugCounts($storyIDList, $executionID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $array; - } - } - - /** - * 测试从测试结果中获取 bug 信息。 - * Test get bug info from a result. - * - * @param int $runID - * @param int $caseID - * @access public - * @return string|int|array - */ - public function getBugInfoFromResultTest(int $resultID, int $caseID = 0): string|int|array - { - $array = $this->objectModel->getBugInfoFromResult($resultID, $caseID); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return isset($array['title']) ? $array['title'] : 0; - } - } - - /** - * 获取执行 bug 数量报表的测试用例。 - * Test get report data of bugs per execution. - * - * @access public - * @return array - */ - public function getDataOfBugsPerExecutionTest(): array - { - global $tester; - $tester->loadModel('report'); - $tester->session->set('project', 0); - - $datas = $this->objectModel->getDataOfBugsPerExecution(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 获取版本 bug 数量报表的测试用例。 - * Test get report data of bugs per build. - * - * @access public - * @return array - */ - public function getDataOfBugsPerBuildTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerBuild(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 获取模块 bug 数量报表的测试用例。 - * Test get report data of bugs per module. - * - * @access public - * @return array - */ - public function getDataOfBugsPerModuleTest() - { - $datas = $this->objectModel->getDataOfBugsPerModule(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每天新增 bug 数。 - * Test get report data of opened bugs per day. - * - * @access public - * @return array - */ - public function getDataOfOpenedBugsPerDayTest(): array - { - $datas = $this->objectModel->getDataOfOpenedBugsPerDay(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每天解决 bug 数。 - * Test get report data of resolved bugs per day. - * - * @access public - * @return array - */ - public function getDataOfResolvedBugsPerDayTest(): array - { - $datas = $this->objectModel->getDataOfResolvedBugsPerDay(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每天关闭的 bug 数。 - * Test get report data of closed bugs per day. - * - * @access public - * @return array - */ - public function getDataOfClosedBugsPerDayTest(): array - { - $datas = $this->objectModel->getDataOfClosedBugsPerDay(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每人提交的 bug 数。 - * Test get report data of openeded bugs per user. - * - * @access public - * @return array - */ - public function getDataOfOpenedBugsPerUserTest(): array - { - $datas = $this->objectModel->getDataOfOpenedBugsPerUser(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每人解决的 bug 数。 - * Test get report data of resolved bugs per user. - * - * @access public - * @return array - */ - public function getDataOfResolvedBugsPerUserTest(): array - { - $datas = $this->objectModel->getDataOfResolvedBugsPerUser(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每人解决的 bug 数(空数据测试)。 - * Test get report data of resolved bugs per user with empty data. - * - * @access public - * @return array - */ - public function getDataOfResolvedBugsPerUserTestWithEmptyData(): array - { - global $tester; - $originalBugs = $tester->dao->select('*')->from(TABLE_BUG)->where('resolvedBy')->ne('')->fetchAll(); - $tester->dao->update(TABLE_BUG)->set('resolvedBy')->eq('')->where('resolvedBy')->ne('')->exec(); - - $datas = $this->objectModel->getDataOfResolvedBugsPerUser(); - - foreach($originalBugs as $bug) - { - $tester->dao->update(TABLE_BUG)->set('resolvedBy')->eq($bug->resolvedBy)->where('id')->eq($bug->id)->exec(); - } - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 统计每人关闭的 bug 数。 - * Test get report data of closed bugs per user. - * - * @access public - * @return array - */ - public function getDataOfClosedBugsPerUserTest(): array - { - $datas = $this->objectModel->getDataOfClosedBugsPerUser(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 严重程度统计。 - * Test get report data of bugs per severity. - * - * @access public - * @return array - */ - public function getDataOfBugsPerSeverityTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerSeverity(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 解决方案统计。 - * Test get report data of bugs per resolution. - * - * @access public - * @return array - */ - public function getDataOfBugsPerResolutionTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerResolution(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 状态统计。 - * Test get report data of bugs per status. - * - * @access public - * @return array - */ - public function getDataOfBugsPerStatusTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerStatus(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 优先级次数统计。 - * Test get report data of bugs per pri. - * - * @access public - * @return array - */ - public function getDataOfBugsPerPriTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerPri(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 激活次数统计。 - * Test get report data of bugs per status. - * - * @access public - * @return array - */ - public function getDataOfBugsPerActivatedCountTest() - { - $datas = $this->objectModel->getDataOfBugsPerActivatedCount(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 类型统计。 - * Test get report data of bugs per type. - * - * @access public - * @return array - */ - public function getDataOfBugsPerTypeTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerType(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 按照 bug 指派给统计。 - * Test get report data of bugs per assignedTo. - * - * @access public - * @return array - */ - public function getDataOfBugsPerAssignedToTest(): array - { - $datas = $this->objectModel->getDataOfBugsPerAssignedTo(); - - if(dao::isError()) return dao::getError(); - - return $datas; - } - - /** - * 测试判断当前动作是否可以点击。 - * Test adjust the action is clickable. - * - * @param object $bug - * @param string $action - * @access public - * @return int - */ - public function isClickableTest(object $bug, string $action): int - { - $bool = $this->objectModel->isClickable($bug, $action); - return $bool ? 1 : 2; - } - - /** - * Test link bug to build and release. - * - * @param int $bugID - * @param int|string $resolvedBuild - * @access public - * @return object|array|bool - */ - public function linkBugToBuildTest(int $bugID, int|string $resolvedBuild): array|object|bool - { - $this->objectModel->linkBugToBuild($bugID, $resolvedBuild); - - global $tester; - $release = $tester->dao->select('id,bugs')->from(TABLE_RELEASE)->where('build')->eq($resolvedBuild)->andWhere('deleted')->eq('0')->fetch(); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $release; - } - } - - /** - * 测试 获取指派用户和抄送给用户列表。 - * Test get toList and ccList. - * - * @param int $bugID - * @access public - * @return string|string - */ - public function getToAndCcListTest(int $bugID): array|string - { - $bug = $this->objectModel->getByID($bugID); - $array = $this->objectModel->getToAndCcList($bug); - - $account = ''; - foreach($array as $value) $account .= ',' . $value; - $account = trim($account, ','); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $account; - } - } - - /** - * 测试获取bug查询语句。 - * Test get bug query. - * - * @param string $bugQuery - * @access public - * @return string|array - */ - public function getBugQueryTest(string $bugQuery): string|array - { - $array = $this->objectModel->getBugQuery($bugQuery); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $array; - } - } - - /** - * Test get statistic. - * - * @param int $productID - * @access public - * @return string - */ - public function getStatisticTest($productID = 0) - { - $dates = $this->objectModel->getStatistic($productID); - $returns = array(); - $today = date('m/d', time()); - foreach($dates as $dateType => $dateList) - { - $returns[$dateType] = $dateList[$today]; - } - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $returns; - } - } - - /** - * 测试更新相关 bug。 - * The test for updatelinkbug function. - * - * @param int $bugID - * @param string $relatedBug - * @param string $oldRelatedBug - * @access public - * @return array - */ - public function updateRelatedBugTest(int $bugID, string $relatedBug, string $oldRelatedBug): array|bool - { - $this->objectModel->updateRelatedBug($bugID, $relatedBug, $oldRelatedBug); - - $relatedBugs = explode(',', $relatedBug); - $oldRelatedBugs = explode(',', $oldRelatedBug); - $addedRelatedBugs = array_diff($relatedBugs, $oldRelatedBugs); - $removedRelatedBugs = array_diff($oldRelatedBugs, $relatedBugs); - $allRelatedRelatedBugs = array_merge($addedRelatedBugs, $removedRelatedBugs, array($bugID)); - - global $tester; - $relatedBugPairs = $tester->dao->select('id, relatedBug')->from(TABLE_BUG) - ->where('id')->in(array_filter($allRelatedRelatedBugs)) - ->andWhere('deleted')->eq('0') - ->fetchPairs(); - - if(dao::isError()) return dao::getError(); - return $relatedBugPairs; - } - - /** - * 测试在解决bug的时候创建版本。 - * Test create build when resolving a bug. - * - * @access public - * @return array - */ - public function createBuildTest(object $bug, int $bugID) - { - global $tester; - $oldBug = $tester->dao->findByID($bugID)->from(TABLE_BUG)->fetch(); - $this->objectModel->createBuild($bug, $oldBug); - - if(dao::isError()) - { - $errors = dao::getError(); - $return = ''; - foreach($errors as $key => $value) - { - if(is_string($value)) $return .= "{$value}"; - if(is_array($value)) $return .= implode('', $value); - } - return $return; - } - else - { - $build = $tester->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch(); - return $build; - } - } - - /** - * 测试通过版本 id 列表获取版本关联的执行。 - * Test get linked execution by id list. - * - * @param string $buildIdList - * @access public - * @return void - */ - public function getLinkedExecutionByIdListTest(string $buildIdList): array|string - { - $buildIdList = explode(',', $buildIdList); - $array = $this->objectModel->getLinkedExecutionByIdList($buildIdList); - - $idList = ''; - foreach($array as $execution) $idList .= ',' . $execution; - $idList = trim($idList, ','); - - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $idList; - } - } - - /** - * 测试获取 bugs 统计信息。 - * Test get the statistics of the bugs. - * - * @param string $bugIdList - * @access public - * @return string - */ - public function summaryTest(string $bugIdList): string - { - $bugs = $this->objectModel->getByIdList($bugIdList); - if(empty($bugs)) $bugs = array(); - $summary = $this->objectModel->summary($bugs); - return $summary; - } - - /** - * 测试从 SESSION 中获取报表操作。 - * Test get report condition from session. - * - * @param string $bugIdList - * @access public - * @return string - */ - public function reportConditionTest(string|bool $bugQueryCondition, bool $bugOnlyCondition): string - { - global $tester; - if($bugQueryCondition) $tester->session->set('bugQueryCondition', $bugQueryCondition); - if($bugOnlyCondition) $tester->session->set('bugOnlyCondition', $bugOnlyCondition); - $reportCondition = $this->objectModel->reportCondition(); - unset($_SESSION['bugQueryCondition']); - unset($_SESSION['bugOnlyCondition']); - return $reportCondition; - } - - /** - * 测试获取产品的 bugs。 - * Test get product bugs. - * - * @param string $productIdList - * @param string $type - * @param string $begin - * @param string $end - * @access public - * @return string - */ - public function getProductBugsTest(string $productIdList, string $type = '', string $begin = '', string $end = ''): string - { - if($begin == 'today') $begin = date('Y-m-d', time()); - if($begin == 'lastweek') $begin = date('Y-m-d', strtotime('-7 days')); - if($end == 'today') $end = date('Y-m-d', time()); - if($end == 'nextweek') $end = date('Y-m-d', strtotime('+7 days')); - $bugs = $this->objectModel->getProductBugs(explode(',', $productIdList), $type, $begin, $end); - if(dao::isError()) return dao::getError(); - return implode(',', array_column($bugs, 'id')); - } - - /** - * 测试获取产品的 bugs。 - * Test get product bugs. - * - * @param string $productIdList - * @param string $begin - * @param string $end - * @param string $buildIdList - * @access public - * @return string - */ - public function getActivatedBugsTest(string $productIdList, string $begin = '', string $end = '', string $buildIdList = ''): string - { - $date = '2025-05-01'; - if($begin == 'lastweek') $begin = date('Y-m-d', strtotime($date . '-7 days')); - if($begin == 'lastmonth') $begin = date('Y-m-d', strtotime($date . '-30 days')); - if($end == 'nextweek') $end = date('Y-m-d', strtotime($date . '+7 days')); - if($end == 'nextmonth') $end = date('Y-m-d', strtotime($date . '+30 days')); - $bugs = $this->objectModel->getActivatedBugs(explode(',', $productIdList), $begin, $end, explode(',', $buildIdList)); - if(dao::isError()) return dao::getError(); - return implode(',', array_column($bugs, 'id')); - } - - /** - * 测试通过任务 id 获取相关 Bug. - * Test get linked bug by task id. - * - * @param int $taskID - * @access public - * @return array|string|false - */ - public function getLinkedBugsByTaskIDTest(int $taskID): array|string|false - { - $bugs = $this->objectModel->getLinkedBugsByTaskID($taskID); - - $result = ''; - foreach($bugs as $bug) $result .= "{$bug->id}:{$bug->title},"; - $result = trim($result, ','); - - return dao::isError() ? dao::getError() : $result; - } - - /** - * Test buildSearchForm method. - * - * @param int $productID - * @param array $products - * @param int $queryID - * @param string $actionURL - * @param string $branch - * @access public - * @return array|string - */ - public function buildSearchFormTest(int $productID, array $products, int $queryID, string $actionURL, string $branch = '0'): array|string - { - global $tester; - - // 模拟必要的session设置 - if(!isset($tester->session->project)) $tester->session->set('project', 0); - - // 模拟语言配置 - if(!isset($tester->lang->all)) $tester->lang->all = 'All'; - if(!isset($tester->lang->bug->allProject)) $tester->lang->bug->allProject = 'All Projects'; - if(!isset($tester->lang->navGroup->bug)) $tester->lang->navGroup->bug = 'qa'; - - // 如果是教程模式,直接返回简单结果 - if(defined('TUTORIAL') && TUTORIAL) return array('actionURL' => $actionURL, 'queryID' => $queryID, 'hasProductParams' => 1); - - try { - $this->objectModel->buildSearchForm($productID, $products, $queryID, $actionURL, $branch); - } catch(Exception $e) { - // 如果调用失败,返回模拟结果 - return array('actionURL' => $actionURL, 'queryID' => $queryID, 'hasProductParams' => 1); - } - - if(dao::isError()) return dao::getError(); - - $result = array(); - if(isset($tester->config->bug->search)) - { - $searchConfig = $tester->config->bug->search; - $result['actionURL'] = $searchConfig['actionURL'] ?? $actionURL; - $result['queryID'] = $searchConfig['queryID'] ?? $queryID; - $result['hasProjectParams'] = isset($searchConfig['params']['project']['values']) ? 1 : 0; - $result['hasProductParams'] = isset($searchConfig['params']['product']['values']) ? 1 : 0; - $result['hasModuleParams'] = isset($searchConfig['params']['module']['values']) ? 1 : 0; - $result['hasBranchField'] = isset($searchConfig['fields']['branch']) ? 1 : 0; - } else { - // 如果配置未设置,返回基本结果 - $result = array('actionURL' => $actionURL, 'queryID' => $queryID, 'hasProductParams' => 1); - } - - return $result; - } - - /** - * Test buildSearchConfig method. - * - * @param int $productID - * @access public - * @return array - */ - public function buildSearchConfigTest(int $productID): array - { - $result = $this->objectModel->buildSearchConfig($productID); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test getRelatedObjects method. - * - * @param string $object - * @param string $pairs - * @access public - * @return int - */ - public function getRelatedObjectsTest(string $object, string $pairs = ''): object - { - global $tester; - - /* 设置bugQueryCondition来模拟有查询条件的情况 */ - $_SESSION['bugQueryCondition'] = "SELECT * FROM " . TABLE_BUG . " WHERE deleted = '0'"; - $_SESSION['bugOnlyCondition'] = true; - - $result = $this->objectModel->getRelatedObjects($object, $pairs); - - if(dao::isError()) return (object)array('error' => dao::getError()); - - /* 返回详细的测试结果 */ - $testResult = new stdClass(); - $testResult->count = count($result); - $testResult->hasEmpty = isset($result['']) ? 1 : 0; - $testResult->hasZero = isset($result[0]) ? 1 : 0; - $testResult->hasTrunk = isset($result['trunk']) ? 1 : 0; - $testResult->data = $result; - - return $testResult; - } - - /** - * Test getDatatableModules method. - * - * @param int $productID - * @access public - * @return array - */ - public function getDatatableModulesTest(int $productID): array - { - $result = $this->objectModel->getDatatableModules($productID); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test updateLinkedCommits method. - * - * @param int $bugID - * @param int $repoID - * @param array $revisions - * @access public - * @return bool - */ - public function updateLinkedCommitsTest(int $bugID, int $repoID, array $revisions): bool - { - $result = $this->objectModel->updateLinkedCommits($bugID, $repoID, $revisions); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test getLinkedCommits method. - * - * @param int $repoID - * @param array $revisions - * @access public - * @return array - */ - public function getLinkedCommitsTest(int $repoID, array $revisions): array - { - // 处理空数组情况,避免SQL语法错误 - if(empty($revisions)) return array(); - - $result = $this->objectModel->getLinkedCommits($repoID, $revisions); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test getBatchResolveVars method. - * - * @param array $bugIDList - * @access public - * @return array|int - */ - public function getBatchResolveVarsTest(array $bugIDList): array|int - { - global $tester; - - if(empty($bugIDList)) return 0; - - $oldBugs = array(); - foreach($bugIDList as $bugID) - { - $bug = $tester->dao->select('*')->from(TABLE_BUG)->where('id')->eq($bugID)->fetch(); - if($bug) $oldBugs[] = $bug; - } - - if(empty($oldBugs)) return 0; - - $bug = reset($oldBugs); - $productID = $bug->product; - $product = $this->objectModel->loadModel('product')->getByID($productID); - if(!$product) return 0; - - $stmt = $tester->dao->query($this->objectModel->loadModel('tree')->buildMenuQuery($productID, 'bug')); - $modules = array(); - while($module = $stmt->fetch()) $modules[$module->id] = $module; - - if(dao::isError()) return dao::getError(); - - return array(count($modules), 'modules'); - } - - /** - * Test setBrowseCookie method. - * - * @param object $product - * @param string $branch - * @param string $browseType - * @param int $param - * @param string $orderBy - * @access public - * @return bool - */ - public function setBrowseCookieTest(object $product, string $branch, string $browseType, int $param, string $orderBy): bool - { - global $app; - - $app->rawModule = 'bug'; - $app->rawMethod = 'browse'; - - $zen = initReference('bug'); - $method = $zen->getMethod('setBrowseCookie'); - - $result = $method->invokeArgs($zen->newInstance(), array($product, $branch, $browseType, $param, $orderBy)); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test setCreateMenu method. - * - * @param int $productID - * @param string $branch - * @param array $output - * @access public - * @return bool - */ - public function setCreateMenuTest(int $productID, string $branch, array $output): bool - { - global $tester, $app; - - // 设置app属性 - if(isset($output['executionID'])) - { - $app->tab = 'execution'; - $tester->session->set('execution', $output['executionID']); - } - elseif(isset($output['projectID'])) - { - $app->tab = 'project'; - } - else - { - $app->tab = 'qa'; - } - - $zen = initReference('bug'); - $method = $zen->getMethod('setCreateMenu'); - - $zenInstance = $zen->newInstance(); - - // 模拟products属性避免重定向 - $products = $tester->loadModel('product')->getPairs('noclosed', 0, '', 'all'); - $zenInstance->products = $products; - - $result = $method->invokeArgs($zenInstance, array($productID, $branch, $output)); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test setEditMenu method. - * - * @param int $bugID - * @param string $tab - * @access public - * @return int - */ - public function setEditMenuTest(int $bugID, string $tab): int - { - global $tester, $app; - - // 获取bug对象 - $bug = $this->objectModel->getById($bugID); - if(!$bug) return 0; - - // 设置app tab - $app->tab = $tab; - - $zen = initReference('bug'); - $method = $zen->getMethod('setEditMenu'); - - $zenInstance = $zen->newInstance(); - - $result = $method->invokeArgs($zenInstance, array($bug)); - - if(dao::isError()) return 0; - - return $result ? 1 : 0; - } - - /** - * Test setViewMenu method. - * - * @param object $bug - * @param string $tab - * @access public - * @return bool - */ - public function setViewMenuTest(object $bug, string $tab): bool - { - global $tester, $app; - - // 设置app tab - $app->tab = $tab; - - try { - // 使用反射调用受保护的方法 - $zenClass = initReference('bug'); - $method = $zenClass->getMethod('setViewMenu'); - $zenInstance = $zenClass->newInstance(); - - $result = $method->invokeArgs($zenInstance, array($bug)); - - if(dao::isError()) return dao::getError(); - - return $result; - } catch (Exception $e) { - // 如果调用失败,模拟返回true(因为setViewMenu总是返回true) - return true; - } - } - - /** - * Test prepareBrowseParams method. - * - * @param string $browseType - * @param int $param - * @param string $orderBy - * @param int $recTotal - * @param int $recPerPage - * @param int $pageID - * @access public - * @return array - */ - public function prepareBrowseParamsTest(string $browseType, int $param, string $orderBy, int $recTotal, int $recPerPage, int $pageID): array - { - global $tester; - - // 设置cookie模拟 - if(!isset($_COOKIE['bugModule'])) $_COOKIE['bugModule'] = 1; - - // 创建zen实例 - $zen = initReference('bug'); - $method = $zen->getMethod('prepareBrowseParams'); - $zenInstance = $zen->newInstance(); - - // 设置必要的属性 - $zenInstance->cookie = (object)array('bugModule' => 1); - $zenInstance->app = $tester->app; - - $result = $method->invokeArgs($zenInstance, array($browseType, $param, $orderBy, $recTotal, $recPerPage, $pageID)); - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test buildBrowseView method. - * - * @param array $bugs - * @param object $product - * @param string $branch - * @param string $browseType - * @param int $moduleID - * @param array $executions - * @param int $param - * @param string $orderBy - * @param object $pager - * @access public - * @return array - */ - public function buildBrowseViewTest(array $bugs, object $product, string $branch, string $browseType, int $moduleID, array $executions, int $param, string $orderBy, object $pager): array - { - global $tester; - - // 由于buildBrowseView方法主要是设置视图变量,我们模拟其主要逻辑 - // 验证参数的有效性和基本逻辑处理 - - $result = array(); - - // 验证基础参数处理 - $result['bugCount'] = count($bugs); - $result['productType'] = $product->type ?? 'normal'; - $result['branchValid'] = is_string($branch) ? 1 : 0; - $result['browseTypeValid'] = is_string($browseType) ? 1 : 0; - $result['moduleIDValid'] = is_int($moduleID) ? 1 : 0; - $result['executionCount'] = count($executions); - $result['paramValid'] = is_int($param) ? 1 : 0; - $result['orderByValid'] = is_string($orderBy) ? 1 : 0; - $result['pagerValid'] = is_object($pager) ? 1 : 0; - - // 验证bugs数组中story和task的提取逻辑 - $storyCount = 0; - $taskCount = 0; - foreach($bugs as $bug) { - if(isset($bug->story) && $bug->story > 0) $storyCount++; - if(isset($bug->task) && $bug->task > 0) $taskCount++; - if(isset($bug->toTask) && $bug->toTask > 0) $taskCount++; - } - $result['storyCount'] = $storyCount; - $result['taskCount'] = $taskCount; - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test getProductsForCreate method. - * - * @param object $bug - * @access public - * @return object|array - */ - public function getProductsForCreateTest(object $bug): object|array - { - global $tester; - - try { - // 直接模拟方法的核心逻辑,因为反射可能失败 - $productID = (int)$bug->productID; - $projectID = (int)$bug->projectID; - $executionID = (int)$bug->executionID; - - // 模拟获取产品列表 - $products = $this->objectModel->loadModel('product')->getPairs('noclosed', 0, '', 'all'); - $productID = isset($products[$productID]) ? $productID : key($products); - - // 根据不同tab处理产品列表 - global $app; - if($app->tab == 'project' && $projectID) - { - $products = array(); - $linkedProducts = $this->objectModel->loadModel('product')->getOrderedProducts('normal', 40, $projectID); - foreach($linkedProducts as $product) $products[$product->id] = $product->name; - } - elseif($app->tab == 'execution' && $executionID) - { - $products = array(); - $linkedProducts = $this->objectModel->loadModel('product')->getProducts($executionID); - foreach($linkedProducts as $product) $products[$product->id] = $product->name; - - $execution = $this->objectModel->loadModel('execution')->getByID($executionID); - if($execution) $projectID = $execution->project; - } - - // 创建返回对象 - $result = clone $bug; - $result->products = $products; - $result->productID = $productID; - $result->projectID = $projectID; - - if(dao::isError()) return dao::getError(); - - return $result; - } catch (Exception $e) { - // 如果失败,返回基本的bug对象 - $result = clone $bug; - $result->productID = $bug->productID; - return $result; - } - } - - /** - * Test getBranchesForCreate method. - * - * @param object $bug - * @access public - * @return object|array|string - */ - public function getBranchesForCreateTest(object $bug): object|array|string - { - global $tester; - - try { - // 模拟方法的核心逻辑 - $productID = (int)$bug->productID; - $branch = (string)$bug->branch; - $product = $this->objectModel->loadModel('product')->getByID($productID); - - if(!$product) return 'product not found'; - - global $app; - $branches = array(); - - if($app->tab == 'execution' || $app->tab == 'project') - { - $objectID = $app->tab == 'project' ? (int)$bug->projectID : (int)$bug->executionID; - if($product->type != 'normal') - { - $productBranches = $this->objectModel->loadModel('execution')->getBranchByProduct(array($productID), $objectID, 'noclosed|withMain'); - $branches = isset($productBranches[$productID]) ? $productBranches[$productID] : array(''); - } - else - { - $branches = array(''); - } - $branch = empty($branch) ? key($branches) : $branch; - } - else - { - if($product->type != 'normal') - { - $branches = $this->objectModel->loadModel('branch')->getPairs($productID, 'active'); - } - else - { - $branches = array(''); - } - $branch = isset($branches[$branch]) ? $branch : ''; - } - - $result = clone $bug; - $result->branches = $branches; - $result->branch = $branch; - - if(dao::isError()) return dao::getError(); - - return $result; - } catch (Exception $e) { - return 'error: ' . $e->getMessage(); - } - } - - /** - * Test getProjectsForCreate method. - * - * @param object $bug - * @access public - * @return object|array - */ - public function getProjectsForCreateTest(object $bug): object|array - { - global $tester; - - // 模拟方法的核心逻辑,因为反射可能不稳定 - $projectID = (int)$bug->projectID; - $productID = (int)$bug->productID; - $branch = (string)$bug->branch; - $executionID = (int)$bug->executionID; - - // 模拟获取产品信息 - $product = new stdclass(); - $product->shadow = ($productID == 5) ? 1 : 0; // 产品5为影子产品 - - // 模拟获取项目列表 - $projects = array(); - for($i = 11; $i <= 15; $i++) { - $projects[$i] = "项目{$i}"; - } - - // 检查项目ID是否有效,如果无效则选择第一个 - if(!isset($projects[$projectID])) { - $projectID = key($projects); // 选择第一个项目ID (11) - } - - // 处理执行环境下的项目获取逻辑 - if($tester->app->tab == 'execution' && $executionID && !$projectID) { - // 根据执行ID获取项目ID - if($executionID >= 101 && $executionID <= 105) { - $projectID = $executionID - 90; // 101->11, 102->12... - } - } - - // 处理影子产品逻辑 - if($product->shadow && !$projectID) { - $projectID = key($projects); - } - - // 模拟项目信息 - $project = array(); - if($projectID) { - $project = new stdclass(); - $project->id = $projectID; - $project->name = "项目{$projectID}"; - $project->model = ($projectID == 13) ? 'waterfall' : 'scrum'; - $project->multiple = ($projectID <= 13) ? 1 : 0; - - if($project->model == 'waterfall') { - // 模拟瀑布模式处理 - } - - if(!$project->multiple) { - // 模拟获取非多迭代执行ID - $executionID = $projectID + 90; // 简单映射 - } - } - - // 创建结果对象 - $result = clone $bug; - $result->projects = $projects; - $result->projectID = $projectID; - $result->project = $project; - $result->executionID = $executionID; - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Get config fields for testing. - * - * @access public - * @return string - */ - public function getConfigFields(): string - { - global $config; - return isset($config->bug->list->customCreateFields) ? $config->bug->list->customCreateFields : ''; - } - - /** - * Test getStoriesForCreate method. - * - * @param object $bug - * @access public - * @return int - */ - public function getStoriesForCreateTest(object $bug): int - { - // 模拟getStoriesForCreate方法的逻辑,因为它是私有方法 - // 这里模拟该方法的主要业务逻辑来进行测试 - - $productID = (int)$bug->productID; - $branch = (string)$bug->branch; - $moduleID = (int)$bug->moduleID; - $projectID = (int)$bug->projectID; - $executionID = (int)$bug->executionID; - - $stories = array(); - - // 模拟根据不同条件获取需求 - if($executionID || $projectID) - { - // 模拟从项目或执行获取需求 - $stories = array( - 1 => '需求标题1', - 2 => '需求标题2', - 3 => '需求标题3', - 4 => '需求标题4' - ); - } - else - { - if($moduleID) - { - // 模拟从指定模块获取需求 - $stories = array( - 1 => '需求标题1', - 6 => '需求标题6' - ); - } - else - { - // 模拟获取产品所有需求 - if($productID == 1) { - $stories = array( - 11 => '需求标题11', - 15 => '需求标题15' - ); - } else { - $stories = array( - 16 => '需求标题16', - 20 => '需求标题20' - ); - } - } - } - - // 返回需求的数量 - return count($stories); - } - - /** - * Test getTasksForCreate method. - * - * @param object $bug - * @access public - * @return object - */ - public function getTasksForCreateTest(object $bug): object - { - // 模拟getTasksForCreate方法的业务逻辑 - // 因为该方法是私有的,我们直接实现其逻辑进行测试 - - $executionID = (int)$bug->executionID; - - $tasks = null; - if($executionID) - { - // 从数据库获取执行的任务 - global $tester; - $taskModel = $tester->loadModel('task'); - $tasks = $taskModel->getExecutionTaskPairs($executionID); - } - - // 模拟updateBug方法的效果 - $result = clone $bug; - $result->tasks = $tasks; - - // 为了方便测试,我们返回tasks的数量或null状态 - if($tasks === null) - { - $result->tasksCount = 0; - } - else - { - $result->tasksCount = is_array($tasks) ? count($tasks) : 0; - } - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test buildEditForm method. - * - * @param object $bug - * @access public - * @return array - */ - public function buildEditFormTest(object $bug): array - { - global $tester; - - // 简化测试:检查传入的bug对象是否有效 - if(empty($bug) || !isset($bug->id)) { - return array('hasBug' => 0, 'hasProduct' => 0, 'hasExecutions' => 0); - } - - // 模拟buildEditForm方法的关键逻辑验证 - $result = array(); - $result['hasBug'] = !empty($bug->id) ? 1 : 0; - $result['hasProduct'] = !empty($bug->product) ? 1 : 0; - $result['hasProjects'] = !empty($bug->project) ? 1 : 0; - $result['hasExecutions'] = !empty($bug->execution) ? 1 : 0; - $result['hasModuleOptionMenu'] = !empty($bug->module) ? 1 : 0; - $result['hasBranchTagOption'] = !empty($bug->branch) ? 1 : 0; - $result['hasOpenedBuilds'] = !empty($bug->openedBuild) ? 1 : 0; - $result['hasAssignedToList'] = !empty($bug->assignedTo) ? 1 : 0; - $result['hasStories'] = !empty($bug->story) ? 1 : 0; - $result['hasCases'] = 1; // 总是返回1,因为用例总是会被查询 - - if(dao::isError()) return dao::getError(); - - return $result; - } - - /** - * Test assignVarsForEdit method. - * - * 由于assignVarsForEdit是protected方法且主要设置视图变量, - * 我们通过模拟其主要业务逻辑来测试。 - * - * @param object $bug - * @param object $product - * @access public - * @return mixed - */ - public function assignVarsForEditTest($bug = null, $product = null) - { - if(is_null($bug)) - { - $bug = new stdclass(); - $bug->id = 1; - $bug->product = 1; - $bug->execution = 101; - $bug->project = 11; - $bug->branch = 'main'; - $bug->assignedTo = 'admin'; - $bug->openedBuild = '1'; - $bug->story = 1; - $bug->module = 1; - } - - if(is_null($product)) - { - $product = new stdclass(); - $product->id = 1; - $product->name = 'Test Product'; - $product->shadow = 0; - $product->type = 'normal'; - } - - // 模拟assignVarsForEdit方法的主要逻辑验证 - $result = array(); - - // 验证bug对象的基本属性 - if(!empty($bug->id) && !empty($bug->product)) - { - $result['hasBugAndProduct'] = 1; - } - else - { - $result['hasBugAndProduct'] = 0; - } - - // 验证产品处理逻辑 - if(!empty($product->shadow)) - { - $result['isShadowProduct'] = 1; - } - else - { - $result['isShadowProduct'] = 0; - } - - // 验证执行相关逻辑 - if(!empty($bug->execution)) - { - $result['hasExecution'] = 1; - } - else if(!empty($bug->project)) - { - $result['hasProject'] = 1; - } - else - { - $result['hasDefault'] = 1; - } - - // 验证指派人员 - if(!empty($bug->assignedTo)) - { - $result['hasAssignedTo'] = 1; - } - else - { - $result['hasAssignedTo'] = 0; - } - - $result['executedSuccessfully'] = 1; - - return $result; - } - - /** - * Test buildBugForResolve method. - * - * @param object $oldBug - * @access public - * @return mixed - */ - public function buildBugForResolveTest($oldBug) - { - if(empty($oldBug)) return false; - - // 模拟buildBugForResolve方法的主要逻辑 - $bug = new stdclass(); - - // 设置基本字段 - $bug->id = $oldBug->id; - $bug->execution = $oldBug->execution; - $bug->status = 'resolved'; - $bug->confirmed = 1; - - // 设置默认值 - $bug->assignedTo = $oldBug->openedBy; - $bug->resolvedDate = helper::now(); - - // 处理resolution逻辑 - if(isset($_POST['resolution']) && $_POST['resolution'] != 'duplicate') - { - // 非重复bug不包含duplicateBug字段 - $bug->noDuplicateBug = true; - } - else - { - // 重复bug包含duplicateBug字段 - $bug->duplicateBug = isset($_POST['duplicateBug']) ? $_POST['duplicateBug'] : 0; - } - - // 处理resolvedBuild逻辑 - if(isset($_POST['resolvedBuild']) && $_POST['resolvedBuild'] != 'trunk') - { - // 非trunk构建时设置testtask - $bug->testtask = 1; // 模拟找到的testtask ID - } - - return $bug; - } - - /** - * Test buildBugsForBatchCreate method. - * - * @param int $productID - * @param string $branch - * @param array $bugImagesFile - * @access public - * @return mixed - */ - public function buildBugsForBatchCreateTest(int $productID, string $branch = '', array $bugImagesFile = array()) - { - // 模拟buildBugsForBatchCreate方法的核心逻辑 - global $app; - - // 模拟表单数据提取 - $bugs = array(); - if(!empty($_POST['title'])) { - foreach($_POST['title'] as $index => $title) { - if(empty($title)) continue; - - $bug = new stdclass(); - $bug->title = $title; - $bug->type = isset($_POST['type'][$index]) ? $_POST['type'][$index] : 'codeerror'; - $bug->severity = isset($_POST['severity'][$index]) ? $_POST['severity'][$index] : 3; - $bug->pri = isset($_POST['pri'][$index]) ? $_POST['pri'][$index] : 3; - $bug->module = isset($_POST['module'][$index]) ? $_POST['module'][$index] : 0; - $bug->steps = isset($_POST['steps'][$index]) ? $_POST['steps'][$index] : ''; - - // 设置创建者和时间 - $bug->openedBy = $app->user->account ?? 'admin'; - $bug->openedDate = helper::now(); - $bug->product = $productID; - $bug->steps = nl2br($bug->steps); - - // 模拟模块负责人分配 - if(!empty($bug->module)) { - $bug->assignedTo = $app->user->account ?? 'admin'; - $bug->assignedDate = helper::now(); - } - - // 处理图片上传 - $bug->uploadImage = isset($_POST['uploadImage'][$index]) ? $_POST['uploadImage'][$index] : ''; - $bug->imageFile = array(); - - $bugs[] = $bug; - } - } - - return $bugs; - } - - /** - * Test assignBatchCreateVars method. - * - * @param int $executionID - * @param object $product - * @param string $branch - * @param array $output - * @param array $bugImagesFile - * @access public - * @return mixed - */ - public function assignBatchCreateVarsTest(int $executionID = 0, ?object $product = null, string $branch = '', array $output = array(), array $bugImagesFile = array()) - { - global $tester; - - if($product === null) $product = new stdclass(); - - // 模拟assignBatchCreateVars方法的关键逻辑验证 - $result = array(); - $result['executionID'] = $executionID; - $result['hasProduct'] = !empty($product) ? 1 : 0; - $result['productType'] = isset($product->type) ? $product->type : 'normal'; - $result['hasBranch'] = !empty($branch) ? 1 : 0; - $result['hasOutput'] = !empty($output) ? 1 : 0; - $result['hasImages'] = !empty($bugImagesFile) ? 1 : 0; - - // 根据executionID判断是否需要设置执行相关变量 - if($executionID > 0) - { - $result['hasExecution'] = 1; - $result['executionBased'] = 1; - } - else - { - $result['hasExecution'] = 0; - $result['executionBased'] = 0; - } - - // 根据产品类型判断是否有分支 - if(isset($product->type) && $product->type != 'normal') - { - $result['hasBranches'] = 1; - } - else - { - $result['hasBranches'] = 0; - } - - // 如果有图片文件,验证标题提取 - if(!empty($bugImagesFile)) - { - $result['imageCount'] = count($bugImagesFile); - $result['hasTitles'] = 1; - } - else - { - $result['imageCount'] = 0; - $result['hasTitles'] = 0; - } - - return $result; - } - - /** - * Test assignVarsForBatchCreate method. - * - * @param object $product - * @param object $project - * @param array $bugImagesFile - * @access public - * @return mixed - */ - public function assignVarsForBatchCreateTest(object $product, object $project, array $bugImagesFile): mixed - { - // 模拟assignVarsForBatchCreate方法的关键逻辑验证 - $result = array(); - - // 根据配置设置自定义字段 - $customFields = array(); - $customBatchCreateFields = 'project,execution,plan,steps,type,pri,deadline,severity,os,browser,keywords'; - foreach(explode(',', $customBatchCreateFields) as $field) - { - $customFields[$field] = ucfirst($field); - } - - // 根据产品类型添加分支字段 - if($product->type != 'normal') - { - $customFields['branch'] = 'Branch'; - } - - // 根据项目模式添加执行字段 - if(isset($project->model) && $project->model == 'kanban') - { - $customFields['execution'] = 'Execution'; - } - - // 处理图片文件标题 - $titles = array(); - if(!empty($bugImagesFile)) - { - foreach($bugImagesFile as $fileName => $file) - { - if(isset($file['title'])) - { - $title = $file['title']; - $titles[$title] = $fileName; - } - } - } - - // 设置显示字段 - $showFields = 'project,execution,deadline,steps,type,pri,severity,os,browser,' . ($product->type != 'normal' ? 'branch' : ''); - $showFields = trim($showFields, ','); - - return (object) array( - 'customFields' => $customFields, - 'showFields' => $showFields, - 'titles' => $titles, - 'hasCustomFields' => !empty($customFields) ? '1' : '0', - 'hasTitles' => !empty($titles) ? '1' : '0', - 'hasBranch' => isset($customFields['branch']) ? '1' : '0', - 'hasExecution' => isset($customFields['execution']) ? '1' : '0', - 'productType' => $product->type, - 'projectModel' => isset($project->model) ? $project->model : '' - ); - } - - /** - * Test buildSearchFormForLinkBugs method. - * - * @param object $bug - * @param string $excludeBugs - * @param int $queryID - * @access public - * @return mixed - */ - public function buildSearchFormForLinkBugsTest($bug = null, $excludeBugs = '', $queryID = 0) - { - if(is_null($bug)) - { - $bug = new stdClass(); - $bug->id = 1; - $bug->project = 1; - $bug->product = 1; - $bug->title = 'Test Bug'; - } - - // 简化测试,直接模拟方法的逻辑 - $hasProduct = '1'; - $hasExecution = '1'; - $hasPlan = '1'; - - // 模拟方法内部的逻辑判断 - if($bug->project && $bug->id != 4) // 不是QA tab - { - // 模拟project.hasProduct为false的情况(如bug id为2或3) - if($bug->id == 2 || $bug->id == 3) - { - $hasProduct = '0'; - $hasExecution = '0'; - $hasPlan = '0'; - } - } - - return array( - 'hasProduct' => $hasProduct, - 'hasExecution' => $hasExecution, - 'hasPlan' => $hasPlan - ); - } - - /** - * Test buildBugsForBatchEdit method. - * - * @param array $oldBugs - * @access public - * @return mixed - */ - public function buildBugsForBatchEditTest($oldBugs = array()) - { - global $tester; - - if(empty($oldBugs)) return array(); - - // 模拟 form::batchData 返回的数据 - $bugs = array(); - foreach($oldBugs as $oldBug) - { - $bug = new stdclass(); - $bug->id = $oldBug->id; - $bug->os = isset($oldBug->os) ? $oldBug->os : 'linux'; - $bug->browser = isset($oldBug->browser) ? $oldBug->browser : 'chrome'; - $bug->assignedTo = isset($oldBug->assignedTo) ? $oldBug->assignedTo : ''; - $bug->resolution = isset($oldBug->resolution) ? $oldBug->resolution : ''; - $bug->resolvedBy = isset($oldBug->resolvedBy) ? $oldBug->resolvedBy : ''; - $bug->duplicateBug = isset($oldBug->duplicateBug) ? $oldBug->duplicateBug : 0; - $bug->project = isset($oldBug->project) ? $oldBug->project : 0; - $bugs[] = $bug; - } - - $now = helper::now(); - - // 模拟 buildBugsForBatchEdit 方法的主要逻辑 - foreach($bugs as $index => $bug) - { - $oldBug = $oldBugs[$bug->id - 1]; // 调整索引 - - // 处理数组类型的 os 和 browser - if(is_array($bug->os)) $bug->os = implode(',', $bug->os); - if(is_array($bug->browser)) $bug->browser = implode(',', $bug->browser); - - // 如果bug已关闭,指派人员不变 - if(isset($oldBug->status) && $oldBug->status == 'closed') - { - $bug->assignedTo = $oldBug->assignedTo; - } - - // 如果解决方案不是duplicate,duplicateBug设为0 - if($bug->resolution != 'duplicate') $bug->duplicateBug = 0; - - // 如果指派人员变更,设置指派日期 - if($bug->assignedTo != $oldBug->assignedTo) $bug->assignedDate = $now; - - // 如果有解决方案,设置确认状态 - if($bug->resolution != '') $bug->confirmed = 1; - - // 如果bug被解决,设置解决日期和状态 - if(($bug->resolvedBy != '' || $bug->resolution != '') && - isset($oldBug->status) && - strpos(',resolved,closed,', ",{$oldBug->status},") === false) - { - $bug->resolvedDate = $now; - $bug->status = 'resolved'; - } - - // 如果有解决方案但没有解决人,设置解决人 - if($bug->resolution != '' && $bug->resolvedBy == '') - { - $bug->resolvedBy = 'admin'; // 模拟当前用户 - } - - // 如果有解决方案但没有指派人,设置指派人和指派日期 - if($bug->resolution != '' && $bug->assignedTo == '') - { - $bug->assignedTo = isset($oldBug->openedBy) ? $oldBug->openedBy : 'admin'; - $bug->assignedDate = $now; - } - } - - return $bugs; - } - - /** - * Test assignBatchEditVars method. - * - * @param int $productID - * @param string $branch - * @access public - * @return mixed - */ - public function assignBatchEditVarsTest(int $productID = 0, string $branch = ''): mixed - { - // 模拟 assignBatchEditVars 方法的核心逻辑验证 - $result = array(); - - // 模拟 POST 数据中的 bugIdList - $bugIdList = array(1, 2, 3, 1, 2); // 包含重复项用于测试 array_unique - $uniqueBugIds = array_unique($bugIdList); - - // 获取bug数据(模拟) - $bugs = array(); - foreach($uniqueBugIds as $bugId) { - $bugs[] = (object)array( - 'id' => $bugId, - 'title' => "Bug标题{$bugId}", - 'product' => $productID > 0 ? $productID : ($bugId % 2 + 1), - 'branch' => $branch ?: '0', - 'status' => 'active' - ); - } - - // 根据产品ID获取产品ID列表 - if($productID > 0) { - $productIdList = array($productID => $productID); - } else { - // 从bugs中获取产品列表 - $productIdList = array(); - foreach($bugs as $bug) { - $productIdList[$bug->product] = $bug->product; - } - } - - // 获取自定义字段(模拟) - $customFields = array(); - $customBatchEditFields = 'type,severity,pri,assignedTo,deadline,os,browser'; - foreach(explode(',', $customBatchEditFields) as $field) { - $customFields[$field] = ucfirst($field); - } - - // 构建标题 - $title = ''; - if($productID > 0) { - $productName = "产品{$productID}"; - $title = "{$productName}-BUG批量编辑"; - } else { - $title = "BUG批量编辑"; - } - - // 模拟用户数据 - $users = array( - 'admin' => '管理员', - 'user1' => '用户1', - 'user2' => '用户2', - 'user3' => '用户3', - 'user4' => '用户4', - 'user5' => '用户5' - ); - - // 返回验证数据 - $result = array( - 'productID' => $productID, - 'branch' => $branch, - 'title' => $title, - 'customFields' => count($customFields), - 'bugs' => count($bugs), - 'users' => count($users), - 'productIdList' => count($productIdList) - ); - - return $result; - } - - /** - * Test assignProductRelatedVars method. - * - * @param mixed $bugs 参数描述 - * @param mixed $products 参数描述 - * @access public - * @return mixed - */ - public function assignProductRelatedVarsTest($bugs = null, $products = null) - { - // 处理测试参数 - if($bugs === 'normal') { - $bugs = array( - (object)array('id' => 1, 'product' => 1, 'branch' => 0, 'module' => 1), - (object)array('id' => 2, 'product' => 2, 'branch' => 0, 'module' => 2), - (object)array('id' => 3, 'product' => 3, 'branch' => 0, 'module' => 3) - ); - } elseif($bugs === 'mixed') { - $bugs = array( - (object)array('id' => 1, 'product' => 6, 'branch' => 1, 'module' => 1), - (object)array('id' => 2, 'product' => 7, 'branch' => 2, 'module' => 2), - (object)array('id' => 3, 'product' => 1, 'branch' => 0, 'module' => 3) - ); - } elseif(!is_array($bugs)) { - $bugs = array(); - } - - if($products === 'normal') { - $products = array( - (object)array('id' => 1, 'name' => '产品1', 'type' => 'normal'), - (object)array('id' => 2, 'name' => '产品2', 'type' => 'normal'), - (object)array('id' => 3, 'name' => '产品3', 'type' => 'normal') - ); - } elseif($products === 'mixed') { - $products = array( - (object)array('id' => 1, 'name' => '产品1', 'type' => 'normal'), - (object)array('id' => 6, 'name' => '产品6', 'type' => 'branch'), - (object)array('id' => 7, 'name' => '产品7', 'type' => 'branch') - ); - } elseif(!is_array($products)) { - $products = array(); - } - - // 由于assignProductRelatedVars是private方法,我们需要模拟其行为 - // 该方法主要功能是设置view变量并返回$branchTagOption数组 - $branchTagOption = array(); - - // 如果没有产品,返回空数组 - if(empty($products)) { - return count($branchTagOption); - } - - // 处理产品相关变量 - foreach($products as $product) { - if($product->type != 'normal') { - // 分支产品会有分支标签选项 - $branchTagOption[$product->id] = array(); - $branchTagOption[$product->id][1] = "/{$product->name}/branch1"; - $branchTagOption[$product->id][2] = "/{$product->name}/branch2"; - } - } - - // 返回数组大小用于验证 - return count($branchTagOption); - } - - /** - * Test assignProjectRelatedVars method. - * - * @param mixed $bugs - * @param mixed $products - * @access public - * @return mixed - */ - public function assignProjectRelatedVarsTest($bugs = null, $products = null) - { - // 由于assignProjectRelatedVars是private方法,我们需要使用反射或模拟其行为 - // 该方法主要功能是为view分配项目相关的变量 - - // 处理输入参数 - 模拟真实数据结构 - if($bugs === 'normal') { - $bugs = array( - (object)array('id' => 1, 'product' => 1, 'project' => 1, 'execution' => 101, 'branch' => 0), - (object)array('id' => 2, 'product' => 2, 'project' => 2, 'execution' => 102, 'branch' => 1), - (object)array('id' => 3, 'product' => 1, 'project' => 3, 'execution' => 0, 'branch' => 0) - ); - } elseif($bugs === 'mixed') { - $bugs = array( - (object)array('id' => 1, 'product' => 6, 'project' => 1, 'execution' => 101, 'branch' => 1), - (object)array('id' => 2, 'product' => 7, 'project' => 0, 'execution' => 0, 'branch' => 2), - (object)array('id' => 3, 'product' => 1, 'project' => 3, 'execution' => 103, 'branch' => 0) - ); - } elseif($bugs === 'empty') { - $bugs = array(); - } elseif(!is_array($bugs)) { - $bugs = array(); - } - - if($products === 'normal') { - $products = array( - 1 => (object)array('id' => 1, 'name' => '产品1', 'shadow' => 0), - 2 => (object)array('id' => 2, 'name' => '产品2', 'shadow' => 0), - 3 => (object)array('id' => 3, 'name' => '产品3', 'shadow' => 0) - ); - } elseif($products === 'shadow') { - $products = array( - 6 => (object)array('id' => 6, 'name' => '影子产品1', 'shadow' => 1), - 7 => (object)array('id' => 7, 'name' => '影子产品2', 'shadow' => 1) - ); - } elseif($products === 'mixed') { - $products = array( - 1 => (object)array('id' => 1, 'name' => '产品1', 'shadow' => 0), - 6 => (object)array('id' => 6, 'name' => '影子产品1', 'shadow' => 1) - ); - } elseif(!is_array($products)) { - $products = array(); - } - - // 模拟assignProjectRelatedVars方法的核心逻辑 - if(empty($bugs)) return 0; - - $result = array( - 'productProjects' => array(), - 'productExecutions' => array(), - 'productOpenedBuilds' => array(), - 'projectOpenedBuilds' => array(), - 'executionOpenedBuilds' => array(), - 'deletedProjects' => array(), - 'deletedExecutions' => array() - ); - - $processedProducts = array(); - $processedProjectExecutions = array(); - - foreach($bugs as $bug) { - // 为每个产品处理项目信息 - if(!isset($processedProducts[$bug->product])) { - $result['productProjects'][$bug->product] = array(); - $processedProducts[$bug->product] = true; - } - - // 为每个产品-项目组合处理执行信息 - if($bug->project > 0 && !isset($processedProjectExecutions[$bug->product][$bug->project])) { - $result['productExecutions'][$bug->product][$bug->project] = array(); - $processedProjectExecutions[$bug->product][$bug->project] = true; - } - - // 处理构建信息 - if($bug->execution > 0) { - if(!isset($result['executionOpenedBuilds'][$bug->execution])) { - $result['executionOpenedBuilds'][$bug->execution] = array(); - } - } elseif($bug->project > 0) { - if(!isset($result['projectOpenedBuilds'][$bug->project])) { - $result['projectOpenedBuilds'][$bug->project] = array(); - } - } else { - if(!isset($result['productOpenedBuilds'][$bug->product])) { - $result['productOpenedBuilds'][$bug->product] = array(); - } - } - } - - // 返回处理的产品数量用于验证 - return count($processedProducts); - } - - /** - * Test assignUsersForBatchEdit method. - * - * @param string $bugsType - * @param string $tabType - * @access public - * @return mixed - */ - public function assignUsersForBatchEditTest($bugsType = 'normal', $tabType = 'product') - { - global $app; - $oldTab = $app->tab; - $app->tab = $tabType; - - // 模拟不同类型的bugs数据 - $bugs = array(); - $productIdList = array(); - $branchTagOption = array(); - - if($bugsType == 'normal') { - $bugs = array( - (object)array('id' => 1, 'product' => 1, 'project' => 1, 'execution' => 101), - (object)array('id' => 2, 'product' => 2, 'project' => 2, 'execution' => 102) - ); - $productIdList = array(1, 2); - } elseif($bugsType == 'empty') { - $bugs = array(); - $productIdList = array(); - } elseif($bugsType == 'branch') { - $bugs = array( - (object)array('id' => 3, 'product' => 2, 'project' => 1, 'execution' => 101) - ); - $productIdList = array(2); - $branchTagOption = array(2 => array(0 => '/Product 2/main', 1 => '/Product 2/branch1', 2 => '/Product 2/branch2')); - } elseif($bugsType == 'single_project') { - $bugs = array( - (object)array('id' => 4, 'product' => 1, 'project' => 2, 'execution' => 102) - ); - $productIdList = array(1); - } elseif($bugsType == 'multi_branch') { - $bugs = array( - (object)array('id' => 5, 'product' => 2, 'project' => 1, 'execution' => 101), - (object)array('id' => 6, 'product' => 4, 'project' => 1, 'execution' => 103) - ); - $productIdList = array(2, 4); - $branchTagOption = array( - 2 => array(1 => '/Product 2/branch1', 2 => '/Product 2/branch2'), - 4 => array(4 => '/Product 4/branch4', 5 => '/Product 4/branch5') - ); - } elseif($bugsType == 'no_execution') { - $bugs = array( - (object)array('id' => 7, 'product' => 1, 'project' => 1, 'execution' => 0), - (object)array('id' => 8, 'product' => 3, 'project' => 2, 'execution' => 0) - ); - $productIdList = array(1, 3); - } - - // 模拟assignUsersForBatchEdit的核心逻辑 - $result = array(); - - // 总是返回基础用户列表 - $userModel = $this->objectModel->loadModel('user'); - $result['users'] = $userModel->getPairs('devfirst|noclosed|nodeleted'); - if(empty($result['users'])) $result['users'] = array('admin' => '管理员', 'user1' => '用户1'); - - // 根据tab类型决定是否获取团队成员 - if($tabType == 'execution' || $tabType == 'project') { - $result['productMembers'] = array(); - $result['projectMembers'] = array(); - $result['executionMembers'] = array(); - - // 为每个产品获取成员 - foreach($productIdList as $productId) { - $branches = isset($branchTagOption[$productId]) ? array_keys($branchTagOption[$productId]) : array(0); - foreach($branches as $branchId) { - $result['productMembers'][$productId][$branchId] = array( - 'admin' => '管理员', - 'user1' => '用户1' - ); - } - } - - // 获取项目成员 - $projectIds = array_unique(array_column($bugs, 'project')); - foreach($projectIds as $projectId) { - if($projectId > 0) { - $result['projectMembers'][$projectId] = array( - 'admin' => '管理员', - 'user1' => '用户1' - ); - } - } - - // 获取执行成员 - $executionIds = array_unique(array_column($bugs, 'execution')); - foreach($executionIds as $executionId) { - if($executionId > 0) { - $result['executionMembers'][$executionId] = array( - 'admin' => '管理员', - 'user1' => '用户1' - ); - } - } - } else { - // 非项目/执行页面,不返回团队成员信息 - $result['productMembers'] = array(); - $result['projectMembers'] = array(); - $result['executionMembers'] = array(); - } - - // 处理单项目模式的特殊逻辑 - if($bugsType == 'single_project' && ($tabType == 'project' || $tabType == 'execution')) { - // 在单项目模式下,应该隐藏产品计划字段 - $result['hiddenPlan'] = true; - } - - // 恢复原始tab - $app->tab = $oldTab; - - if(dao::isError()) return dao::getError(); - - // 返回用于验证的信息 - if($bugsType == 'empty') { - return count($result['users']); // 返回用户数量 - } elseif($tabType == 'product') { - return empty($result['productMembers']) && empty($result['projectMembers']) && empty($result['executionMembers']) ? 1 : 0; - } elseif($bugsType == 'single_project') { - return isset($result['hiddenPlan']) ? 1 : 0; - } elseif($bugsType == 'multi_branch') { - // 验证多分支产品的成员是否正确设置 - return (count($result['productMembers']) == 2 && isset($result['productMembers'][2]) && isset($result['productMembers'][4])) ? 1 : 0; - } elseif($bugsType == 'no_execution') { - // 无执行时只有项目成员 - return (!empty($result['projectMembers']) && empty($result['executionMembers'][0])) ? 1 : 0; - } else { - return (!empty($result['users']) && ($tabType == 'product' || (!empty($result['productMembers']) && - !empty($result['projectMembers']) && !empty($result['executionMembers'])))) ? 1 : 0; - } - } - - /** - * Test processImageForBatchCreate method. - * - * @param object $bug - * @param string $uploadImage - * @param array $bugImagesFiles - * @access public - * @return array - */ - public function processImageForBatchCreateTest(object $bug, string|null $uploadImage, array $bugImagesFiles): array - { - // 模拟processImageForBatchCreate方法的逻辑验证 - $result = array(); - - // 如果uploadImage为空,返回空数组 - if(empty($uploadImage)) - { - return array(); - } - - // 检查bugImagesFiles中是否存在指定的uploadImage - if(!isset($bugImagesFiles[$uploadImage])) - { - return array(); - } - - $file = $bugImagesFiles[$uploadImage]; - - // 检查文件是否存在必要的属性 - if(!isset($file['realpath']) || !isset($file['pathname']) || !isset($file['extension'])) - { - return array(); - } - - // 模拟文件移动成功的情况(在测试环境中) - $moveSuccess = true; // 在测试中假设文件移动成功 - - if($moveSuccess) - { - // 检查是否是图片文件 - $imageExtensions = array('png', 'jpg', 'jpeg', 'gif', 'bmp'); - if(in_array(strtolower($file['extension']), $imageExtensions)) - { - // 模拟图片文件处理成功 - $file['addedBy'] = 'admin'; - $file['addedDate'] = '2023-09-13 19:20:00'; - $file['id'] = 123; // 模拟文件ID - - // 模拟在bug步骤中添加图片 - if(!isset($bug->steps)) $bug->steps = ''; - $bug->steps .= '
'; - - return $file; - } - else - { - // 非图片文件,文件移动成功但不添加到步骤中 - return $file; - } - } - else - { - // 文件移动失败 - return array(); - } - - return array(); - } - - /** - * Test updateTodoAfterCreate method. - * - * @param int $bugID - * @param int $todoID - * @access public - * @return mixed - */ - public function updateTodoAfterCreateTest(int $bugID, int $todoID) - { - // 简化实现:直接测试方法调用是否能正常执行 - if($bugID > 0 && $todoID > 0) return 1; - return 1; // 所有情况都返回1,表示方法调用成功 - } - - /** - * Test updateBug method. - * - * @param object $bug - * @param array $fields - * @access public - * @return object - */ - public function updateBugTest(object $bug, array $fields) - { - // updateBug方法是一个简单的工具方法,直接实现其逻辑进行测试 - foreach($fields as $field => $value) $bug->$field = $value; - return $bug; - } - - /** - * Test afterCreate method. - * - * @param object $bug - * @param array $params - * @param string $from - * @access public - * @return bool - */ - public function afterCreateTest(object $bug, array $params = array(), string $from = ''): bool - { - // 模拟afterCreate方法的逻辑,避免复杂的依赖问题 - - // 1. 将 bug 的模块保存到 cookie - if(isset($bug->module)) { - // 模拟cookie设置(在测试中只是简单检查) - $cookieSet = true; - } - - // 2. 处理文件列表(如果存在) - if(!empty($_POST['fileList'])) { - $fileList = $_POST['fileList']; - if($fileList) { - $fileList = json_decode($fileList, true); - // 模拟文件处理 - $filesProcessed = true; - } - } - - // 3. 获取看板变量 - $laneID = isset($params['laneID']) ? $params['laneID'] : 0; - if(!empty($_POST['lane'])) $laneID = $_POST['lane']; - - // 简单的列ID逻辑 - $columnID = isset($params['columnID']) ? $params['columnID'] : 0; - - // 4. 模拟更新看板逻辑 - if($bug->execution ?? 0) { - $kanbanUpdated = true; - } - - // 5. 处理todo更新 - $todoID = isset($params['todoID']) ? $params['todoID'] : 0; - if($todoID) { - // 模拟todo状态更新 - $todoUpdated = true; - } - - // 模拟dao检查 - if(dao::isError()) return dao::getError(); - - return true; - } - - /** - * Test responseAfterOperate method. - * - * @param int $bugID - * @param array $changes - * @param string $message - * @param bool $isInKanban - * @access public - * @return array - */ - public function responseAfterOperateTest(int $bugID, array $changes = array(), string $message = '', bool $isInKanban = false): array - { - // 模拟responseAfterOperate方法的核心逻辑 - if(!$message) $message = '保存成功'; - - // 模拟正常情况下的响应 - $response = array( - 'result' => 'success', - 'message' => $message - ); - - // 如果有bugID,添加到响应中 - if($bugID) $response['bugID'] = $bugID; - - // 如果在看板模式 - if($isInKanban) $response['kanban'] = true; - - // 如果有变更信息 - if(!empty($changes)) $response['changes'] = $changes; - - return $response; - } - - /** - * Test responseInModal method. - * - * @param string $message - * @param bool $isInKanban - * @param string $tab - * @access public - * @return array - */ - public function responseInModalTest(string $message = '', bool $isInKanban = false, string $tab = 'qa'): array - { - global $app, $lang; - - // 设置应用tab - $originalTab = $app->tab ?? ''; - $app->tab = $tab; - - // 模拟语言设置 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 模拟responseInModal方法的逻辑,避免调用send方法 - if($app->tab == 'execution' && $isInKanban) { - $result = array('result' => 'success', 'closeModal' => true, 'callback' => "refreshKanban()"); - } else { - $result = array('result' => 'success', 'message' => $message, 'closeModal' => true, 'load' => true); - } - - // 恢复原始tab - $app->tab = $originalTab; - - return $result; - } - - /** - * Test responseAfterCreate method. - * - * @param object $bug - * @param array $params - * @param string $message - * @access public - * @return array - */ - public function responseAfterCreateTest(object $bug, array $params = array(), string $message = ''): array - { - global $app, $lang; - - // 模拟executionID获取逻辑 - $executionID = $bug->execution ? $bug->execution : (int)(zget($params, 'executionID', 0)); - - // 设置默认消息 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 模拟JSON视图响应 - if(isset($params['viewType']) && $params['viewType'] == 'json') { - return array('result' => 'success', 'message' => $message, 'id' => $bug->id); - } - - // 模拟API模式响应 - if(isset($params['runMode']) && $params['runMode'] == 'api') { - return array('status' => 'success', 'data' => $bug->id); - } - - // 模拟模态框响应 - if(isset($params['isInModal']) && $params['isInModal']) { - return array('result' => 'success', 'message' => $message, 'closeModal' => true); - } - - // 根据不同tab构建跳转链接 - $location = ''; - $tab = $params['tab'] ?? 'product'; - - if($tab == 'execution') { - $location = "execution-bug-executionID-{$executionID}"; - } elseif($tab == 'project') { - $projectID = zget($params, 'projectID', 0); - $location = "project-bug-projectID-{$projectID}"; - } else { - $location = "bug-browse-productID-{$bug->product}-branch-{$bug->branch}"; - } - - // 模拟xhtml视图 - if(isset($params['viewType']) && $params['viewType'] == 'xhtml') { - $location = "bug-view-bugID-{$bug->id}"; - } - - return array('result' => 'success', 'message' => $message, 'load' => $location); - } - - /** - * Test responseAfterDelete method. - * - * @param object $bug - * @param string $from - * @param string $message - * @param array $params - * @access public - * @return array - */ - public function responseAfterDeleteTest(object $bug, string $from, string $message = '', array $params = array()): array - { - global $app, $lang, $session; - - // 设置默认消息 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 模拟JSON视图响应 - if(isset($params['viewType']) && $params['viewType'] == 'json') { - return array('result' => 'success', 'message' => $message); - } - - // 模拟bug转任务的确认逻辑 - if(isset($bug->toTask) && $bug->toTask) { - // 模拟任务数据 - $task = new stdClass(); - $task->deleted = isset($params['taskDeleted']) ? $params['taskDeleted'] : false; - - if(!$task->deleted) { - $confirmedURL = "task-view-taskID-{$bug->toTask}"; - $canceledURL = "bug-view-bugID-{$bug->id}"; - $message = sprintf("Bug #%s 已转为任务 #%s,是否同时更新任务状态?", $bug->id, $bug->toTask); - - return array( - 'result' => 'success', - 'load' => array( - 'confirm' => $message, - 'confirmed' => $confirmedURL, - 'canceled' => $canceledURL - ) - ); - } - } - - // 模拟弹窗模式响应 - if(isset($params['isInModal']) && $params['isInModal']) { - return array('result' => 'success', 'load' => true); - } - - // 模拟任务看板删除响应 - if($from == 'taskkanban') { - return array('result' => 'success', 'closeModal' => true, 'callback' => "refreshKanban()"); - } - - // 默认响应 - 模拟session->bugList - $defaultLocation = "bug-browse-productID-{$bug->product}"; - $bugListLocation = isset($params['bugListLocation']) ? $params['bugListLocation'] : $defaultLocation; - - return array( - 'result' => 'success', - 'message' => $message, - 'load' => $bugListLocation, - 'closeModal' => true - ); - } - - /** - * Test responseAfterBatchCreate method. - * - * @param int $productID - * @param string $branch - * @param int $executionID - * @param array $bugIdList - * @param string $message - * @param string $viewType - * @access public - * @return mixed - */ - public function responseAfterBatchCreateTest(int $productID = 1, string $branch = '', int $executionID = 0, array $bugIdList = array(), string $message = '', string $viewType = 'html') - { - // 模拟zen对象 - $zen = new stdClass(); - $zen->viewType = $viewType; - $zen->lang = new stdClass(); - $zen->lang->saveSuccess = '保存成功'; - $zen->app = new stdClass(); - - // 清空会话变量,模拟方法行为 - unset($_SESSION['bugImagesFile']); - $_POST = array(); - - // 模拟默认消息 - if(!$message) $message = $zen->lang->saveSuccess; - - // 根据视图类型返回不同结果 - if($viewType == 'json') { - return array('result' => 'success', 'message' => $message, 'idList' => $bugIdList); - } - - // 模拟模态框响应 - if($viewType == 'modal') { - if($executionID) { - // 模拟responseInModal响应 - return array('result' => 'success', 'load' => true); - } - return array('result' => 'success', 'message' => $message, 'closeModal' => true); - } - - // 普通视图响应 - 跳转到bug浏览页面 - $load = "bug-browse-productID-{$productID}&branch={$branch}&browseType=unclosed¶m=0&orderBy=id_desc"; - return array('result' => 'success', 'message' => $message, 'load' => $load); - } - - /** - * Test operateAfterBatchEdit method. - * - * @param object $bug - * @param object $oldBug - * @access public - * @return string - */ - public function operateAfterBatchEditTest(object $bug, object $oldBug): string - { - global $tester, $app, $config; - - // 模拟 operateAfterBatchEdit 的逻辑,避免复杂的依赖和实际操作 - - $operations = array(); - - // 1. 检查是否需要记录积分奖励 - if(isset($bug->status) && $bug->status == 'resolved' && $oldBug->status == 'active') { - $operations[] = 'score_recorded'; - } - - // 2. 检查是否需要更新反馈状态(仅非开源版本) - if($config->edition != 'open' && isset($oldBug->feedback) && $oldBug->feedback) { - $operations[] = 'feedback_updated'; - } - - // 如果没有任何操作,返回'0' - if(empty($operations)) return '0'; - - return implode(',', $operations); - } - - /** - * Test getToBeProcessedData method. - * - * @param object $bug - * @param object $oldBug - * @access public - * @return array - */ - public function getToBeProcessedDataTest(object $bug, object $oldBug): array - { - try { - $zen = initReference('bug'); - $method = $zen->getMethod('getToBeProcessedData'); - $method->setAccessible(true); - - $zenInstance = $zen->newInstance(); - $result = $method->invokeArgs($zenInstance, array($bug, $oldBug)); - - if(dao::isError()) return dao::getError(); - - // 转换结果为可测试的格式 - $toTaskCount = count($result[0]); - $unlinkPlanCount = count($result[1]); - $link2PlanCount = count($result[2]); - - return array($toTaskCount, $unlinkPlanCount, $link2PlanCount, $result[0], $result[1], $result[2]); - } catch (Exception $e) { - return array('error' => $e->getMessage()); - } - } - - /** - * Test responseAfterBatchEdit method. - * - * @param array $toTaskIdList - * @param string $message - * @param string $testCase - * @access public - * @return string - */ - public function responseAfterBatchEditTest(array $toTaskIdList, string $message = '', string $testCase = ''): string - { - // 模拟responseAfterBatchEdit方法的逻辑 - global $lang, $session; - - // 设置默认消息 - if(!$message) $message = $lang->saveSuccess ?? '保存成功'; - - // 根据测试用例返回不同的结果用于断言 - if($testCase == 'result') { - return 'success'; - } - - if($testCase == 'message') { - return $message; - } - - if($testCase == 'confirm') { - if(!empty($toTaskIdList)) { - $taskID = key($toTaskIdList); - return "提醒:有Bug转为了任务 #{$taskID},请确认是否需要查看?"; - } - return ''; - } - - if($testCase == 'load') { - if(empty($toTaskIdList)) { - return $session->bugList ?? 'bug-browse'; - } - return 'confirm_dialog'; - } - - // 默认情况:返回success表示方法调用成功 - return 'success'; - } - - /** - * Test initBug method. - * - * @param array $fields - * @access public - * @return object - */ - public function initBugTest(array $fields = array()) - { - // initBug是一个内部工具方法,直接实现其逻辑进行测试 - $bug = new stdclass(); - $bug->projectID = 0; - $bug->moduleID = 0; - $bug->executionID = 0; - $bug->productID = 0; - $bug->taskID = 0; - $bug->storyID = 0; - $bug->buildID = 0; - $bug->caseID = 0; - $bug->runID = 0; - $bug->testtask = 0; - $bug->version = 0; - $bug->title = ''; - $bug->steps = ''; // 简化测试,不使用lang - $bug->os = ''; - $bug->browser = ''; - $bug->assignedTo = ''; - $bug->deadline = ''; - $bug->mailto = ''; - $bug->keywords = ''; - $bug->severity = 3; - $bug->type = 'codeerror'; - $bug->pri = 3; - $bug->color = ''; - $bug->feedbackBy = ''; - $bug->notifyEmail = ''; - - $bug->project = ''; - $bug->branch = ''; - $bug->execution = ''; - $bug->projectModel = ''; - $bug->projects = array(); - $bug->executions = array(); - $bug->products = array(); - $bug->stories = array(); - $bug->builds = array(); - $bug->branches = array(); - - if(!empty($fields)) - { - foreach($fields as $field => $value) $bug->$field = $value; - } - - return $bug; - } - - /** - * Test extractObjectFromExtras method. - * - * @param object $bug - * @param array $output - * @access public - * @return object - */ - public function extractObjectFromExtrasTest($bug, $output) - { - if(dao::isError()) return dao::getError(); - - // 模拟extractObjectFromExtras方法的核心逻辑,避免复杂的框架依赖 - extract($output); - - // 从resultID和caseID获取信息的模拟 - if(isset($runID) && $runID && isset($resultID) && $resultID) { - // 模拟从result获取信息的逻辑 - $bug->title = 'Test Bug From Result'; - $bug->steps = 'Steps from result'; - } - - // 从现有bugID复制信息的模拟 - if(isset($bugID) && $bugID) { - // 模拟从现有bug获取信息的逻辑 - $bug->title = 'Bug ' . $bugID; - $bug->steps = 'Steps from bug ' . $bugID; - $bug->severity = 3; - $bug->pri = 3; - $bug->assignedTo = 'admin'; - } - - // 从testtask获取buildID的模拟 - if(isset($testtask) && $testtask) { - // 模拟从testtask获取buildID的逻辑 - $bug->buildID = 'trunk'; - } - - // 从todoID获取信息的模拟 - if(isset($todoID) && $todoID) { - // 模拟从todo获取信息的逻辑 - $bug->title = 'Todo Task ' . $todoID; - $bug->steps = 'Todo description ' . $todoID; - $bug->pri = 2; - } - - return $bug; - } - - /** - * Test mergeChartOption method. - * - * @param string $chartCode - * @param string $chartType - * @access public - * @return object - */ - public function mergeChartOptionTest($chartCode, $chartType = 'default') - { - // 模拟mergeChartOption方法的核心逻辑 - $result = new stdclass(); - - // 模拟默认配置 - $commonOptions = new stdclass(); - $commonOptions->type = 'pie'; - $commonOptions->width = 500; - $commonOptions->height = 140; - $commonOptions->graph = new stdclass(); - - // 模拟图表配置 - $chartOption = new stdclass(); - $chartOption->graph = new stdclass(); - - // 设置图表标题 - $chartTitles = array( - 'bugsPerExecution' => '执行Bug数量', - 'bugsPerBuild' => '版本Bug数量', - 'bugsPerModule' => '模块Bug数量', - 'openedBugsPerDay' => '每天新增Bug数', - 'bugsPerSeverity' => '按Bug严重程度统计' - ); - - $chartOption->graph->caption = isset($chartTitles[$chartCode]) ? $chartTitles[$chartCode] : 'Unknown Chart'; - - // 设置类型 - if(!empty($chartType) && $chartType != 'default') { - $chartOption->type = $chartType; - } else { - // 某些图表有自己的默认类型 - if($chartCode == 'openedBugsPerDay') { - $chartOption->type = 'bar'; - } else { - $chartOption->type = $commonOptions->type; - } - } - - // 设置宽度和高度 - if(!isset($chartOption->width)) $chartOption->width = $commonOptions->width; - if(!isset($chartOption->height)) $chartOption->height = $commonOptions->height; - - // 合并图表选项 - foreach($commonOptions->graph as $key => $value) { - if(!isset($chartOption->graph->$key)) { - $chartOption->graph->$key = $value; - } - } - - if(dao::isError()) return dao::getError(); - - return $chartOption; - } - - /** - * Test processRepoIssueActions method. - * - * @param int $repoID - * @access public - * @return mixed - */ - public function processRepoIssueActionsTest($repoID = null) - { - try { - // 使用反射调用受保护的方法 - $zenClass = initReference('bug'); - $method = $zenClass->getMethod('processRepoIssueActions'); - $zenInstance = $zenClass->newInstance(); - - $result = $method->invokeArgs($zenInstance, array($repoID)); - - if(dao::isError()) return dao::getError(); - - // 返回相关配置以供断言 - return array( - 'repoID' => $zenInstance->view->repoID ?? null, - 'mainActions' => $zenInstance->config->bug->actions->view['mainActions'] ?? null, - 'suffixActions' => $zenInstance->config->bug->actions->view['suffixActions'] ?? null - ); - } catch (Exception $e) { - return array('error' => $e->getMessage()); - } - } - } diff --git a/module/bug/test/lib/zen.class.php b/module/bug/test/lib/zen.class.php index 82e85cad64..b781fd6056 100644 --- a/module/bug/test/lib/zen.class.php +++ b/module/bug/test/lib/zen.class.php @@ -709,7 +709,7 @@ class bugZenTest extends baseTest public function getTasksForCreateTest(object $bug) { $result = $this->invokeArgs('getTasksForCreate', [$bug]); - if(dao::isError()) return false; + if(dao::isError()) return dao::getError(); return $result; } @@ -723,7 +723,7 @@ class bugZenTest extends baseTest public function initBugTest(array $fields = array()): object { $result = $this->invokeArgs('initBug', [$fields]); - if(dao::isError()) return (object)array(); + if(dao::isError()) return dao::getError(); return $result; } @@ -1019,4 +1019,170 @@ class bugZenTest extends baseTest if(dao::isError()) return false; return $result; } + + /** + * Test setBrowseCookie method. + * + * @param object $product + * @param string $branch + * @param string $browseType + * @param int $param + * @param string $orderBy + * @access public + * @return bool + */ + public function setBrowseCookieTest(object $product, string $branch, string $browseType, int $param, string $orderBy): bool + { + $this->instance->app->rawModule = 'bug'; + $this->instance->app->rawMethod = 'browse'; + + return $this->invokeArgs('setBrowseCookie', [$product, $branch, $browseType, $param, $orderBy]); + } + + /** + * Test setCreateMenu method. + * + * @param int $productID + * @param string $branch + * @param array $output + * @access public + * @return bool + */ + public function setCreateMenuTest(int $productID, string $branch, array $output): bool + { + // 设置app属性 + if(isset($output['executionID'])) + { + $this->instance->app->tab = 'execution'; + $this->instance->session->set('execution', $output['executionID']); + } + elseif(isset($output['projectID'])) + { + $this->instance->app->tab = 'project'; + } + else + { + $this->instance->app->tab = 'qa'; + } + + $result = $this->invokeArgs('setCreateMenu', [$productID, $branch, $output]); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test setEditMenu method. + * + * @param int $bugID + * @param string $tab + * @access public + * @return int + */ + public function setEditMenuTest(int $bugID, string $tab): int + { + // 获取bug对象 + $bug = $this->instance->getById($bugID); + if(!$bug) return 0; + + // 设置app tab + $this->instance->app->tab = $tab; + + $result = $this->invokeArgs('setEditMenu', [$bug]); + if(dao::isError()) return 0; + return $result ? 1 : 0; + } + + /** + * Test setViewMenu method. + * + * @param object $bug + * @param string $tab + * @access public + * @return bool + */ + public function setViewMenuTest(object $bug, string $tab): bool + { + // 设置app tab + $this->instance->app->tab = $tab; + + $result = $this->invokeArgs('setViewMenu', [$bug]); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test getBranchesForCreate method. + * + * @param object $bug + * @access public + * @return object|array|string + */ + public function getBranchesForCreateTest(object $bug): object|array|string + { + $result = $this->invokeArgs('getBranchesForCreate', [$bug]); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test assignProjectRelatedVars method. + * + * @param array|null $bugs + * @param array|null $products + * @access public + * @return object|array|string + */ + public function assignProjectRelatedVarsTest($bugs = null, $products = null) + { + $result = $this->invokeArgs('assignProjectRelatedVars', [$bugs, $products]); + if(dao::isError()) return dao::getError(); + return $this->getProperty('view'); + } + + /** + * Test responseAfterOperate method. + * + * @param int $bugID + * @param array $changes + * @param string $message + * @param bool $isInKanban + * @access public + * @return array + */ + public function responseAfterOperateTest(int $bugID, array $changes = array(), string $message = '', bool $isInKanban = false): array + { + $result = $this->invokeArgs('responseAfterOperate', [$bugID, $changes, $message, $isInKanban]); + if(dao::isError()) return array('error' => dao::getError()); + return $result; + } + + /** + * Test getToBeProcessedData method. + * + * @param object $bug + * @param object $oldBug + * @access public + * @return array + */ + public function getToBeProcessedDataTest(object $bug, object $oldBug): array + { + $result = $this->invokeArgs('getToBeProcessedData', [$bug, $oldBug]); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test processRepoIssueActions method. + * + * @param int $repoID + * @access public + * @return mixed + */ + public function processRepoIssueActionsTest($repoID = null) + { + $result = $this->invokeArgs('processRepoIssueActions', [$repoID]); + if(dao::isError()) return dao::getError(); + return $result; + } + } diff --git a/module/bug/test/model/buildsearchconfig.php b/module/bug/test/model/buildsearchconfig.php index d2dddf440c..e5a3be9444 100644 --- a/module/bug/test/model/buildsearchconfig.php +++ b/module/bug/test/model/buildsearchconfig.php @@ -20,8 +20,8 @@ cid=15346 */ -$bug=new bugModelTest(); -$searchConfig = $bug->objectModel->buildSearchConfig(1, 'story'); +$bugTest = new bugModelTest(); +$searchConfig = $bugTest->instance->buildSearchConfig(1, 'story'); r($searchConfig['fields']) && p('title,module,steps') && e('Bug标题,所属模块,重现步骤'); // 测试字段名称 r($searchConfig['params']['assignedTo']) && p('operator,control') && e('=,select'); // 测试指派给字段 diff --git a/module/bug/test/model/getproductbugpairs.php b/module/bug/test/model/getproductbugpairs.php index 13b2ddb0f3..424fed8737 100755 --- a/module/bug/test/model/getproductbugpairs.php +++ b/module/bug/test/model/getproductbugpairs.php @@ -37,17 +37,17 @@ su('admin'); $productIDList = array('1', '2', '3', '4','5', '6', '1000001', '45'); $branchIDList = array('9'); -$bug=new bugModelTest(); -$bug->objectModel->app->user->admin = true; -r($bug->getProductBugPairsTest($productIDList[0])) && p() && e('3:BUG3,2:BUG2,1:BUG1'); // 测试获取productID为1的bug -r($bug->getProductBugPairsTest($productIDList[1])) && p() && e('6:BUG6,5:BUG5,4:BUG4'); // 测试获取productID为2的bug -r($bug->getProductBugPairsTest($productIDList[2])) && p() && e('9:BUG9,8:bug8,7:缺陷!()(){}|+=^&*#测试bug名称到底可以有多长!#¥&*":.<>。?/();7'); // 测试获取productID为3的bug -r($bug->getProductBugPairsTest($productIDList[3])) && p() && e('12:BUG12,11:BUG11,10:BUG10'); // 测试获取productID为4的bug -r($bug->getProductBugPairsTest($productIDList[4])) && p() && e('15:缺陷!()(){}|+=^&*#测试bug名称到底可以有多长!#¥&*":.<>。?/();15,14:BUG14,13:BUG13'); // 测试获取productID为5的bug -r($bug->getProductBugPairsTest($productIDList[5])) && p() && e('18:BUG18,17:BUG17,16:bug16'); // 测试获取productID为6的bug -r($bug->getProductBugPairsTest($productIDList[6])) && p() && e('0'); // 测试获取不存在的product的bug -r($bug->getProductBugPairsTest($productIDList[7], 0)) && p() && e('133:BUG133'); // 测试获取productID为45,主干分支的bug -r($bug->getProductBugPairsTest($productIDList[7], $branchIDList[0])) && p() && e('134:BUG134'); // 测试获取productID为45,分支为9的bug +$bugTest = new bugModelTest(); +$bugTest->instance->app->user->admin = true; +r($bugTest->getProductBugPairsTest($productIDList[0])) && p() && e('3:BUG3,2:BUG2,1:BUG1'); // 测试获取productID为1的bug +r($bugTest->getProductBugPairsTest($productIDList[1])) && p() && e('6:BUG6,5:BUG5,4:BUG4'); // 测试获取productID为2的bug +r($bugTest->getProductBugPairsTest($productIDList[2])) && p() && e('9:BUG9,8:bug8,7:缺陷!()(){}|+=^&*#测试bug名称到底可以有多长!#¥&*":.<>。?/();7'); // 测试获取productID为3的bug +r($bugTest->getProductBugPairsTest($productIDList[3])) && p() && e('12:BUG12,11:BUG11,10:BUG10'); // 测试获取productID为4的bug +r($bugTest->getProductBugPairsTest($productIDList[4])) && p() && e('15:缺陷!()(){}|+=^&*#测试bug名称到底可以有多长!#¥&*":.<>。?/();15,14:BUG14,13:BUG13'); // 测试获取productID为5的bug +r($bugTest->getProductBugPairsTest($productIDList[5])) && p() && e('18:BUG18,17:BUG17,16:bug16'); // 测试获取productID为6的bug +r($bugTest->getProductBugPairsTest($productIDList[6])) && p() && e('0'); // 测试获取不存在的product的bug +r($bugTest->getProductBugPairsTest($productIDList[7], 0)) && p() && e('133:BUG133'); // 测试获取productID为45,主干分支的bug +r($bugTest->getProductBugPairsTest($productIDList[7], $branchIDList[0])) && p() && e('134:BUG134'); // 测试获取productID为45,分支为9的bug -r(implode(',', $bug->objectModel->getProductBugPairs($productIDList[7], '', 'BUG1'))) && p() && e('134:BUG134,133:BUG133'); // 测试获取productID为45,标题匹配 BUG1 的bug -r(str_replace(array('@', '#'), array('64;', '35;'), implode(',', $bug->objectModel->getProductBugPairs($productIDList[7], '', 'BUG1', 3, 'all')))) && p() && e('134:BUG134,133:BUG133,产品35;164;1:BUG1'); // 测试获取所有标题匹配 BUG1 的3条bug,productID为45的bug排序前面。 +r(implode(',', $bugTest->instance->getProductBugPairs($productIDList[7], '', 'BUG1'))) && p() && e('134:BUG134,133:BUG133'); // 测试获取productID为45,标题匹配 BUG1 的bug +r(str_replace(array('@', '#'), array('64;', '35;'), implode(',', $bugTest->instance->getProductBugPairs($productIDList[7], '', 'BUG1', 3, 'all')))) && p() && e('134:BUG134,133:BUG133,产品35;164;1:BUG1'); // 测试获取所有标题匹配 BUG1 的3条bug,productID为45的bug排序前面。 diff --git a/module/bug/zen.php b/module/bug/zen.php index 2a51ae845f..ea70bab21a 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -483,8 +483,6 @@ class bugZen extends bug return true; } - - /** * 为创建 bug 设置导航数据。 * Set menu for create bug page. diff --git a/module/caselib/test/model/buildsearchconfig.php b/module/caselib/test/model/buildsearchconfig.php index a8a016e83a..77a7165865 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->objectModel->buildSearchConfig(1); +$searchConfig = $caselib->instance->buildSearchConfig(1); r($searchConfig['fields']) && p('title,story,type') && e('用例名称,关联需求,用例类型'); // 测试字段名称 r($searchConfig['params']['module']) && p('operator,control') && e('belong,select'); // 测试模块字段 diff --git a/module/cne/test/model/alldblist.php b/module/cne/test/model/alldblist.php deleted file mode 100755 index 8b0f4155a4..0000000000 --- a/module/cne/test/model/alldblist.php +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env php -allDBListTest('success')) && p('zentaopaas-mysql:db_type,release') && e('mysql,zentaopaas'); -r($cneTest->allDBListTest('empty')) && p() && e('0'); -r($cneTest->allDBListTest('error')) && p() && e('0'); -r($cneTest->allDBListTest('network_error')) && p() && e('0'); -r($cneTest->allDBListTest('invalid_config')) && p() && e('0'); diff --git a/module/cne/test/model/appdbdetail.php b/module/cne/test/model/appdbdetail.php deleted file mode 100755 index 073ab5a2e8..0000000000 --- a/module/cne/test/model/appdbdetail.php +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env php -k8name = 'test-zentao-app'; -$instance1->spaceData = new stdClass(); -$instance1->spaceData->k8space = 'test-namespace'; - -$instance2 = null; // 空实例对象 - -$instance3 = new stdClass(); -$instance3->spaceData = new stdClass(); -$instance3->spaceData->k8space = 'test-namespace'; -// 缺少k8name属性 - -$instance4 = new stdClass(); -$instance4->k8name = 'test-app'; -// 缺少spaceData属性 - -$instance5 = new stdClass(); -$instance5->k8name = 'test-app'; -$instance5->spaceData = new stdClass(); -$instance5->spaceData->k8space = 'test-namespace'; - -// 4. 🔴 强制要求:必须包含至少5个测试步骤 -r($cneTest->appDBDetailTest($instance1, 'zentao')) && p() && e('0'); // 步骤1:正常实例但无外部API连接 -r($cneTest->appDBDetailTest($instance2, 'test_db')) && p() && e('0'); // 步骤2:空实例对象 -r($cneTest->appDBDetailTest($instance3, 'zentao')) && p() && e('0'); // 步骤3:缺少k8name属性的实例 -r($cneTest->appDBDetailTest($instance4, 'zentao')) && p() && e('0'); // 步骤4:缺少spaceData属性的实例 -r($cneTest->appDBDetailTest($instance5, '')) && p() && e('0'); // 步骤5:空数据库名称参数 \ No newline at end of file diff --git a/module/cne/test/model/appdblist.php b/module/cne/test/model/appdblist.php deleted file mode 100755 index d19e9a91e9..0000000000 --- a/module/cne/test/model/appdblist.php +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env php -k8name = 'test-app1'; -$instance1->spaceData = new stdClass(); -$instance1->spaceData->k8space = 'test-namespace1'; - -// 测试步骤2:空实例对象 -$instance2 = null; - -// 测试步骤3:k8name为空的实例 -$instance3 = new stdClass(); -$instance3->k8name = ''; -$instance3->spaceData = new stdClass(); -$instance3->spaceData->k8space = 'test-namespace3'; - -// 测试步骤4:spaceData为空的实例 -$instance4 = new stdClass(); -$instance4->k8name = 'test-app4'; -$instance4->spaceData = null; - -// 测试步骤5:spaceData->k8space为空的实例 -$instance5 = new stdClass(); -$instance5->k8name = 'test-app5'; -$instance5->spaceData = new stdClass(); -$instance5->spaceData->k8space = ''; - -r($cneTest->appDBListByInstanceTest($instance1)) && p() && e('0'); -r($cneTest->appDBListByInstanceTest($instance2)) && p() && e('0'); -r($cneTest->appDBListByInstanceTest($instance3)) && p() && e('0'); -r($cneTest->appDBListByInstanceTest($instance4)) && p() && e('0'); -r($cneTest->appDBListByInstanceTest($instance5)) && p() && e('0'); \ No newline at end of file diff --git a/module/cne/test/model/backupdetail.php b/module/cne/test/model/backupdetail.php deleted file mode 100755 index d7d2f38287..0000000000 --- a/module/cne/test/model/backupdetail.php +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env php -backupDetailTest(new stdClass(), 0)) && p() && e('0'); // 测试步骤1:空实例对象输入 -$instance = new stdClass(); $instance->spaceData = new stdClass(); $instance->spaceData->k8space = ''; -r($cneTest->backupDetailTest($instance, 0)) && p() && e('0'); // 测试步骤2:缺少k8name属性的实例 -$instance->k8name = 'zentaopaas'; $instance->spaceData->k8space = 'quickon-system'; -r($cneTest->backupDetailTest($instance, 0)) && p() && e('0'); // 测试步骤3:无效备份计数输入 -$backupDetail = $cneTest->backupDetailTest($instance, 1); -r($backupDetail->db) && p('0:db_type,status') && e('mysql,completed'); // 测试步骤4:正常实例获取备份详情-数据库 -r($backupDetail->volume) && p('0:volume,status') && e('data,completed'); // 测试步骤5:正常实例获取备份详情-卷 \ No newline at end of file diff --git a/module/cne/test/model/batchquerystatus.php b/module/cne/test/model/batchquerystatus.php deleted file mode 100755 index 669c0c315a..0000000000 --- a/module/cne/test/model/batchquerystatus.php +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env php -k8name = 'test-app-1'; -$instance1->chart = 'zentao'; -$instance1->spaceData = new stdclass(); -$instance1->spaceData->k8space = 'test-namespace-1'; -$instance1->channel = 'stable'; - -$instance2 = new stdclass(); -$instance2->k8name = 'test-app-2'; -$instance2->chart = 'sonarqube'; -$instance2->spaceData = new stdclass(); -$instance2->spaceData->k8space = 'test-namespace-2'; -$instance2->channel = 'beta'; - -r(count($cneTest->batchQueryStatusTest(array($instance1, $instance2)))) && p() && e('2'); // 步骤1:正常实例列表 - -// 步骤2:测试空实例列表 -r(count($cneTest->batchQueryStatusTest(array()))) && p() && e('0'); // 步骤2:空实例列表 - -// 步骤3:测试单个实例 -$singleInstance = new stdclass(); -$singleInstance->k8name = 'single-app'; -$singleInstance->chart = 'gitlab'; -$singleInstance->spaceData = new stdclass(); -$singleInstance->spaceData->k8space = 'single-namespace'; -$singleInstance->channel = 'stable'; - -r(count($cneTest->batchQueryStatusTest(array($singleInstance)))) && p() && e('1'); // 步骤3:单个实例 - -// 步骤4:测试包含空channel的实例 -$emptyChannelInstance = new stdclass(); -$emptyChannelInstance->k8name = 'empty-channel-app'; -$emptyChannelInstance->chart = 'zentao'; -$emptyChannelInstance->spaceData = new stdclass(); -$emptyChannelInstance->spaceData->k8space = 'empty-channel-namespace'; -$emptyChannelInstance->channel = ''; // 空channel - -r($cneTest->batchQueryStatusTest(array($emptyChannelInstance))) && p('empty-channel-app:status') && e('running'); // 步骤4:空channel实例 - -// 步骤5:测试默认场景(传入null参数,使用默认模拟数据) -r(count($cneTest->batchQueryStatusTest(null))) && p() && e('2'); // 步骤5:默认模拟数据 \ No newline at end of file diff --git a/module/cne/test/model/certinfo.php b/module/cne/test/model/certinfo.php deleted file mode 100755 index 8cbf1a7cce..0000000000 --- a/module/cne/test/model/certinfo.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php -certInfoTest('')) && p() && e('0'); // 步骤1:空证书名称查询 -r($cneTest->certInfoTest('invalid-cert-name')) && p() && e('0'); // 步骤2:无效证书名称查询 -r($cneTest->certInfoTest('tls-haogs-cn')) && p('sans:0') && e('devops.corp.cc'); // 步骤3:有效证书名称查询 -r($cneTest->certInfoTest('tls-haogs-cn', '')) && p('sans:0') && e('devops.corp.cc'); // 步骤4:使用默认channel参数查询 -r($cneTest->certInfoTest('tls-haogs-cn', 'stable')) && p('sans:0') && e('devops.corp.cc'); // 步骤5:有效证书名称带自定义channel查询 \ No newline at end of file diff --git a/module/cne/test/model/dbdetail.php b/module/cne/test/model/dbdetail.php deleted file mode 100755 index 437d9417a3..0000000000 --- a/module/cne/test/model/dbdetail.php +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env php -dbDetailTest('', '')) && p() && e('0'); // 步骤1:测试空参数边界值 -r($cneTest->dbDetailTest('mysql', '')) && p() && e('0'); // 步骤2:测试部分参数为空的情况 -r($cneTest->dbDetailTest('mysql', 'quickon-system')) && p() && e('0'); // 步骤3:测试错误数据库服务名的异常处理 -r($cneTest->dbDetailTest('', 'quickon-system')) && p() && e('0'); // 步骤4:测试空数据库服务名但有效命名空间 -r($cneTest->dbDetailTest('zentaopaas-mysql', 'invalid-namespace')) && p() && e('0'); // 步骤5:测试错误命名空间的异常处理 -r($cneTest->dbDetailTest('zentaopaas-mysql', 'quickon-system')) && p('host') && e('zentaopaas-mysql.quickon-system.svc'); // 步骤6:测试正确参数获取host属性 -r($cneTest->dbDetailTest('zentaopaas-mysql', 'quickon-system')) && p('username') && e('root'); // 步骤7:测试正确参数获取username属性 \ No newline at end of file diff --git a/module/cne/test/model/getappconfig.php b/module/cne/test/model/getappconfig.php deleted file mode 100755 index a699eddc1c..0000000000 --- a/module/cne/test/model/getappconfig.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -getAppConfigTest(1)) && p() && e('0'); -r($cneTest->getAppConfigTest(999)) && p() && e('0'); -r($cneTest->getAppConfigTest(0)) && p() && e('0'); -r($cneTest->getAppConfigTest(-1)) && p() && e('0'); -r($cneTest->getAppConfigTest(100)) && p() && e('0'); \ No newline at end of file diff --git a/module/cne/test/model/getapplogs.php b/module/cne/test/model/getapplogs.php deleted file mode 100644 index ecee0612a7..0000000000 --- a/module/cne/test/model/getapplogs.php +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env php -getAppLogs(); -timeout=0 -cid=15612 - -- 获取CNE平台的日志 status @0 -- 获取CNE平台的日志 status @0 -- 获取CNE平台的日志 status @0 -- 获取CNE平台的日志 status @0 -- 获取CNE平台的日志 status @0 - -*/ - -include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -$cneModel = new cneModelTest(); - -r($cneModel->getAppLogsTest()) && p('status') && e('0'); - -r($cneModel->getAppLogsTest()) && p('status') && e('0'); - -r($cneModel->getAppLogsTest()) && p('status') && e('0'); - -r($cneModel->getAppLogsTest()) && p('status') && e('0'); - -r($cneModel->getAppLogsTest()) && p('status') && e('0'); \ No newline at end of file diff --git a/module/cne/test/model/getcomponents.php b/module/cne/test/model/getcomponents.php deleted file mode 100755 index 9f5f59cd3e..0000000000 --- a/module/cne/test/model/getcomponents.php +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env php -getComponentsTest()) && p('code') && e('600'); -r($cneTest->getComponentsTest(999)) && p() && e('0'); -r($cneTest->getComponentsTest(0)) && p('code') && e('400'); -r($cneTest->getComponentsTest(null)) && p() && e('0'); -r($cneTest->getComponentsTest(2)) && p('code') && e('600'); \ No newline at end of file diff --git a/module/cne/test/model/getdefaultaccount.php b/module/cne/test/model/getdefaultaccount.php deleted file mode 100755 index a6ad18ca3e..0000000000 --- a/module/cne/test/model/getdefaultaccount.php +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env php -id = 1; -$instance1->k8name = 'test-zentao-app-1'; -$instance1->channel = 'stable'; -$instance1->spaceData = new stdclass(); -$instance1->spaceData->k8space = 'test-namespace'; - -$instance2 = new stdclass(); -$instance2->id = 2; -$instance2->k8name = 'test-zentao-app-2'; -$instance2->channel = 'stable'; -$instance2->spaceData = new stdclass(); -$instance2->spaceData->k8space = 'test-namespace'; - -$invalidInstance = new stdclass(); -$invalidInstance->id = 999; -// 缺少必需的属性 - -// 5. 🔴 强制要求:必须包含至少5个测试步骤 -r($cneTest->getDefaultAccountTest($instance1, '')) && p() && e('0'); // 步骤1:正常情况测试获取默认账号(空组件参数) -r($cneTest->getDefaultAccountTest($instance1, 'mysql')) && p() && e('0'); // 步骤2:使用mysql组件获取默认账号 -r($cneTest->getDefaultAccountTest($instance2, 'redis')) && p() && e('0'); // 步骤3:使用redis组件获取默认账号 -r($cneTest->getDefaultAccountTest(null)) && p() && e('0'); // 步骤4:使用null实例参数 -r($cneTest->getDefaultAccountTest($invalidInstance, 'invalid-component')) && p() && e('0'); // 步骤5:使用无效实例对象验证容错性 \ No newline at end of file diff --git a/module/cne/test/model/getdomain.php b/module/cne/test/model/getdomain.php deleted file mode 100755 index 8a9fb243cf..0000000000 --- a/module/cne/test/model/getdomain.php +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env php -id = 2; -$validInstance->k8name = 'test-zentao-app'; -$validInstance->channel = 'stable'; -$validInstance->spaceData = new stdclass(); -$validInstance->spaceData->k8space = 'test-namespace'; - -$invalidInstance = new stdclass(); -$invalidInstance->id = 999; -$invalidInstance->k8name = ''; - -// 4. 🔴 强制要求:必须包含至少5个测试步骤 -r($cneTest->getDomainTest($validInstance, '')) && p() && e('0'); // 步骤1:使用默认实例获取域名信息 -r($cneTest->getDomainTest($validInstance)) && p() && e('0'); // 步骤2:使用默认实例和空组件名获取域名 -r($cneTest->getDomainTest($validInstance, 'mysql')) && p() && e('0'); // 步骤3:使用默认实例和mysql组件获取域名 -r($cneTest->getDomainTest($validInstance, 'web')) && p() && e('0'); // 步骤4:使用默认实例和web组件获取域名 -r($cneTest->getDomainTest($invalidInstance, '')) && p() && e('0'); // 步骤5:使用无效实例对象获取域名 \ No newline at end of file diff --git a/module/cne/test/model/getevents.php b/module/cne/test/model/getevents.php deleted file mode 100755 index a9fe1daf3b..0000000000 --- a/module/cne/test/model/getevents.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php -getEventsTest(1, '')) && p() && e('200'); -r($cneTest->getEventsTest(2, 'mysql')) && p() && e('200'); -r($cneTest->getEventsTest(3, '')) && p() && e('0'); -r($cneTest->getEventsTest(4, '')) && p() && e('600'); -r($cneTest->getEventsTest(0, '')) && p() && e('600'); \ No newline at end of file diff --git a/module/cne/test/model/getpods.php b/module/cne/test/model/getpods.php deleted file mode 100755 index 6cdb44a296..0000000000 --- a/module/cne/test/model/getpods.php +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env php -loadYaml('instance_getpods', false, 2)->gen(5); -zenData('space')->loadYaml('space_getpods', false, 2)->gen(3); - -// 3. 用户登录(选择合适角色) -su('admin'); - -// 4. 创建测试实例(变量名与模块名一致) -$cneTest = new cneModelTest(); - -// 5. 🔴 强制要求:必须包含至少5个测试步骤 -r($cneTest->getPodsTest(1)) && p() && e('0'); // 步骤1:正常情况测试获取实例pods(实例ID=1) -r($cneTest->getPodsTest(2, 'mysql')) && p() && e('0'); // 步骤2:使用指定组件mysql获取pods -r($cneTest->getPodsTest(999)) && p() && e('0'); // 步骤3:测试无效实例ID的容错处理(实例ID=999) -r($cneTest->getPodsTest(-1)) && p() && e('0'); // 步骤4:测试负数实例ID的边界情况(实例ID=-1) -r($cneTest->getPodsTest(3, 'invalid-component')) && p() && e('0'); // 步骤5:测试无效组件名的容错处理 \ No newline at end of file diff --git a/module/cne/test/model/getrestorestatus.php b/module/cne/test/model/getrestorestatus.php deleted file mode 100755 index c6838304ae..0000000000 --- a/module/cne/test/model/getrestorestatus.php +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env php -id = 1; -$instance1->k8name = 'test-app-1'; -$instance1->spaceData = new stdclass(); -$instance1->spaceData->k8space = 'test-namespace'; -$instance1->channel = 'stable'; - -$instance999 = new stdclass(); -$instance999->id = 999; -$instance999->k8name = 'test-app-999'; -$instance999->spaceData = new stdclass(); -$instance999->spaceData->k8space = 'test-namespace'; -$instance999->channel = 'stable'; - -$instance0 = new stdclass(); -$instance0->id = 0; -$instance0->k8name = 'test-app-0'; -$instance0->spaceData = new stdclass(); -$instance0->spaceData->k8space = 'test-namespace'; -$instance0->channel = 'stable'; - -$instanceNeg = new stdclass(); -$instanceNeg->id = -1; -$instanceNeg->k8name = 'test-app-neg'; -$instanceNeg->spaceData = new stdclass(); -$instanceNeg->spaceData->k8space = 'test-namespace'; -$instanceNeg->channel = 'stable'; - -r($cneTest->getRestoreStatusTest($instance1, 'backup-restore-001')) && p('code,message') && e('600,CNE服务器出错'); // 步骤1:正常实例和有效备份名查询恢复状态 -r($cneTest->getRestoreStatusTest($instance999, 'backup-test')) && p('code,message') && e('404,Instance not found'); // 步骤2:不存在的实例ID查询恢复状态 -r($cneTest->getRestoreStatusTest($instance0, 'backup-test')) && p('code,message') && e('404,Instance not found'); // 步骤3:无效实例ID(0)查询恢复状态 -r($cneTest->getRestoreStatusTest($instance1, '')) && p('code,message') && e('400,Backup name cannot be empty'); // 步骤4:空备份名查询恢复状态 -r($cneTest->getRestoreStatusTest($instanceNeg, 'backup-test')) && p('code,message') && e('404,Instance not found'); // 步骤5:负数实例ID查询恢复状态 \ No newline at end of file diff --git a/module/cne/test/model/getsettingsmapping.php b/module/cne/test/model/getsettingsmapping.php deleted file mode 100755 index 01a8400552..0000000000 --- a/module/cne/test/model/getsettingsmapping.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -getSettingsMappingTest()) && p('admin_username') && e('admin'); -r($cneTest->getSettingsMappingTest(array())) && p('z_username') && e('zentao_user'); -r($cneTest->getSettingsMappingTest(array(array('key' => 'custom_username', 'type' => 'helm', 'path' => 'auth.custom_username')))) && p('custom_username') && e('test_value_for_custom_username'); -r($cneTest->getSettingsMappingTest(array(array('key' => 'db_username', 'type' => 'secret', 'path' => 'database.username'), array('key' => 'db_password', 'type' => 'secret', 'path' => 'database.password')))) && p('db_username') && e('test_value_for_db_username'); -r($cneTest->getSettingsMappingTest(array(array('key' => 'invalid_key', 'type' => 'invalid_type', 'path' => 'invalid.path')))) && p('invalid_key') && e('test_value_for_invalid_key'); \ No newline at end of file diff --git a/module/cne/test/model/querystatus.php b/module/cne/test/model/querystatus.php deleted file mode 100755 index 48f7eef59a..0000000000 --- a/module/cne/test/model/querystatus.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -queryStatusTest(1)) && p('code') && e('0'); -r($cneTest->queryStatusTest(999)) && p() && e('0'); -r($cneTest->queryStatusTest(0)) && p() && e('0'); -r($cneTest->queryStatusTest(-1)) && p() && e('0'); -r($cneTest->queryStatusTest(100)) && p() && e('0'); \ No newline at end of file diff --git a/module/cne/test/model/shareddblist.php b/module/cne/test/model/shareddblist.php deleted file mode 100755 index 5a93c39833..0000000000 --- a/module/cne/test/model/shareddblist.php +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env php -sharedDBListTest('')) && p() && e('0'); -r($cneTest->sharedDBListTest('mysql')) && p('zentaopaas-mysql:name,kind,port') && e('zentaopaas-mysql,mysql,3306'); -r($cneTest->sharedDBListTest('postgresql')) && p('postgres-shared:name,kind,port') && e('postgres-shared,postgresql,5432'); -r($cneTest->sharedDBListTest('mongodb')) && p() && e('0'); -r($cneTest->sharedDBListTest('redis')) && p('redis-cluster:name,kind,port') && e('redis-cluster,redis,6379'); \ No newline at end of file diff --git a/module/cne/test/model/startapp.php b/module/cne/test/model/startapp.php deleted file mode 100755 index 9ad78ca4ac..0000000000 --- a/module/cne/test/model/startapp.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -startAppTest()) && p('code') && e('200'); -r($cneTest->startAppWithEmptyChannelTest()) && p('data:channel') && e('stable'); -r($cneTest->startAppWithInvalidParamsTest()) && p('code') && e('200'); -r($cneTest->startAppWithMissingParamsTest()) && p('code') && e('200'); -r($cneTest->startAppWithNullParamsTest()) && p() && e('~~'); \ No newline at end of file diff --git a/module/cne/test/model/translateerror.php b/module/cne/test/model/translateerror.php deleted file mode 100755 index 21ef6b9400..0000000000 --- a/module/cne/test/model/translateerror.php +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env php -code = 400; -$apiResult1->message = 'original error'; -r($cneTest->translateErrorTest($apiResult1)) && p('code') && e('400'); - -// 测试步骤2:已知错误代码404 -$apiResult2 = new stdclass(); -$apiResult2->code = 404; -$apiResult2->message = 'not found'; -r($cneTest->translateErrorTest($apiResult2)) && p('code') && e('404'); - -// 测试步骤3:未知错误代码999 -$apiResult3 = new stdclass(); -$apiResult3->code = 999; -$apiResult3->message = 'unknown error'; -r($cneTest->translateErrorTest($apiResult3)) && p('code') && e('999'); - -// 测试步骤4:已知错误代码41001 -$apiResult4 = new stdclass(); -$apiResult4->code = 41001; -$apiResult4->message = 'certificate expired'; -r($cneTest->translateErrorTest($apiResult4)) && p('code') && e('41001'); - -// 测试步骤5:已知错误代码40004 -$apiResult5 = new stdclass(); -$apiResult5->code = 40004; -$apiResult5->message = 'cert domain mismatch'; -r($cneTest->translateErrorTest($apiResult5)) && p('code') && e('40004'); \ No newline at end of file diff --git a/module/cne/test/model/updateconfig.php b/module/cne/test/model/updateconfig.php deleted file mode 100755 index e3fbb4b396..0000000000 --- a/module/cne/test/model/updateconfig.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -updateConfigTest()) && p() && e('0'); -r($cneTest->updateConfigTest('2024.04.2401')) && p() && e('0'); -r($cneTest->updateConfigTest(null, true)) && p() && e('0'); -r($cneTest->updateConfigTest(null, null, array('key1' => 'value1'))) && p() && e('0'); -r($cneTest->updateConfigTest(null, false, null, (object)array('setting1' => 'map1'))) && p() && e('0'); \ No newline at end of file diff --git a/module/cne/test/model/validatedb.php b/module/cne/test/model/validatedb.php deleted file mode 100755 index a2ebb4f9f3..0000000000 --- a/module/cne/test/model/validatedb.php +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env php -validateDB(); -timeout=0 -cid=15638 - -- 空的数据 - - 属性user @1 - - 属性database @1 -- 正确的数据库 - - 属性user @1 - - 属性database @1 -- 正确的数据库和用户 - - 属性user @1 - - 属性database @1 -- 正确的数据库、用户和数据库名 - - 属性user @1 - - 属性database @1 -- 正确的所有数据,表名重复 - - 属性user @1 - - 属性database @~~ -- 正确的数据库、用户、数据库名和表名 - - 属性user @1 - - 属性database @1 - -*/ - -include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -$cneModel = new cneModelTest(); - -$dbService = ''; -$dbUser = ''; -$dbName = ''; -$namespace = ''; -r($cneModel->validateDBTest($dbService, $dbUser, $dbName, $namespace)) && p('user,database') && e('1,1'); // 空的数据 - -$dbService = 'zentaopaas-mysql'; -r($cneModel->validateDBTest($dbService, $dbUser, $dbName, $namespace)) && p('user,database') && e('1,1'); // 正确的数据库 - -$dbUser = 'root'; -r($cneModel->validateDBTest($dbService, $dbUser, $dbName, $namespace)) && p('user,database') && e('1,1'); // 正确的数据库和用户 - -$dbName = 'zentaopaas'; -r($cneModel->validateDBTest($dbService, $dbUser, $dbName, $namespace)) && p('user,database') && e('1,1'); // 正确的数据库、用户和数据库名 - -$namespace = 'quickon-system'; -r($cneModel->validateDBTest($dbService, $dbUser, $dbName, $namespace)) && p('user,database') && e('~~,~~'); // 正确的所有数据,表名重复 - -$dbName = 'zentaopaas_test'; -r($cneModel->validateDBTest($dbService, $dbUser, $dbName, $namespace)) && p('user,database') && e('~~,1'); // 正确的数据库、用户、数据库名和表名 diff --git a/module/common/test/lib/model.class.php b/module/common/test/lib/model.class.php index 14a57f75a8..b782d95568 100644 --- a/module/common/test/lib/model.class.php +++ b/module/common/test/lib/model.class.php @@ -17,11 +17,7 @@ class commonModelTest extends baseTest */ public function apiErrorTest($result = null) { - $reflection = new ReflectionClass('commonModel'); - $method = $reflection->getMethod('apiError'); - $method->setAccessible(true); - - $result = $method->invoke(null, $result); + $result = $this->invokeArgs('apiError', [$result]); if(dao::isError()) return dao::getError(); return $result; } @@ -43,37 +39,172 @@ class commonModelTest extends baseTest } /** - * Test printBack method metadata. + * Test canOperateEffort method. * - * @param string $checkType + * @param object $effort * @access public * @return mixed */ - public function printBackMetaTest(string $checkType) + public function canOperateEffortTest($effort = null) { - if($checkType == 'exists') - { - return method_exists('commonModel', 'printBack') ? '1' : '0'; + $result = $this->instance->canOperateEffort($effort); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test checkIP method. + * + * @param string $ipWhiteList + * @access public + * @return mixed + */ + public function checkIPTest($ipWhiteList = '') + { + $result = $this->instance->checkIP($ipWhiteList); + if(dao::isError()) return dao::getError(); + return $result ? '1' : '0'; + } + + /** + * Test checkPrivByObject method. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return bool + */ + public function checkPrivByObjectTest(string $objectType, int $objectID): bool + { + $result = $this->instance->checkPrivByObject($objectType, $objectID); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * 检查详情页操作按钮的权限。 + * Check the privilege of the operate action. + * + * @param string $moduleName + * @param object $data + * @param object $menu + * @access protected + * @return array|bool + */ + public function checkPrivForOperateActionTest(string $moduleName, string $action, array $actionData) + { + $object = $this->instance->dao->select('*')->from($this->instance->config->objectTables[$moduleName])->where('id')->eq(1)->fetch(); + $result = $this->instance->checkPrivForOperateAction($actionData, $action, $moduleName, $object, 'mainActions'); + return is_array($result) ? !empty($result['url']) : $result; + } + + /** + * Test createMenuLink method. + * + * @param object $menuItem + * @access public + * @return mixed + */ + public function createMenuLinkTest($menuItem) + { + $result = $this->instance->createMenuLink($menuItem); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test getDotStyle method. + * + * @param bool $showCount + * @param int $unreadCount + * @access public + * @return array + */ + public function getDotStyleTest(bool $showCount, int $unreadCount): array + { + $result = commonModel::getDotStyle($showCount, $unreadCount); + return $result; + } + + /** + * Test getMainNavList method. + * + * @param string $moduleName + * @param bool $useDefault + * @access public + * @return mixed + */ + public function getMainNavListTest($moduleName, $useDefault = false) + { + $result = commonModel::getMainNavList($moduleName, $useDefault); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test isOpenMethod method. + * + * @param string $module + * @param string $method + * @access public + * @return bool + */ + public function isOpenMethodTest($module, $method) + { + $result = $this->objectModel->isOpenMethod($module, $method); + if(dao::isError()) return dao::getError(); + return $result; + } + + /** + * Test isTutorialMode method. + * + * @access public + * @return mixed + */ + public function isTutorialModeTest() + { + $result = commonModel::isTutorialMode(); + if(dao::isError()) return dao::getError(); + return $result ? '1' : '0'; + } + + /** + * Test setUser method. + * + * @param string $mode 测试模式:'guest'测试访客,'session'测试已登录用户 + * @access public + * @return mixed + */ + public function setUserTest($mode = '') + { + // 如果指定测试guest模式,先清除session + if($mode === 'guest') { + if(isset($_SESSION['user'])) unset($_SESSION['user']); + if(isset($this->instance->app->user)) unset($app->user); } - $reflection = new ReflectionMethod('commonModel', 'printBack'); + // 执行setUser方法 + $this->instance->setUser(); + if(dao::isError()) return dao::getError(); - if($checkType == 'static') - { - return $reflection->isStatic() ? '1' : '0'; - } + // 返回结果 + return $this->instance->app->user; + } - if($checkType == 'public') - { - return $reflection->isPublic() ? '1' : '0'; - } - - if($checkType == 'paramCount') - { - return (string)$reflection->getNumberOfParameters(); - } - - return '0'; + /** + * Test strEndsWith method. + * + * @param string $haystack + * @param string $needle + * @access public + * @return bool + */ + public function strEndsWithTest($haystack, $needle) + { + $result = commonModel::strEndsWith($haystack, $needle); + if(dao::isError()) return dao::getError(); + return $result; } /** @@ -121,7 +252,6 @@ class commonModelTest extends baseTest { $result = commonModel::printDuration($seconds, $format); if(dao::isError()) return dao::getError(); - return $result; } diff --git a/module/common/test/model/apidelete.php b/module/common/test/model/apidelete.php deleted file mode 100755 index 05847a6fb4..0000000000 --- a/module/common/test/model/apidelete.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -apiDeleteTest('https://api.example.com/success', array('id' => 123))) && p('code') && e('200'); // 步骤1:成功删除请求 -r($commonTest->apiDeleteTest('https://api.example.com/error', array('id' => 456))) && p('code') && e('400'); // 步骤2:业务错误请求 -r($commonTest->apiDeleteTest('', array('id' => 789))) && p() && e('Empty URL'); // 步骤3:空URL参数 -r($commonTest->apiDeleteTest('https://api.example.com/timeout', array('id' => 999))) && p('code') && e('600'); // 步骤4:超时错误请求 -r($commonTest->apiDeleteTest('https://api.example.com/invalid-json', array('id' => 111))) && p('code') && e('600'); // 步骤5:无效JSON响应 \ No newline at end of file diff --git a/module/common/test/model/apiget.php b/module/common/test/model/apiget.php deleted file mode 100755 index 4ea8794109..0000000000 --- a/module/common/test/model/apiget.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -apiGetTest('')) && p() && e('Empty URL'); -r($commonTest->apiGetTest('invalid-url')) && p('code') && e('600'); -r($commonTest->apiGetTest('http://api.success.com/test', array('param' => 'value'))) && p('code') && e('200'); -r($commonTest->apiGetTest('http://api.error.com/test')) && p('code') && e('400'); -r($commonTest->apiGetTest('http://api.example.com/test')) && p('code') && e('600'); \ No newline at end of file diff --git a/module/common/test/model/apipost.php b/module/common/test/model/apipost.php deleted file mode 100755 index bdac9b81bc..0000000000 --- a/module/common/test/model/apipost.php +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env php -> 期望返回code为200 -- 测试步骤2:成功响应检查 >> 期望返回code为200且message为Success -- 测试步骤3:业务错误响应 >> 期望返回code为400且message为Bad Request -- 测试步骤4:空URL验证 >> 期望返回Empty URL错误信息 -- 测试步骤5:无效URL格式验证 >> 期望返回code为600的错误 - -*/ - -include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -su('admin'); - -$commonTest = new commonModelTest(); - -r($commonTest->apiPostTest('https://api.example.com/test', array('key' => 'value'))) && p('code') && e('200'); -r($commonTest->apiPostTest('https://api.example.com/success', array('data' => 'test'))) && p('code,message') && e('200,Success'); -r($commonTest->apiPostTest('https://api.example.com/error', array('action' => 'fail'))) && p('code,message') && e('400,Bad Request'); -r($commonTest->apiPostTest('', array('empty' => 'url'))) && p() && e('Empty URL'); -r($commonTest->apiPostTest('invalid-url', array('test' => 'data'))) && p('code') && e('600'); \ No newline at end of file diff --git a/module/common/test/model/apiput.php b/module/common/test/model/apiput.php deleted file mode 100755 index eb30195afe..0000000000 --- a/module/common/test/model/apiput.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -apiPutTest('https://api.example.com/success', array('key' => 'value'))) && p('code') && e('200'); // 步骤1:正常成功请求 -r($commonTest->apiPutTest('https://api.example.com/error', array('key' => 'value'))) && p('code') && e('400'); // 步骤2:业务错误请求 -r($commonTest->apiPutTest('invalid-url', array('key' => 'value'))) && p('code') && e('600'); // 步骤3:无效URL -r($commonTest->apiPutTest('', array('key' => 'value'))) && p() && e('Empty URL'); // 步骤4:空URL -r($commonTest->apiPutTest('https://api.example.com/success', array('data' => 'test'), array('Content-Type: application/json'))) && p('code') && e('200'); // 步骤5:带headers的请求 \ No newline at end of file diff --git a/module/common/test/model/buildactionitem.php b/module/common/test/model/buildactionitem.php deleted file mode 100755 index c2fb2b72e7..0000000000 --- a/module/common/test/model/buildactionitem.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -buildActionItemTest('product', 'index', '')) && p('url') && e('product-index-'); // 步骤1:测试有权限模块正常构建链接 -r($commonTest->buildActionItemTest('product', 'index', '', null, array('class' => 'btn'))) && p('class') && e('btn'); // 步骤2:测试带属性参数的链接构建 -r($commonTest->buildActionItemTest('product', 'index', '', null, array('title' => '查看'))) && p('title') && e('查看'); // 步骤3:测试带title属性的链接构建 -r($commonTest->buildActionItemTest('product', 'view', 'id=1')) && p('url') && e('product-view-id=1'); // 步骤4:测试带参数的URL构建 -r($commonTest->buildActionItemTest('', 'index', '')) && p() && e('0'); // 步骤5:测试空模块名的异常处理 \ No newline at end of file diff --git a/module/common/test/model/buildiconbutton.php b/module/common/test/model/buildiconbutton.php deleted file mode 100755 index 58eae08d43..0000000000 --- a/module/common/test/model/buildiconbutton.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -buildIconButtonTest(1)) && p() && e('1'); // 步骤1:验证方法存在 -r($commonTest->buildIconButtonTest(2)) && p() && e('1'); // 步骤2:验证方法为静态方法 -r($commonTest->buildIconButtonTest(3)) && p() && e('1'); // 步骤3:验证方法为公共方法 -r($commonTest->buildIconButtonTest(4)) && p() && e('13'); // 步骤4:验证参数数量 -r($commonTest->buildIconButtonTest(5)) && p() && e('module'); // 步骤5:验证第一个参数名称 \ No newline at end of file diff --git a/module/common/test/model/buildmorebutton.php b/module/common/test/model/buildmorebutton.php deleted file mode 100755 index cbb1cf7e9a..0000000000 --- a/module/common/test/model/buildmorebutton.php +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env php -gen(5); - -// 准备项目和执行数据 -$project = zenData('project'); -$project->id->range('1-10'); -$project->name->range('项目{1-5},执行{6-10}'); -$project->type->range('project{5},sprint{5}'); -$project->parent->range('0{5},0{5}'); -$project->project->range('0{5},1-5'); // 执行的project字段指向父项目 -$project->grade->range('1{5},2{5}'); -$project->deleted->range('0{10}'); -$project->gen(10); - -su('admin'); - -// 创建测试实例 -$commonTest = new commonModelTest(); - -// 模拟Tutorial模式进行一个测试 -$_SESSION['tutorialMode'] = true; - -// 测试用例(5个测试步骤) -r($commonTest->buildMoreButtonTest(999, false)) && p() && e('0'); // 步骤1:不存在的executionID -r($commonTest->buildMoreButtonTest(0, false)) && p() && e('0'); // 步骤2:无效ID为0 -r($commonTest->buildMoreButtonTest(-1, false)) && p() && e('0'); // 步骤3:负数ID -r($commonTest->buildMoreButtonTest(1, false)) && p() && e('0'); // 步骤4:Tutorial模式或正常模式 -r($commonTest->buildMoreButtonTest(6, false)) && p() && e('0'); // 步骤5:执行记录但同项目无其他执行 diff --git a/module/common/test/model/buildoperatemenu.php b/module/common/test/model/buildoperatemenu.php deleted file mode 100755 index c4cf171fca..0000000000 --- a/module/common/test/model/buildoperatemenu.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -testBuildOperateMenuSignature(1)) && p() && e('1'); // 步骤1:验证方法存在 -r($commonTest->testBuildOperateMenuSignature(2)) && p() && e('1'); // 步骤2:验证方法为公共方法 -r($commonTest->testBuildOperateMenuSignature(3)) && p() && e('1'); // 步骤3:验证第一个参数为object类型 -r($commonTest->testBuildOperateMenuSignature(4)) && p() && e('1'); // 步骤4:验证第二个参数为string类型 -r($commonTest->testBuildOperateMenuSignature(5)) && p() && e('2'); // 步骤5:验证参数数量 \ No newline at end of file diff --git a/module/common/test/model/checkentry.php b/module/common/test/model/checkentry.php deleted file mode 100755 index 91f5133f11..0000000000 --- a/module/common/test/model/checkentry.php +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env php -loadYaml('checkentry/entry', false, 2)->gen(10); -zenData('user')->loadYaml('checkentry/user', false, 2)->gen(10); - -su('admin'); - -$commonTest = new commonModelTest(); - -r($commonTest->checkEntryTest('', '', '', '')) && p() && e('EMPTY_ENTRY'); // 测试步骤1:缺少模块参数 -r($commonTest->checkEntryTest('user', '', '', '')) && p() && e('EMPTY_ENTRY'); // 测试步骤2:缺少方法参数 -r($commonTest->checkEntryTest('misc', 'about', '', '')) && p() && e('1'); // 测试步骤3:访问开放方法misc.about -r($commonTest->checkEntryTest('user', 'login', '', '')) && p() && e('PARAM_CODE_MISSING'); // 测试步骤4:缺少code参数 -r($commonTest->checkEntryTest('user', 'login', 'validcode', '')) && p() && e('PARAM_TOKEN_MISSING'); // 测试步骤5:缺少token参数 -r($commonTest->checkEntryTest('user', 'login', 'nonexistcode', 'token123')) && p() && e('EMPTY_ENTRY'); // 测试步骤6:code不存在 -r($commonTest->checkEntryTest('user', 'login', 'nokey', 'token123')) && p() && e('EMPTY_KEY'); // 测试步骤7:entry的key为空 -r($commonTest->checkEntryTest('user', 'login', 'validip', 'token123')) && p() && e('IP_DENIED'); // 测试步骤8:IP地址被拒绝 -r($commonTest->checkEntryTest('user', 'login', 'invalidtoken', 'token123')) && p() && e('INVALID_TOKEN'); // 测试步骤9:token无效 -r($commonTest->checkEntryTest('user', 'login', 'unboundaccount', 'token123')) && p() && e('ACCOUNT_UNBOUND'); // 测试步骤10:账户未绑定 \ No newline at end of file diff --git a/module/common/test/model/checkmenuvarsreplaced.php b/module/common/test/model/checkmenuvarsreplaced.php deleted file mode 100755 index e36c97c6d4..0000000000 --- a/module/common/test/model/checkmenuvarsreplaced.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -checkMenuVarsReplacedTest(1)) && p() && e('public_static_method'); -r($commonTest->checkMenuVarsReplacedTest(2)) && p() && e('no_return_type'); -r($commonTest->checkMenuVarsReplacedTest(3)) && p() && e('no_parameters'); -r($commonTest->checkMenuVarsReplacedTest(4)) && p() && e('has_doc_comment'); -r($commonTest->checkMenuVarsReplacedTest(5)) && p() && e('correct_signature'); \ No newline at end of file diff --git a/module/common/test/model/checknotcn.php b/module/common/test/model/checknotcn.php deleted file mode 100755 index 63addb4e0e..0000000000 --- a/module/common/test/model/checknotcn.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -checkNotCNTest('zh-cn')) && p() && e('0'); // 步骤1:中文简体 -r($commonTest->checkNotCNTest('zh-tw')) && p() && e('0'); // 步骤2:中文繁体 -r($commonTest->checkNotCNTest('en')) && p() && e('1'); // 步骤3:英语 -r($commonTest->checkNotCNTest('de')) && p() && e('1'); // 步骤4:德语 -r($commonTest->checkNotCNTest('fr')) && p() && e('1'); // 步骤5:法语 -r($commonTest->checkNotCNTest('')) && p() && e('0'); // 步骤6:空语言(默认为zh-cn) -r($commonTest->checkNotCNTest('test')) && p() && e('1'); // 步骤7:未知语言 \ No newline at end of file diff --git a/module/common/test/model/checkupgradestatus.php b/module/common/test/model/checkupgradestatus.php deleted file mode 100755 index 12c032e272..0000000000 --- a/module/common/test/model/checkupgradestatus.php +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env php -checkUpgradeStatusTest()) && p() && e('1'); // 步骤1:测试checkUpgradeStatus正常调用情况 -r($commonTest->checkUpgradeStatusTest('container')) && p() && e('1'); // 步骤2:测试容器环境下的行为 -r($commonTest->checkUpgradeStatusTest('safefile')) && p() && e('1'); // 步骤3:测试有安全文件的情况 -r($commonTest->checkUpgradeStatusTest('upgrading')) && p() && e('1'); // 步骤4:测试升级过程中的行为 -r($commonTest->checkUpgradeStatusTest('outputbuffer')) && p() && e('1'); // 步骤5:测试输出缓冲区处理 \ No newline at end of file diff --git a/module/common/test/model/getactivemainmenu.php b/module/common/test/model/getactivemainmenu.php deleted file mode 100755 index 591d0057ff..0000000000 --- a/module/common/test/model/getactivemainmenu.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -getActiveMainMenuTest(1)) && p() && e('method_validated'); // 步骤1:验证方法基本功能-产品模块场景 -r($commonTest->getActiveMainMenuTest(2)) && p() && e('method_validated'); // 步骤2:验证方法基本功能-空模块场景 -r($commonTest->getActiveMainMenuTest(3)) && p() && e('method_validated'); // 步骤3:验证方法基本功能-项目模块场景 -r($commonTest->getActiveMainMenuTest(4)) && p() && e('method_validated'); // 步骤4:验证方法基本功能-执行模块场景 -r($commonTest->getActiveMainMenuTest(5)) && p() && e('method_validated'); // 步骤5:验证方法基本功能-缺陷模块场景 \ No newline at end of file diff --git a/module/common/test/model/gethasprivlink.php b/module/common/test/model/gethasprivlink.php deleted file mode 100644 index 4b84c729cd..0000000000 --- a/module/common/test/model/gethasprivlink.php +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env php - '需求|my|contribute|mode=story'); -$menuList[] = array('link' => '产品|product|all|'); -$menuList[] = array('link' => '项目列表|project|browse|'); -$menuList[] = array('link' => '质量保证计划|auditplan|browse|projectID=%s', 'links' => array('project|deliverableChecklist|projectID=%s', 'nc|browse|project=%s&from=project')); - -r($commonTest->getHasPrivLinkTest($menuList[0])) && p() && e('0'); // 测试空数据 -r($commonTest->getHasPrivLinkTest($menuList[1])) && p('1,2') && e('my,contribute'); // 测试获取有权限的需求链接 -r($commonTest->getHasPrivLinkTest($menuList[2])) && p('1,2') && e('product,all'); // 测试获取有权限的产品链接 -r($commonTest->getHasPrivLinkTest($menuList[3])) && p('1,2') && e('project,browse'); // 测试获取有权限的项目链接 -r($commonTest->getHasPrivLinkTest($menuList[4])) && p('1,2') && e('auditplan,browse'); // 测试获取有权限的质量保证计划 diff --git a/module/common/test/model/getsysurl.php b/module/common/test/model/getsysurl.php deleted file mode 100755 index 19b4cd6b48..0000000000 --- a/module/common/test/model/getsysurl.php +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env php -getSysURLTest(1)) && p() && e('0'); - -// 模拟HTTPS环境测试 -r($commonTest->getSysURLTest(2)) && p() && e('https://example.com'); - -// 模拟HTTP环境测试 -r($commonTest->getSysURLTest(3)) && p() && e('http://example.com'); - -// 模拟X-Forwarded-Proto头部测试 -r($commonTest->getSysURLTest(4)) && p() && e('https://example.com'); - -// 模拟REQUEST_SCHEME头部测试 -r($commonTest->getSysURLTest(5)) && p() && e('https://example.com'); \ No newline at end of file diff --git a/module/common/test/model/getuserpriv.php b/module/common/test/model/getuserpriv.php deleted file mode 100755 index 96110cd9c2..0000000000 --- a/module/common/test/model/getuserpriv.php +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env php -gen(1); -zenData('user')->gen(5); - -su('admin'); - -/** - -title=测试 commonModel::getUserPriv(); -timeout=0 -cid=15678 - -- 执行commonTest模块的getUserPrivTest方法,参数是'user', 'browse', null, '', 'nouser' @0 -- 执行commonTest模块的getUserPrivTest方法,参数是'user', 'browse', null, '', 'admin' @1 -- 执行commonTest模块的getUserPrivTest方法,参数是'user', 'browse', null, '', 'openmethod' @1 -- 执行commonTest模块的getUserPrivTest方法,参数是'user', 'browse', null, '', 'hasrights' @1 -- 执行commonTest模块的getUserPrivTest方法,参数是'task', 'create', null, '', 'norights' @0 - -*/ - -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -$commonTest = new commonModelTest(); - -r($commonTest->getUserPrivTest('user', 'browse', null, '', 'nouser')) && p() && e('0'); -r($commonTest->getUserPrivTest('user', 'browse', null, '', 'admin')) && p() && e('1'); -r($commonTest->getUserPrivTest('user', 'browse', null, '', 'openmethod')) && p() && e('1'); -r($commonTest->getUserPrivTest('user', 'browse', null, '', 'hasrights')) && p() && e('1'); -r($commonTest->getUserPrivTest('task', 'create', null, '', 'norights')) && p() && e('0'); \ No newline at end of file diff --git a/module/common/test/model/http.php b/module/common/test/model/http.php deleted file mode 100755 index 977106a6d4..0000000000 --- a/module/common/test/model/http.php +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env php -httpTest('https://example.com/api', null, array(), array(), 'data', 'GET')) && p() && e('GET response data'); -r($commonTest->httpTest('https://example.com/api', array('name' => 'test'), array(), array(), 'data', 'POST')) && p() && e('POST response with data'); -r($commonTest->httpTest('https://example.com/json/api', array('data' => 'test'), array(), array(), 'json', 'POST')) && p() && e('{"status":"success","data":"test"}'); -r($commonTest->httpTest('https://example.com/httpcode/api', null, array(), array(), 'data', 'POST', 30, true)) && p('1') && e('201'); -r($commonTest->httpTest('', null, array(), array(), 'data', 'POST')) && p() && e('0'); -r($commonTest->httpTest('https://example.com/api', array('update' => 'data'), array(), array(), 'data', 'PUT')) && p() && e('PUT response'); -r($commonTest->httpTest('https://example.com/error/api', null, array(), array(), 'data', 'GET')) && p() && e('0'); \ No newline at end of file diff --git a/module/common/test/model/initauthorize.php b/module/common/test/model/initauthorize.php deleted file mode 100755 index 3453258dcb..0000000000 --- a/module/common/test/model/initauthorize.php +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env php -initAuthorizeTest('', false)) && p('result') && e('0'); // 步骤1:无用户登录情况 -r($commonTest->initAuthorizeTest('admin', true)) && p('result') && e('1'); // 步骤2:升级过程中的用户 -r($commonTest->initAuthorizeTest('admin', false)) && p('result') && e('1'); // 步骤3:正常用户登录非升级状态 -r($commonTest->initAuthorizeTest('user1', false)) && p('result') && e('1'); // 步骤4:普通用户权限初始化 -r($commonTest->initAuthorizeTest('guest', false)) && p('result') && e('1'); // 步骤5:guest用户权限初始化 \ No newline at end of file diff --git a/module/common/test/model/printaboutbar.php b/module/common/test/model/printaboutbar.php deleted file mode 100755 index 32eb17e569..0000000000 --- a/module/common/test/model/printaboutbar.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php -printAboutBarTest(1)) && p() && e('1'); // 步骤1:验证方法存在 -r($commonTest->printAboutBarTest(2)) && p() && e('1'); // 步骤2:验证方法为静态方法 -r($commonTest->printAboutBarTest(3)) && p() && e('1'); // 步骤3:验证方法为公共方法 -r($commonTest->printAboutBarTest(4)) && p() && e('1'); // 步骤4:验证参数数量为0 -r($commonTest->printAboutBarTest(5)) && p() && e('1'); // 步骤5:验证方法可以被调用 \ No newline at end of file diff --git a/module/common/test/model/printclientlink.php b/module/common/test/model/printclientlink.php deleted file mode 100755 index 2697451f18..0000000000 --- a/module/common/test/model/printclientlink.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -printClientLinkTest('both_enabled')) && p() && e('1'); // 步骤1:两个配置都启用 -r($commonTest->printClientLinkTest('xxserver_only')) && p() && e('0'); // 步骤2:仅xxserver安装 -r($commonTest->printClientLinkTest('xuanxuan_only')) && p() && e('0'); // 步骤3:仅xuanxuan开启 -r($commonTest->printClientLinkTest('both_disabled')) && p() && e('0'); // 步骤4:两个都禁用 -r($commonTest->printClientLinkTest('xxserver_not_set')) && p() && e('0'); // 步骤5:xxserver未设置 \ No newline at end of file diff --git a/module/common/test/model/printcreatelist.php b/module/common/test/model/printcreatelist.php deleted file mode 100755 index 24aa14a9d6..0000000000 --- a/module/common/test/model/printcreatelist.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -printCreateListTest(1)) && p() && e('1'); -r($commonTest->printCreateListTest(2)) && p() && e('1'); -r($commonTest->printCreateListTest(3)) && p() && e('1'); -r($commonTest->printCreateListTest(4)) && p() && e('1'); -r($commonTest->printCreateListTest(5)) && p() && e('1'); \ No newline at end of file diff --git a/module/common/test/model/printicon.php b/module/common/test/model/printicon.php deleted file mode 100755 index f2b6f5b31f..0000000000 --- a/module/common/test/model/printicon.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -printIconTest(1)) && p() && e('1'); // 步骤1:验证方法存在 -r($commonTest->printIconTest(2)) && p() && e('1'); // 步骤2:验证方法为静态方法 -r($commonTest->printIconTest(3)) && p() && e('1'); // 步骤3:验证方法为公共方法 -r($commonTest->printIconTest(4)) && p() && e('13'); // 步骤4:验证参数数量 -r($commonTest->printIconTest(5)) && p() && e('1'); // 步骤5:验证方法功能调用buildIconButton \ No newline at end of file diff --git a/module/common/test/model/printlink.php b/module/common/test/model/printlink.php deleted file mode 100755 index aff1b8ba51..0000000000 --- a/module/common/test/model/printlink.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php -printLinkTest('misc', 'ping', '', 'Ping', '', '', true, false, null)) && p('result') && e('1'); -r($commonTest->printLinkTest('admin', 'forbidden', '', 'Forbidden', '', '', true, false, null)) && p() && e('0'); -r($commonTest->printLinkTest('user', 'login', '', 'Login', '', '', true, false, null)) && p('result') && e('1'); -r($commonTest->printLinkTest('task', 'view', 'taskID=123', 'View Task', '_blank', 'class="btn"', true, false, null)) && p('result') && e('1'); -r($commonTest->printLinkTest('project', 'browse', '', 'Projects', '', 'id="project-link"', true, false, null)) && p('result') && e('1'); \ No newline at end of file diff --git a/module/common/test/model/printorderlink.php b/module/common/test/model/printorderlink.php deleted file mode 100755 index 5a5eed4519..0000000000 --- a/module/common/test/model/printorderlink.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php -ID -- 步骤2:当前字段升序排序链接 @ID -- 步骤3:当前字段降序排序链接 @ID -- 步骤4:移动端排序链接生成 @Name -- 步骤5:带反引号字段名处理 @Status - -*/ - -include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -$commonTest = new commonModelTest(); - -r($commonTest->printOrderLinkTest('id', 'name_asc', 'orderBy=%s', 'ID', 'user', 'browse')) && p() && e("ID"); // 步骤1:基本排序链接生成 -r($commonTest->printOrderLinkTest('id', 'id_asc', 'orderBy=%s', 'ID', 'user', 'browse')) && p() && e("ID"); // 步骤2:当前字段升序排序链接 -r($commonTest->printOrderLinkTest('id', 'id_desc', 'orderBy=%s', 'ID', 'user', 'browse')) && p() && e("ID"); // 步骤3:当前字段降序排序链接 -r($commonTest->printOrderLinkTest('name', 'id_asc', 'orderBy=%s', 'Name', 'task', 'browse', 'mhtml')) && p() && e("Name"); // 步骤4:移动端排序链接生成 -r($commonTest->printOrderLinkTest('status', '`status`_desc', 'orderBy=%s', 'Status', 'bug', 'browse')) && p() && e("Status"); // 步骤5:带反引号字段名处理 \ No newline at end of file diff --git a/module/common/test/model/printuserbar.php b/module/common/test/model/printuserbar.php deleted file mode 100755 index 767a025732..0000000000 --- a/module/common/test/model/printuserbar.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php -printUserBarTest(1)) && p() && e('1'); // 步骤1:验证方法存在 -r($commonTest->printUserBarTest(2)) && p() && e('1'); // 步骤2:验证方法为静态方法 -r($commonTest->printUserBarTest(3)) && p() && e('1'); // 步骤3:验证方法为公共方法 -r($commonTest->printUserBarTest(4)) && p() && e('1'); // 步骤4:验证参数数量为0 -r($commonTest->printUserBarTest(5)) && p() && e('1'); // 步骤5:验证方法可以被调用 \ No newline at end of file diff --git a/module/common/test/model/sendheader.php b/module/common/test/model/sendheader.php deleted file mode 100755 index 4126f0f611..0000000000 --- a/module/common/test/model/sendheader.php +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env php -objectModel, 'sendHeader' @1 -- 执行commonTest模块的sendHeaderTest方法,参数是'basic' @1 -- 执行commonTest模块的sendHeaderTest方法,参数是'security_headers' @1 -- 执行commonTest模块的sendHeaderTest方法,参数是'csp' @1 -- 执行commonTest模块的sendHeaderTest方法,参数是'xframe' @1 - -*/ - -include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; - -// 创建测试实例 -$commonTest = new commonModelTest(); - -// 备份原始配置 -global $config; -$originalCharset = isset($config->charset) ? $config->charset : 'UTF-8'; -$originalFramework = isset($config->framework) ? clone $config->framework : new stdClass(); -$originalCSPs = isset($config->CSPs) ? $config->CSPs : array(); -$originalXFrameOptions = isset($config->xFrameOptions) ? $config->xFrameOptions : ''; - -// 确保framework配置对象存在 -if(!isset($config->framework)) $config->framework = new stdClass(); - -r(method_exists($commonTest->objectModel, 'sendHeader')) && p() && e(1); -r($commonTest->sendHeaderTest('basic')) && p() && e(1); -r($commonTest->sendHeaderTest('security_headers')) && p() && e(1); -r($commonTest->sendHeaderTest('csp')) && p() && e(1); -r($commonTest->sendHeaderTest('xframe')) && p() && e(1); - -// 恢复原始配置 -$config->charset = $originalCharset; -$config->framework = $originalFramework; -$config->CSPs = $originalCSPs; -$config->xFrameOptions = $originalXFrameOptions; \ No newline at end of file diff --git a/module/common/test/model/setmainmenu.php b/module/common/test/model/setmainmenu.php deleted file mode 100755 index dd76b9f799..0000000000 --- a/module/common/test/model/setmainmenu.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -setMainMenuTest(1)) && p() && e('method_exists'); // 步骤1:验证方法存在性 -r($commonTest->setMainMenuTest(2)) && p() && e('is_static'); // 步骤2:验证方法为静态方法 -r($commonTest->setMainMenuTest(3)) && p() && e('return_bool'); // 步骤3:验证返回类型为bool -r($commonTest->setMainMenuTest(4)) && p() && e('no_parameters'); // 步骤4:验证无参数要求 -r($commonTest->setMainMenuTest(5)) && p() && e('is_public'); // 步骤5:验证方法为公共可访问 \ No newline at end of file diff --git a/module/common/test/model/setmenuvars.php b/module/common/test/model/setmenuvars.php deleted file mode 100755 index 54de3b308a..0000000000 --- a/module/common/test/model/setmenuvars.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -setMenuVarsTest(1)) && p() && e('browse-123'); // 步骤1:正常情况 -r($commonTest->setMenuVarsTest(2)) && p() && e('view-456.html'); // 步骤2:带html后缀链接 -r($commonTest->setMenuVarsTest(3)) && p() && e('browse-789'); // 步骤3:webMenu模式 -r($commonTest->setMenuVarsTest(4)) && p() && e('browse-999'); // 步骤4:空菜单项跳过 -r($commonTest->setMenuVarsTest(5)) && p() && e('1'); // 步骤5:homeMenu删除 \ No newline at end of file diff --git a/module/common/test/model/setmenuvarsex.php b/module/common/test/model/setmenuvarsex.php deleted file mode 100755 index 1e3e10698d..0000000000 --- a/module/common/test/model/setmenuvarsex.php +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env php -sortFeatureMenuTest(1)) && p() && e('1'); -r($commonTest->sortFeatureMenuTest(2)) && p() && e('1'); -r($commonTest->sortFeatureMenuTest(3)) && p() && e('1'); -r($commonTest->sortFeatureMenuTest(4)) && p() && e('2'); -r($commonTest->sortFeatureMenuTest(5)) && p() && e('1'); \ No newline at end of file diff --git a/module/common/test/model/replacemenulang.php b/module/common/test/tao/replacemenulang.php similarity index 96% rename from module/common/test/model/replacemenulang.php rename to module/common/test/tao/replacemenulang.php index 6baeb9cdc4..c944e45b68 100755 --- a/module/common/test/model/replacemenulang.php +++ b/module/common/test/tao/replacemenulang.php @@ -24,11 +24,11 @@ cid=15704 */ include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/model.class.php'; +include dirname(__FILE__, 2) . '/lib/tao.class.php'; su('admin'); -$commonTest = new commonModelTest(); +$commonTest = new commonTaoTest(); // 步骤1:测试没有 custom 数据时的处理 global $lang; @@ -75,4 +75,4 @@ if(!isset($lang->bug)) $lang->bug = new stdClass(); if(!isset($lang->bug->menu)) $lang->bug->menu = new stdClass(); $lang->bug->menu->view = array('link' => '查看|bug|view|bugID=%s'); r($commonTest->replaceMenuLangTest()) && p() && e('0'); -r($lang->bug->menu->view['link']) && p() && e('Bug查看|bug|view|bugID=%s'); \ No newline at end of file +r($lang->bug->menu->view['link']) && p() && e('Bug查看|bug|view|bugID=%s'); diff --git a/module/execution/test/lib/model.class.php b/module/execution/test/lib/model.class.php index 8dcd85a027..b03e34db59 100644 --- a/module/execution/test/lib/model.class.php +++ b/module/execution/test/lib/model.class.php @@ -17,10 +17,10 @@ class executionModelTest extends baseTest */ public function computeCFDTest($executionID = 0) { - $this->executionModel->computeCFD($executionID); + $this->instance->computeCFD($executionID); $today = helper::today(); - return $this->executionModel->dao->select('*')->from(TABLE_CFD) + return $this->instance->dao->select('*')->from(TABLE_CFD) ->where('date')->eq($today) ->beginIF(!empty($executionID))->andWhere('execution')->in($executionID)->fi() ->fetchAll('id'); @@ -35,7 +35,7 @@ class executionModelTest extends baseTest */ public function getFullNameListTest($executions = array()) { - $result = $this->executionModel->getFullNameList($executions); + $result = $this->instance->getFullNameList($executions); if(dao::isError()) return dao::getError(); return $result; @@ -54,7 +54,7 @@ class executionModelTest extends baseTest */ public function checkBeginAndEndDateTest(int $projectID, string $begin, string $end, int $parentID): bool|array { - $this->executionModel->checkBeginAndEndDate($projectID, $begin, $end, $parentID); + $this->instance->checkBeginAndEndDate($projectID, $begin, $end, $parentID); if(dao::isError()) return dao::getError(); return true; @@ -76,8 +76,8 @@ class executionModelTest extends baseTest $_POST['products'][0] = 1; $_POST['branch'][0] = array(); - $oldExecution = empty($executionID) ? '' : $this->executionModel->getByID($executionID); - $this->executionModel->checkWorkload($type, $percent, $oldExecution); + $oldExecution = empty($executionID) ? '' : $this->instance->getByID($executionID); + $this->instance->checkWorkload($type, $percent, $oldExecution); if(dao::isError()) return dao::getError(); return true; @@ -93,10 +93,10 @@ class executionModelTest extends baseTest */ public function setKanbanTest($executionID, $param = array()): array|object { - $object = $this->executionModel->dao->select('displayCards,fluidBoard,colWidth,minColWidth,maxColWidth')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch(); + $object = $this->instance->dao->select('displayCards,fluidBoard,colWidth,minColWidth,maxColWidth')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch(); foreach($param as $key => $value) $object->$key = $value; - $this->executionModel->setKanban($executionID, $object); + $this->instance->setKanban($executionID, $object); if(dao::isError()) { @@ -104,7 +104,7 @@ class executionModelTest extends baseTest } else { - return $this->executionModel->getByID($executionID); + return $this->instance->getByID($executionID); } } @@ -119,7 +119,7 @@ class executionModelTest extends baseTest public function setProjectSessionTest(int $executionID): int { unset($_SESSION['project']); - $this->executionModel->setProjectSession($executionID); + $this->instance->setProjectSession($executionID); return empty($_SESSION['project']) ? 0 : $_SESSION['project']; } @@ -132,7 +132,7 @@ class executionModelTest extends baseTest public function setProjectSessionTestWithStringInput(): int { unset($_SESSION['project']); - $this->executionModel->setProjectSession((int)'abc'); + $this->instance->setProjectSession((int)'abc'); return empty($_SESSION['project']) ? 0 : $_SESSION['project']; } @@ -146,7 +146,7 @@ class executionModelTest extends baseTest */ public function saveStateTest($executionID = 0, $executions = array()) { - return $this->executionModel->saveState($executionID, $executions); + return $this->instance->saveState($executionID, $executions); } /** @@ -158,7 +158,7 @@ class executionModelTest extends baseTest */ public function checkPrivTest($executionID) { - return $this->executionModel->checkPriv($executionID); + return $this->instance->checkPriv($executionID); } /** @@ -212,15 +212,15 @@ class executionModelTest extends baseTest foreach($createFields as $field => $defaultValue) $execution->$field = $defaultValue; foreach($param as $key => $value) $execution->$key = $value; - $this->executionModel->config->execution->create->requiredFields = 'project,name,code,begin,end'; - $objectID = $this->executionModel->create($execution, $teamMembers); + $this->instance->config->execution->create->requiredFields = 'project,name,code,begin,end'; + $objectID = $this->instance->create($execution, $teamMembers); if(dao::isError()) { return dao::getError(); } else { - $object = $this->executionModel->getByID($objectID); + $object = $this->instance->getByID($objectID); return $object; } } @@ -246,7 +246,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $_POST[$key] = $value; $_POST['uid'] = 'test'; - $change = $this->executionModel->update($objectID, (object)$_POST); + $change = $this->instance->update($objectID, (object)$_POST); if($change == array()) $change = '没有数据更新'; @@ -288,7 +288,7 @@ class executionModelTest extends baseTest foreach($createFields as $field => $defaultValue) $_POST[$field] = $defaultValue; foreach($param as $key => $value) $_POST[$key] = $value; - $object = $this->executionModel->batchUpdate((object)$_POST); + $object = $this->instance->batchUpdate((object)$_POST); unset($_POST); @@ -313,7 +313,7 @@ class executionModelTest extends baseTest */ public function batchChangeStatusObject($executionIdList = '', $status = '') { - $result = $this->executionModel->batchChangeStatus($executionIdList, $status); + $result = $this->instance->batchChangeStatus($executionIdList, $status); if(dao::isError()) { @@ -351,7 +351,7 @@ class executionModelTest extends baseTest $siblingList = array(); if($executionType == 'stage') $siblingList = $siblingStages[$executionID]; - $result = $this->executionModel->changeStatus2Wait($executionID, $selfAndChildren); + $result = $this->instance->changeStatus2Wait($executionID, $selfAndChildren); if(dao::isError()) { @@ -383,7 +383,7 @@ class executionModelTest extends baseTest $selfAndChildren = $selfAndChildrenList[$executionID]; - $result = $this->executionModel->changeStatus2Wait($executionID, $selfAndChildren); + $result = $this->instance->changeStatus2Wait($executionID, $selfAndChildren); if(dao::isError()) return dao::getError(); @@ -412,7 +412,7 @@ class executionModelTest extends baseTest $execution = $selfAndChildren[$executionID]; if(empty($execution)) return false; - $this->executionModel->changeStatus2Doing($executionID, $selfAndChildren); + $this->instance->changeStatus2Doing($executionID, $selfAndChildren); if(dao::isError()) { @@ -447,7 +447,7 @@ class executionModelTest extends baseTest $siblingList = array(); if($executionType == 'stage') $siblingList = $siblingStages[$executionID]; - $result = $this->executionModel->changeStatus2Inactive($executionID, $status, $selfAndChildren); + $result = $this->instance->changeStatus2Inactive($executionID, $status, $selfAndChildren); if(dao::isError()) { @@ -479,7 +479,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $_POST[$key] = $value; $_POST['uid'] = 'test'; - $obj = $this->executionModel->start($executionID, (object)$_POST); + $obj = $this->instance->start($executionID, (object)$_POST); unset($_POST); @@ -492,8 +492,8 @@ class executionModelTest extends baseTest if($testParent) { - $execution = $this->executionModel->getByID($executionID); - $executionParent = $this->executionModel->getByID($execution->parent); + $execution = $this->instance->getByID($executionID); + $executionParent = $this->instance->getByID($execution->parent); return $executionParent; } @@ -521,7 +521,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $_POST[$key] = $value; $_POST['uid'] = 'test'; - $obj = $this->executionModel->putoff($executionID, (object)$_POST); + $obj = $this->instance->putoff($executionID, (object)$_POST); unset($_POST); @@ -552,7 +552,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $_POST[$key] = $value; $_POST['uid'] = 'test'; - $obj = $this->executionModel->suspend($executionID, (object)$_POST); + $obj = $this->instance->suspend($executionID, (object)$_POST); unset($_POST); @@ -589,7 +589,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $_POST[$key] = $value; $_POST['uid'] = 'test'; - $obj = $this->executionModel->activate($executionID, (object)$_POST); + $obj = $this->instance->activate($executionID, (object)$_POST); unset($_POST); @@ -602,8 +602,8 @@ class executionModelTest extends baseTest { if($testParent) { - $execution = $this->executionModel->getByID($executionID); - $executionParent = $this->executionModel->getByID($execution->parent); + $execution = $this->instance->getByID($executionID); + $executionParent = $this->instance->getByID($execution->parent); return $executionParent; } return $obj; @@ -630,7 +630,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $_POST[$key] = $value; $_POST['uid'] = 'test'; - $obj = $this->executionModel->close($executionID, (object)$_POST); + $obj = $this->instance->close($executionID, (object)$_POST); unset($_POST); @@ -645,8 +645,8 @@ class executionModelTest extends baseTest { global $tester; $tester->loadModel('programplan')->computeProgress($executionID, 'close'); - $execution = $this->executionModel->getByID($executionID); - $executionParent = $this->executionModel->getByID($execution->parent); + $execution = $this->instance->getByID($executionID); + $executionParent = $this->instance->getByID($execution->parent); return $executionParent; } return $obj; @@ -665,7 +665,7 @@ class executionModelTest extends baseTest */ public function getPairsTest(int $projectID, int $count, string $mode = ''): array|int { - $object = $this->executionModel->getPairs($projectID, 'all', $mode); + $object = $this->instance->getPairs($projectID, 'all', $mode); if(dao::isError()) { @@ -691,7 +691,7 @@ class executionModelTest extends baseTest */ public function getByIDTest(int $executionID, bool $setImgSize = false): string|object|false { - $object = $this->executionModel->getByID($executionID, $setImgSize); + $object = $this->instance->getByID($executionID, $setImgSize); if(dao::isError()) { @@ -719,7 +719,7 @@ class executionModelTest extends baseTest */ public function getListTest(int $projectID, string $type, string $status, int $limit, int $productID, int $count): array|int { - $object = $this->executionModel->getList($projectID, $type, $status, $limit, $productID); + $object = $this->instance->getList($projectID, $type, $status, $limit, $productID); if(dao::isError()) { @@ -749,7 +749,7 @@ class executionModelTest extends baseTest */ public function getInvolvedExecutionListTest(int $projectID, int $limit, int $productID, int $count): array|int { - $object = $this->executionModel->getInvolvedExecutionList($projectID, $status = 'involved', $limit, $productID); + $object = $this->instance->getInvolvedExecutionList($projectID, $status = 'involved', $limit, $productID); if(dao::isError()) { @@ -782,7 +782,7 @@ class executionModelTest extends baseTest */ public function getByProjectTest(int $projectID, string $status, int $limit, bool $pairs = false, bool $devel = false, int $appendedID = 0, int $count = 0): array|int { - $object = $this->executionModel->getByProject($projectID, $status, $limit, $pairs, $devel, $appendedID); + $object = $this->instance->getByProject($projectID, $status, $limit, $pairs, $devel, $appendedID); if(dao::isError()) { @@ -810,7 +810,7 @@ class executionModelTest extends baseTest */ public function getIdListTest(int $projectID, int $count): array|int { - $object = $this->executionModel->getIdList($projectID); + $object = $this->instance->getIdList($projectID); if(dao::isError()) { @@ -843,7 +843,7 @@ class executionModelTest extends baseTest */ public function getStatDataTest($projectID = 0, $browseType = 'undone', $productID = 0, $branch = 0, $withTasks = false, $param = '', $orderBy = 'id_asc', $pager = null) { - $objects = $this->executionModel->getStatData($projectID); + $objects = $this->instance->getStatData($projectID); return count($objects); } @@ -857,7 +857,7 @@ class executionModelTest extends baseTest */ public function getBranchesTest($executionID, $count) { - $object = $this->executionModel->getBranches($executionID); + $object = $this->instance->getBranches($executionID); if(dao::isError()) { @@ -892,7 +892,7 @@ class executionModelTest extends baseTest if($executionID > 100) return false; // 不存在的ID try { - $object = $this->executionModel->getTree($executionID); + $object = $this->instance->getTree($executionID); } catch(Exception $e) { return false; } @@ -941,7 +941,7 @@ class executionModelTest extends baseTest */ public function getRelatedExecutionsTest($executionID, $count) { - $object = $this->executionModel->getRelatedExecutions($executionID); + $object = $this->instance->getRelatedExecutions($executionID); if(dao::isError()) { @@ -969,7 +969,7 @@ class executionModelTest extends baseTest */ public function getChildExecutionsTest($executionID, $count): array|int { - $object = $this->executionModel->getChildExecutions($executionID); + $object = $this->instance->getChildExecutions($executionID); if(dao::isError()) { @@ -994,7 +994,7 @@ class executionModelTest extends baseTest */ public function getLimitedExecutionTest() { - return $this->executionModel->getLimitedExecution(); + return $this->instance->getLimitedExecution(); } /** @@ -1018,7 +1018,7 @@ class executionModelTest extends baseTest $execution = $tester->dbh->query("select * from zt_project where id = $executionID")->fetch(); $executions = array($executionID => $execution->name); - $object = $this->executionModel->getTasks($productID, $executionID, $executions, $browseType, $queryID, $moduleID, $sort); + $object = $this->instance->getTasks($productID, $executionID, $executions, $browseType, $queryID, $moduleID, $sort); if(dao::isError()) { @@ -1045,7 +1045,7 @@ class executionModelTest extends baseTest */ public function getTaskGroupByExecutionTest($executionIdList = array(), $showCount = true) { - $objects = $this->executionModel->getTaskGroupByExecution($executionIdList); + $objects = $this->instance->getTaskGroupByExecution($executionIdList); return $showCount ? count($objects) : $objects; } @@ -1060,7 +1060,7 @@ class executionModelTest extends baseTest */ public function getBranchByProductTest(int $productID, int $count): array|int { - $object = $this->executionModel->getBranchByProduct(array($productID)); + $object = $this->instance->getBranchByProduct(array($productID)); if(dao::isError()) { @@ -1089,7 +1089,7 @@ class executionModelTest extends baseTest */ public function getOrderedExecutionsTest(int $executionID, string $status, int $count): array|int { - $object = $this->executionModel->getOrderedExecutions($executionID, $status); + $object = $this->instance->getOrderedExecutions($executionID, $status); if(dao::isError()) { @@ -1112,7 +1112,7 @@ class executionModelTest extends baseTest */ public function getToImportTest(array $executionIdList, string $type, int $count): array|int { - $object = $this->executionModel->getToImport($executionIdList, $type); + $object = $this->instance->getToImport($executionIdList, $type); if(dao::isError()) { @@ -1146,7 +1146,7 @@ class executionModelTest extends baseTest foreach($param as $key => $value) $postData->$key = $value; - $this->executionModel->updateProducts($executionID, $postData); + $this->instance->updateProducts($executionID, $postData); if(dao::isError()) { @@ -1155,7 +1155,7 @@ class executionModelTest extends baseTest } else { - return $this->executionModel->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($executionID)->fetchAll(); + return $this->instance->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($executionID)->fetchAll(); } } @@ -1169,8 +1169,8 @@ class executionModelTest extends baseTest */ public function getTasks2ImportedTest($toExecution, $count) { - $branches = $this->executionModel->getBranches($toExecution); - $object = $this->executionModel->getTasks2Imported($toExecution, $branches); + $branches = $this->instance->getBranches($toExecution); + $object = $this->instance->getTasks2Imported($toExecution, $branches); if(dao::isError()) { @@ -1199,7 +1199,7 @@ class executionModelTest extends baseTest */ public function importTaskTest(int $executionID, int $count, array $taskIdList = array()): array|int { - $this->executionModel->importTask($executionID, $taskIdList); + $this->instance->importTask($executionID, $taskIdList); if(dao::isError()) { @@ -1208,12 +1208,12 @@ class executionModelTest extends baseTest } elseif($count == 1) { - $taskList = $this->executionModel->dao->select('*')->from(TABLE_TASK)->where('execution')->eq($executionID)->fetchAll(); + $taskList = $this->instance->dao->select('*')->from(TABLE_TASK)->where('execution')->eq($executionID)->fetchAll(); return count($taskList); } else { - $taskList = $this->executionModel->dao->select('*')->from(TABLE_TASK)->where('execution')->eq($executionID)->fetchAll(); + $taskList = $this->instance->dao->select('*')->from(TABLE_TASK)->where('execution')->eq($executionID)->fetchAll(); return $taskList; } } @@ -1234,8 +1234,8 @@ class executionModelTest extends baseTest $dateExceed = array(); $taskStories = array(); $parents = array(); - $execution = $this->executionModel->fetchByID($executionID); - $tasks = $this->executionModel->loadModel('task')->getByIdList($taskIdList); + $execution = $this->instance->fetchByID($executionID); + $tasks = $this->instance->loadModel('task')->getByIdList($taskIdList); $assignedToes = array(); foreach($tasks as $task) { @@ -1245,9 +1245,9 @@ class executionModelTest extends baseTest if($task->parent < 0) $parents[$task->id] = $task->id; } - $this->executionModel->afterImportTask($execution, $parents, $assignedToes, $taskStories); + $this->instance->afterImportTask($execution, $parents, $assignedToes, $taskStories); - $teams = $this->executionModel->dao->select('*')->from(TABLE_TEAM)->where('type')->eq('execution')->andWhere('root')->eq($executionID)->fetchAll(); + $teams = $this->instance->dao->select('*')->from(TABLE_TEAM)->where('type')->eq('execution')->andWhere('root')->eq($executionID)->fetchAll(); return $count ? count($teams) : $teams; } @@ -1261,7 +1261,7 @@ class executionModelTest extends baseTest */ public function statRelatedDataTest(int $executionID): object|array { - $object = $this->executionModel->statRelatedData($executionID); + $object = $this->instance->statRelatedData($executionID); if(dao::isError()) { @@ -1285,13 +1285,13 @@ class executionModelTest extends baseTest */ public function importBugTest(int $executionID, array $postData): array|bool { - $this->executionModel->loadModel('task'); + $this->instance->loadModel('task'); $tasks = array(); - $execution = $this->executionModel->getByID($executionID); - $bugs = $this->executionModel->loadModel('bug')->getByIdList(array_keys($postData)); - $showAllModule = isset($this->executionModel->config->execution->task->allModule) ? $this->executionModel->config->execution->task->allModule : ''; - $modules = $this->executionModel->loadModel('tree')->getTaskOptionMenu($execution->id, 0, $showAllModule ? 'allModule' : ''); + $execution = $this->instance->getByID($executionID); + $bugs = $this->instance->loadModel('bug')->getByIdList(array_keys($postData)); + $showAllModule = isset($this->instance->config->execution->task->allModule) ? $this->instance->config->execution->task->allModule : ''; + $modules = $this->instance->loadModel('tree')->getTaskOptionMenu($execution->id, 0, $showAllModule ? 'allModule' : ''); $now = helper::now(); foreach($postData as $bugID => $task) { @@ -1311,12 +1311,12 @@ class executionModelTest extends baseTest $task->consumed = 0; $task->status = 'wait'; $task->openedDate = $now; - $task->openedBy = $this->executionModel->app->user->account; + $task->openedBy = $this->instance->app->user->account; $tasks[$bugID] = $task; } - return $this->executionModel->importBug($tasks); + return $this->instance->importBug($tasks); } /** @@ -1332,10 +1332,10 @@ class executionModelTest extends baseTest */ public function changeProjectTest(int $newProjectID, int $oldProjectID, int $executionID, string $syncStories = 'no'): array|object { - $this->executionModel->changeProject($newProjectID, $oldProjectID, $executionID, $syncStories); + $this->instance->changeProject($newProjectID, $oldProjectID, $executionID, $syncStories); if(dao::isError()) return dao::getError(); - return $this->executionModel->dao->select('parent,path')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch(); + return $this->instance->dao->select('parent,path')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch(); } /** @@ -1350,13 +1350,13 @@ class executionModelTest extends baseTest public function linkStoryTest(int $executionID, int $count, array $stories = array()): array|int { - $this->executionModel->dao->delete()->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->exec(); - $this->executionModel->linkStory($executionID, $stories); + $this->instance->dao->delete()->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->exec(); + $this->instance->linkStory($executionID, $stories); if(dao::isError()) return dao::getError(); - if($count == 1) return count($this->executionModel->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll()); - return $this->executionModel->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); + if($count == 1) return count($this->instance->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll()); + return $this->instance->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); } /** @@ -1371,19 +1371,19 @@ class executionModelTest extends baseTest */ public function linkStoriesTest(int $executionID, int $productID = 0, int $planID = 0): int { - if($planID) $this->executionModel->dao->update(TABLE_PROJECTPRODUCT)->set('plan')->eq($planID)->where('project')->eq($executionID)->andWhere('product')->eq($productID)->exec(); + if($planID) $this->instance->dao->update(TABLE_PROJECTPRODUCT)->set('plan')->eq($planID)->where('project')->eq($executionID)->andWhere('product')->eq($productID)->exec(); - $result = $this->executionModel->linkStories($executionID); + $result = $this->instance->linkStories($executionID); if(dao::isError()) return 0; if($productID > 0) { - $objects = $this->executionModel->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->andWhere('product')->eq($productID)->fetchAll(); + $objects = $this->instance->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->andWhere('product')->eq($productID)->fetchAll(); return count($objects); } else { - $objects = $this->executionModel->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); + $objects = $this->instance->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); return count($objects); } } @@ -1401,12 +1401,12 @@ class executionModelTest extends baseTest */ public function linkCasesTest(int $executionID, int $productID, int $storyID, int $count): array|int { - $this->executionModel->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->exec(); - $this->executionModel->linkCases($executionID, $productID, $storyID); + $this->instance->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->exec(); + $this->instance->linkCases($executionID, $productID, $storyID); if(dao::isError()) return dao::getError(); - $objects = $this->executionModel->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->fetchAll(); + $objects = $this->instance->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->fetchAll(); return $count ? count($objects) : $objects; } @@ -1423,21 +1423,21 @@ class executionModelTest extends baseTest */ public function unlinkStoryTest(int $executionID, int $storyID, array $stories, int $count): array|int { - $this->executionModel->dao->delete()->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->exec(); + $this->instance->dao->delete()->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->exec(); - $this->executionModel->linkStory($executionID, $stories); - $this->executionModel->unlinkStory($executionID, $storyID); + $this->instance->linkStory($executionID, $stories); + $this->instance->unlinkStory($executionID, $storyID); if(dao::isError()) return dao::getError(); if($count == 1) { - $object = $this->executionModel->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); + $object = $this->instance->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); return count($object); } else { - return $this->executionModel->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); + return $this->instance->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); } } @@ -1453,10 +1453,10 @@ class executionModelTest extends baseTest */ public function unlinkCasesTest(int $executionID, int $productID, int $storyID): array { - $this->executionModel->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->exec(); + $this->instance->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->exec(); - $this->executionModel->linkCases($executionID, $productID, $storyID); - $this->executionModel->unlinkCases($executionID, $storyID); + $this->instance->linkCases($executionID, $productID, $storyID); + $this->instance->unlinkCases($executionID, $storyID); if(dao::isError()) { @@ -1464,7 +1464,7 @@ class executionModelTest extends baseTest } else { - return $this->executionModel->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->fetchAll(); + return $this->instance->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->fetchAll(); } } @@ -1479,7 +1479,7 @@ class executionModelTest extends baseTest */ public function getTeamMembersTest(int $executionID, int $count): int|array { - $object = $this->executionModel->getTeamMembers($executionID); + $object = $this->instance->getTeamMembers($executionID); if(dao::isError()) { @@ -1506,7 +1506,7 @@ class executionModelTest extends baseTest */ public function getMembersByIdListTest($executionIdList, $count) { - $object = $this->executionModel->getMembersByIdList($executionIdList); + $object = $this->instance->getMembersByIdList($executionIdList); if(dao::isError()) { @@ -1534,7 +1534,7 @@ class executionModelTest extends baseTest */ public function getMembers2ImportTest(int $executionID, array $currentMembers, int $count): int|string|array { - $object = $this->executionModel->getMembers2Import($executionID, $currentMembers); + $object = $this->instance->getMembers2Import($executionID, $currentMembers); if(dao::isError()) { @@ -1569,7 +1569,7 @@ class executionModelTest extends baseTest */ public function getCanCopyObjectsTest(int $projectID = 0, int $count = 0): array|int|string { - $object = $this->executionModel->getCanCopyObjects($projectID); + $object = $this->instance->getCanCopyObjects($projectID); if(dao::isError()) { @@ -1605,7 +1605,7 @@ class executionModelTest extends baseTest */ public function manageMembersTest(int $executionID, int $count, array $params = array()): array|string|int { - $this->executionModel->dao->delete()->from(TABLE_TEAM)->where('root')->eq($executionID)->exec(); + $this->instance->dao->delete()->from(TABLE_TEAM)->where('root')->eq($executionID)->exec(); $members = array(); foreach($params as $key => $valueList) @@ -1617,10 +1617,10 @@ class executionModelTest extends baseTest } } - $execution = $this->executionModel->getByID($executionID); - $this->executionModel->manageMembers($execution, $members); + $execution = $this->instance->getByID($executionID); + $this->instance->manageMembers($execution, $members); - $objects = $this->executionModel->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->orderBy('id_asc')->fetchAll(); + $objects = $this->instance->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->orderBy('id_asc')->fetchAll(); if(dao::isError()) { @@ -1655,12 +1655,12 @@ class executionModelTest extends baseTest */ public function addProjectMembersTest(int $projectID = 0, int $executionID = 0, int $count = 0): array|int { - $this->executionModel->dao->delete()->from(TABLE_TEAM)->where('root')->eq($projectID)->exec(); - $executionMembers = $this->executionModel->dao->select('`root`,`account`,`join`,`role`,`days`,`type`,`hours`')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll('account'); + $this->instance->dao->delete()->from(TABLE_TEAM)->where('root')->eq($projectID)->exec(); + $executionMembers = $this->instance->dao->select('`root`,`account`,`join`,`role`,`days`,`type`,`hours`')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll('account'); - $this->executionModel->addProjectMembers($projectID, $executionMembers); + $this->instance->addProjectMembers($projectID, $executionMembers); - $object = $this->executionModel->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($projectID)->fetchAll(); + $object = $this->instance->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($projectID)->fetchAll(); if(dao::isError()) { @@ -1692,7 +1692,7 @@ class executionModelTest extends baseTest global $tester; $oldObject = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll(); - $this->executionModel->unlinkMember($executionID, $account); + $this->instance->unlinkMember($executionID, $account); $object = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll(); @@ -1727,7 +1727,7 @@ class executionModelTest extends baseTest */ public function computeBurnTest($executionID = '') { - $result = $this->executionModel->computeBurn($executionID); + $result = $this->instance->computeBurn($executionID); if(dao::isError()) return dao::getError(); return $result; @@ -1759,12 +1759,12 @@ class executionModelTest extends baseTest $burnData->$key = $value; } - $this->executionModel->computeBurn(); - $this->executionModel->fixFirst($burnData); + $this->instance->computeBurn(); + $this->instance->fixFirst($burnData); unset($_POST); - $object = $this->executionModel->dao->select('*')->from(TABLE_BURN)->where('execution')->eq($executionID)->andWhere('date')->eq($date)->fetchAll(); + $object = $this->instance->dao->select('*')->from(TABLE_BURN)->where('execution')->eq($executionID)->andWhere('date')->eq($date)->fetchAll(); if(dao::isError()) { @@ -1797,9 +1797,9 @@ class executionModelTest extends baseTest public function getBurnDataFlotTest(int $executionID, string $burnBy, bool $showDelay = false, string $begin = '', string $end = ''):array|null { $dateList = array(); - if($begin && $end) list($dateList) = $this->executionModel->getDateList($begin, $end, 'noweekend', 0, 'Y-m-d'); + if($begin && $end) list($dateList) = $this->instance->getDateList($begin, $end, 'noweekend', 0, 'Y-m-d'); - $object = $this->executionModel->getBurnDataFlot($executionID, $burnBy, $showDelay, $dateList); + $object = $this->instance->getBurnDataFlot($executionID, $burnBy, $showDelay, $dateList); if(dao::isError()) { @@ -1822,10 +1822,10 @@ class executionModelTest extends baseTest */ public function getBurnDataTest(int $executionID = 0): string|array { - $execution = $this->executionModel->getByID($executionID); + $execution = $this->instance->getByID($executionID); if(empty($execution)) return '0'; - $object = $this->executionModel->getBurnData(array($executionID => $execution)); + $object = $this->instance->getBurnData(array($executionID => $execution)); if(dao::isError()) { @@ -1852,8 +1852,8 @@ class executionModelTest extends baseTest */ public function processBurnDataTest(int $executionID, int $itemCounts, string $begin, string $end, int $count): array|int { - $dateList = $this->executionModel->dao->select('execution, `date` as name, `left` as value')->from(TABLE_BURN)->where('execution')->eq($executionID)->fetchAll('name'); - $object = $this->executionModel->processBurnData($dateList, $itemCounts, $begin, $end); + $dateList = $this->instance->dao->select('execution, `date` as name, `left` as value')->from(TABLE_BURN)->where('execution')->eq($executionID)->fetchAll('name'); + $object = $this->instance->processBurnData($dateList, $itemCounts, $begin, $end); if(dao::isError()) { @@ -1880,7 +1880,7 @@ class executionModelTest extends baseTest */ public function summaryTest($tasks): string { - $result = $this->executionModel->summary($tasks); + $result = $this->instance->summary($tasks); if(dao::isError()) return dao::getError(); @@ -1898,7 +1898,7 @@ class executionModelTest extends baseTest */ public function isClickableTest(object $execution, string $action): string { - $object = $this->executionModel->isClickable($execution, $action); + $object = $this->instance->isClickable($execution, $action); if(dao::isError()) { @@ -1932,7 +1932,7 @@ class executionModelTest extends baseTest */ public function getDateListTest(string $begin, string $end, string $type, int $count, int|string $interval = 0): array|string|int { - $object = $this->executionModel->getDateList($begin, $end, $type, $interval); + $object = $this->instance->getDateList($begin, $end, $type, $interval); if(dao::isError()) { @@ -1967,7 +1967,7 @@ class executionModelTest extends baseTest { global $tester; - $this->executionModel->fixOrder(); + $this->instance->fixOrder(); $object = $tester->dao->select('id,`order`')->from(TABLE_EXECUTION)->fetchAll('id'); @@ -1987,7 +1987,7 @@ class executionModelTest extends baseTest */ public function getKanbanTasksTest(int $executionID, int $count, array $excludeTasks = array()): array|int { - $object = $this->executionModel->getKanbanTasks($executionID, 'id_desc', $excludeTasks); + $object = $this->instance->getKanbanTasks($executionID, 'id_desc', $excludeTasks); if(dao::isError()) { @@ -2013,7 +2013,7 @@ class executionModelTest extends baseTest */ public function getKanbanSettingTest($param = 0) { - $object = $this->executionModel->getKanbanSetting(); + $object = $this->instance->getKanbanSetting(); if(dao::isError()) { @@ -2070,18 +2070,18 @@ class executionModelTest extends baseTest break; case 'count_default': $kanbanSetting->allCols = false; - $result = $this->executionModel->getKanbanColumns($kanbanSetting); + $result = $this->instance->getKanbanColumns($kanbanSetting); return count($result); case 'count_all': $kanbanSetting->allCols = true; - $result = $this->executionModel->getKanbanColumns($kanbanSetting); + $result = $this->instance->getKanbanColumns($kanbanSetting); return count($result); case 'empty': // 空对象,不设置allCols属性 break; } - $result = $this->executionModel->getKanbanColumns($kanbanSetting); + $result = $this->instance->getKanbanColumns($kanbanSetting); if(dao::isError()) return dao::getError(); return $result; @@ -2096,8 +2096,8 @@ class executionModelTest extends baseTest */ public function getKanbanStatusMapTest($count) { - $kanbanSetting = $this->executionModel->getKanbanSetting(); - $object = $this->executionModel->getKanbanStatusMap($kanbanSetting); + $kanbanSetting = $this->instance->getKanbanSetting(); + $object = $this->instance->getKanbanStatusMap($kanbanSetting); if(dao::isError()) { @@ -2123,8 +2123,8 @@ class executionModelTest extends baseTest */ public function getKanbanStatusListTest($count) { - $kanbanSetting = $this->executionModel->getKanbanSetting(); - $object = $this->executionModel->getKanbanStatusList($kanbanSetting); + $kanbanSetting = $this->instance->getKanbanSetting(); + $object = $this->instance->getKanbanStatusList($kanbanSetting); if(dao::isError()) { @@ -2152,14 +2152,14 @@ class executionModelTest extends baseTest { if($testType === 'default') { - $kanbanSetting = $this->executionModel->getKanbanSetting(); - $object = $this->executionModel->getKanbanColorList($kanbanSetting); + $kanbanSetting = $this->instance->getKanbanSetting(); + $object = $this->instance->getKanbanColorList($kanbanSetting); } elseif($testType === 'empty') { $kanbanSetting = new stdclass(); $kanbanSetting->colorList = array(); - $object = $this->executionModel->getKanbanColorList($kanbanSetting); + $object = $this->instance->getKanbanColorList($kanbanSetting); return count($object); } elseif($testType === 'custom') @@ -2170,24 +2170,24 @@ class executionModelTest extends baseTest 'doing' => '#00FF00', 'done' => '#0000FF' ); - $object = $this->executionModel->getKanbanColorList($kanbanSetting); + $object = $this->instance->getKanbanColorList($kanbanSetting); } elseif($testType === 'count') { - $kanbanSetting = $this->executionModel->getKanbanSetting(); - $object = $this->executionModel->getKanbanColorList($kanbanSetting); + $kanbanSetting = $this->instance->getKanbanSetting(); + $object = $this->instance->getKanbanColorList($kanbanSetting); return count($object); } elseif($testType === 'specific_color') { - $kanbanSetting = $this->executionModel->getKanbanSetting(); - $object = $this->executionModel->getKanbanColorList($kanbanSetting); + $kanbanSetting = $this->instance->getKanbanSetting(); + $object = $this->instance->getKanbanColorList($kanbanSetting); return isset($object['wait']) ? $object['wait'] : false; } elseif($testType === 'all_keys') { - $kanbanSetting = $this->executionModel->getKanbanSetting(); - $object = $this->executionModel->getKanbanColorList($kanbanSetting); + $kanbanSetting = $this->instance->getKanbanSetting(); + $object = $this->instance->getKanbanColorList($kanbanSetting); $expectedKeys = array('wait', 'doing', 'pause', 'done', 'cancel', 'closed'); $actualKeys = array_keys($object); sort($expectedKeys); @@ -2220,8 +2220,8 @@ class executionModelTest extends baseTest $begin = '2022-01-07'; $end = '2022-01-17'; - $dateList = $this->executionModel->getDateList($begin, $end, $type, 0, 'Y-m-d'); - $object = $this->executionModel->buildBurnData($executionID, $dateList[0], $burnBy); + $dateList = $this->instance->getDateList($begin, $end, $type, 0, 'Y-m-d'); + $object = $this->instance->buildBurnData($executionID, $dateList[0], $burnBy); if(dao::isError()) { @@ -2251,7 +2251,7 @@ class executionModelTest extends baseTest */ public function getPlansTest(array $productIdList, string $param, int $executionID, int $count): array|int { - $object = $this->executionModel->getPlans($productIdList, $param, $executionID); + $object = $this->instance->getPlans($productIdList, $param, $executionID); if(dao::isError()) { @@ -2278,7 +2278,7 @@ class executionModelTest extends baseTest */ public function getStageLinkProductPairsTest($projects, $count) { - $object = $this->executionModel->getStageLinkProductPairs($projects); + $object = $this->instance->getStageLinkProductPairs($projects); if(dao::isError()) { @@ -2306,7 +2306,7 @@ class executionModelTest extends baseTest { global $tester; - $this->executionModel->setTreePath($executionID); + $this->instance->setTreePath($executionID); $object = $tester->dao->select('id,project,parent,path')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetchAll('id'); @@ -2333,8 +2333,8 @@ class executionModelTest extends baseTest { global $tester; - $execution = $this->executionModel->getByID($executionID); - $object = $this->executionModel->getBeginEnd4CFD($execution); + $execution = $this->instance->getByID($executionID); + $object = $this->instance->getBeginEnd4CFD($execution); $object[0] = $object[0] == date('Y-m-d', strtotime('-13 days', time())) ? 1 : 0; $object[1] = $object[1] == helper::today() ? 1 : 0; @@ -2369,7 +2369,7 @@ class executionModelTest extends baseTest $tester->app->loadClass('pager', $static = true); $pager = new pager(0, $recPerPage, 1); - $objects = $this->executionModel->getSearchTasks($condition, $orderBy, $pager); + $objects = $this->instance->getSearchTasks($condition, $orderBy, $pager); if(dao::isError()) return dao::getError(); return $objects; @@ -2387,7 +2387,7 @@ class executionModelTest extends baseTest */ public function getKanbanGroupDataTest($stories, $tasks, $bugs, $type = 'story') { - $object = $this->executionModel->getKanbanGroupData($stories, $tasks, $bugs, $type); + $object = $this->instance->getKanbanGroupData($stories, $tasks, $bugs, $type); if(dao::isError()) { @@ -2408,7 +2408,7 @@ class executionModelTest extends baseTest */ public function getPrevKanbanTest(int $executionID): array|string|null { - $result = $this->executionModel->getPrevKanban($executionID); + $result = $this->instance->getPrevKanban($executionID); if(dao::isError()) { @@ -2438,7 +2438,7 @@ class executionModelTest extends baseTest global $tester; $contents = array('story', 'wait', 'doing', 'done', 'cancel'); $stories = $tester->loadModel('story')->getExecutionStories($executionID, 0, 'id_asc'); - $kanbanTasks = $this->executionModel->getKanbanTasks($executionID, "id"); + $kanbanTasks = $this->instance->getKanbanTasks($executionID, "id"); $kanbanBugs = $tester->loadModel('bug')->getExecutionBugs($executionID); $users = array(); $taskAndBugs = array(); @@ -2469,7 +2469,7 @@ class executionModelTest extends baseTest $kanbanDataList = $datas; } - $object = $this->executionModel->saveKanbanData($executionID, $kanbanDataList); + $object = $this->instance->saveKanbanData($executionID, $kanbanDataList); if(dao::isError()) { @@ -2478,7 +2478,7 @@ class executionModelTest extends baseTest } else { - $result = $this->executionModel->getPrevKanban($executionID); + $result = $this->instance->getPrevKanban($executionID); return !$result ? 'empty' : $result; } } @@ -2495,7 +2495,7 @@ class executionModelTest extends baseTest */ public function updateUserViewTest(int $executionID, string $objectType = 'sprint', array $users = array()): string|array { - $this->executionModel->updateUserView($executionID, $objectType, $users); + $this->instance->updateUserView($executionID, $objectType, $users); if(dao::isError()) { @@ -2523,7 +2523,7 @@ class executionModelTest extends baseTest if(empty($projectID) || !is_numeric($projectID)) return 0; // 获取项目信息,如果不存在则返回0 - $project = $this->executionModel->fetchByID($projectID); + $project = $this->instance->fetchByID($projectID); if(empty($project)) return 0; // 为项目对象添加缺失的必需字段 @@ -2561,14 +2561,14 @@ class executionModelTest extends baseTest $executionData->whitelist = ''; $executionData->plans = array(); $executionData->hasProduct = $project->hasProduct; - $executionData->openedBy = $this->executionModel->app->user->account; + $executionData->openedBy = $this->instance->app->user->account; $executionData->openedDate = helper::now(); $executionData->parent = $projectID; $executionData->isTpl = $project->isTpl; if($project->code) $executionData->code = $project->code; try { - $executionID = $this->executionModel->create($executionData, array($this->executionModel->app->user->account)); + $executionID = $this->instance->create($executionData, array($this->instance->app->user->account)); if(dao::isError()) return 0; return $executionID ? $executionID : 0; } catch(Exception $e) { @@ -2586,10 +2586,10 @@ class executionModelTest extends baseTest */ public function setMenuTest($executionID = 0): object|string { - $execution = $this->executionModel->getByID($executionID); + $execution = $this->instance->getByID($executionID); if(empty($execution)) return '0'; - $this->executionModel->setMenu($executionID); + $this->instance->setMenu($executionID); global $lang; return $lang->execution->menu; @@ -2604,8 +2604,8 @@ class executionModelTest extends baseTest */ public function syncNoMultipleSprintTest(int $projectID): string|object { - $executionID = $this->executionModel->syncNoMultipleSprint($projectID); - return !$executionID ? '' : $this->executionModel->fetchByID($executionID); + $executionID = $this->instance->syncNoMultipleSprint($projectID); + return !$executionID ? '' : $this->instance->fetchByID($executionID); } /** @@ -2617,7 +2617,7 @@ class executionModelTest extends baseTest */ public function buildSearchFormTest($queryID) { - $this->executionModel->buildSearchForm($queryID, 'searchUrl'); + $this->instance->buildSearchForm($queryID, 'searchUrl'); return $_SESSION['executionsearchParams']['queryID']; } @@ -2633,8 +2633,8 @@ class executionModelTest extends baseTest { global $app; $app->moduleName = 'task'; - $tree = $this->executionModel->getTree($executionID); - return $this->executionModel->buildTree($tree); + $tree = $this->instance->getTree($executionID); + return $this->instance->buildTree($tree); } /** @@ -2648,7 +2648,7 @@ class executionModelTest extends baseTest */ public function buildTreeTestDirect(array $trees, bool $hasProduct = true, array $gradeGroup = array()): array { - $result = $this->executionModel->buildTree($trees, $hasProduct, $gradeGroup); + $result = $this->instance->buildTree($trees, $hasProduct, $gradeGroup); if(dao::isError()) return dao::getError(); return $result; @@ -2698,7 +2698,7 @@ class executionModelTest extends baseTest $fullTrees = $this->treeModel->getTaskStructure($executionID, 0); if(empty($fullTrees)) return '0'; - return $this->executionModel->fillTasksInTree((object)$fullTrees[0], $executionID); + return $this->instance->fillTasksInTree((object)$fullTrees[0], $executionID); } /** @@ -2715,7 +2715,7 @@ class executionModelTest extends baseTest */ public function buildTaskSearchFormTest($executionID, $executions, $queryID, $actionURL, $module, $cacheSearchFunc): array { - return $this->executionModel->buildTaskSearchForm($executionID, $executions, $queryID, $actionURL, $module, $cacheSearchFunc); + return $this->instance->buildTaskSearchForm($executionID, $executions, $queryID, $actionURL, $module, $cacheSearchFunc); } /** @@ -2733,8 +2733,8 @@ class executionModelTest extends baseTest $product = $this->productModel->getByID($productID); if(empty($product)) return 0; - $this->executionModel->loadModel('bug'); - $this->executionModel->buildBugSearchForm(array($productID => $product), $queryID, 'searchBug', $type); + $this->instance->loadModel('bug'); + $this->instance->buildBugSearchForm(array($productID => $product), $queryID, 'searchBug', $type); return $_SESSION['executionBugsearchParams']['queryID']; } @@ -2750,13 +2750,13 @@ class executionModelTest extends baseTest */ public function buildStorySearchFormTest(int $executionID, int $queryID): int { - $execution = $this->executionModel->getByID($executionID); + $execution = $this->instance->getByID($executionID); if(empty($execution)) return 0; - $this->executionModel->loadModel('story'); - $products = $this->executionModel->loadModel('product')->getProducts($executionID); - $branchGroups = $this->executionModel->loadModel('branch')->getByProducts(array_keys($products)); - $this->executionModel->buildStorySearchForm($products, $branchGroups, array(), $queryID, 'searchStory', 'executionStory', $execution); + $this->instance->loadModel('story'); + $products = $this->instance->loadModel('product')->getProducts($executionID); + $branchGroups = $this->instance->loadModel('branch')->getByProducts(array_keys($products)); + $this->instance->buildStorySearchForm($products, $branchGroups, array(), $queryID, 'searchStory', 'executionStory', $execution); return $_SESSION['executionStorysearchParams']['queryID']; } @@ -2778,7 +2778,7 @@ class executionModelTest extends baseTest $dateList = array(); for($date = $begin; $date <= $end; $date += 24 * 3600) $dateList[] = date('Y-m-d', $date); - return $this->executionModel->getCFDData($executionID, $dateList, $type); + return $this->instance->getCFDData($executionID, $dateList, $type); } /** @@ -2798,7 +2798,7 @@ class executionModelTest extends baseTest $dateList = array(); for($date = $begin; $date <= $end; $date += 24 * 3600) $dateList[] = date('Y-m-d', $date); - return $this->executionModel->buildCFDData($executionID, $dateList, $type); + return $this->instance->buildCFDData($executionID, $dateList, $type); } /** @@ -2812,9 +2812,9 @@ class executionModelTest extends baseTest */ public function updateCFDDataTest(int $executionID, string $date): array { - $this->executionModel->updateCFDData($executionID, $date); + $this->instance->updateCFDData($executionID, $date); - return $this->executionModel->dao->select("date, `count` AS value, `name`")->from(TABLE_CFD) + return $this->instance->dao->select("date, `count` AS value, `name`")->from(TABLE_CFD) ->where('execution')->eq((int)$executionID) ->andWhere('date')->eq($date) ->orderBy('date DESC, id asc')->fetchGroup('name', 'date'); @@ -2829,7 +2829,7 @@ class executionModelTest extends baseTest */ public function buildExecutionByStatusTest($status) { - return $this->executionModel->buildExecutionByStatus($status); + return $this->instance->buildExecutionByStatus($status); } /** @@ -2845,14 +2845,14 @@ class executionModelTest extends baseTest { $executions = array(); $executionIDList = ''; - $executions = $this->executionModel->dao->select('*')->from(TABLE_EXECUTION) + $executions = $this->instance->dao->select('*')->from(TABLE_EXECUTION) ->where('deleted')->eq(0) ->andWhere('project')->eq($projectID) ->andWhere('type')->in('sprint,stage,kanban') ->orderBy('order_asc') ->fetchAll('id'); - $executions = $this->executionModel->resetExecutionSorts($executions); + $executions = $this->instance->resetExecutionSorts($executions); if(!empty($executions)) { $executionIDList = array_keys($executions); @@ -2870,7 +2870,7 @@ class executionModelTest extends baseTest */ public function getExtendFieldsTest($moduleName = 'project') { - $extendFields = $this->executionModel->getExtendFields($moduleName); + $extendFields = $this->instance->getExtendFields($moduleName); return $extendFields; } @@ -2884,9 +2884,9 @@ class executionModelTest extends baseTest */ public function getExecutionQueryTest(int $queryID): string { - if(!$queryID) $this->executionModel->session->set('executionQuery', "(( `project` = 'all' ) AND ( 1 AND `status` = 'doing'))"); + if(!$queryID) $this->instance->session->set('executionQuery', "(( `project` = 'all' ) AND ( 1 AND `status` = 'doing'))"); - return $this->executionModel->getExecutionQuery($queryID); + return $this->instance->getExecutionQuery($queryID); } /** @@ -2898,8 +2898,8 @@ class executionModelTest extends baseTest */ public function setKanbanMenuTest(): object { - $this->executionModel->setKanbanMenu(); - return $this->executionModel->lang->execution->menu; + $this->instance->setKanbanMenu(); + return $this->instance->lang->execution->menu; } /** @@ -2911,8 +2911,8 @@ class executionModelTest extends baseTest */ public function setKanbanMenuWithLangTest(): object { - $this->executionModel->setKanbanMenu(); - return $this->executionModel->lang->execution; + $this->instance->setKanbanMenu(); + return $this->instance->lang->execution; } /** @@ -2925,9 +2925,9 @@ class executionModelTest extends baseTest */ public function removeMenuTest(int $executionID): object { - $execution = $this->executionModel->fetchByID($executionID); - $this->executionModel->removeMenu($execution); - return $this->executionModel->lang->execution->menu; + $execution = $this->instance->fetchByID($executionID); + $this->instance->removeMenu($execution); + return $this->instance->lang->execution->menu; } /** @@ -2940,7 +2940,7 @@ class executionModelTest extends baseTest */ public function getExecutionFeaturesTest(object $execution): array { - $features = $this->executionModel->getExecutionFeatures($execution); + $features = $this->instance->getExecutionFeatures($execution); foreach($features as $key => $value) { if(!$value) $features[$key] = 0; @@ -2959,8 +2959,8 @@ class executionModelTest extends baseTest */ public function saveSessionTest(int $executionID): int { - $this->executionModel->saveSession($executionID); - return $this->executionModel->session->execution; + $this->instance->saveSession($executionID); + return $this->instance->session->execution; } /** @@ -2982,9 +2982,9 @@ class executionModelTest extends baseTest $laneGroup = array(array($columnCard)); $count = $cardIdList ? count(explode(',', $cardIdList)) : 0; - $this->executionModel->updateTodayCFDData($executionID, $type, $colName, $laneGroup); + $this->instance->updateTodayCFDData($executionID, $type, $colName, $laneGroup); - return $this->executionModel->dao->select('*')->from(TABLE_CFD) + return $this->instance->dao->select('*')->from(TABLE_CFD) ->where('execution')->eq($executionID) ->andWhere('date')->eq(helper::today()) ->andWhere('name')->eq($colName) @@ -3004,15 +3004,15 @@ class executionModelTest extends baseTest */ public function buildExecutionPairsTest(int $projectID, string $mode = ''): array { - $executions = $this->executionModel->dao->select("*, IF(INSTR('done,closed', status) < 2, 0, 1) AS isDone, INSTR('doing,wait,suspended,closed', status) AS sortStatus")->from(TABLE_EXECUTION) - ->where('vision')->eq($this->executionModel->config->vision) + $executions = $this->instance->dao->select("*, IF(INSTR('done,closed', status) < 2, 0, 1) AS isDone, INSTR('doing,wait,suspended,closed', status) AS sortStatus")->from(TABLE_EXECUTION) + ->where('vision')->eq($this->instance->config->vision) ->andWhere('type')->in('stage,sprint,kanban') ->andWhere('project')->eq($projectID) ->beginIF(strpos($mode, 'multiple') !== false)->andWhere('multiple')->eq('1')->fi() ->beginIF(strpos($mode, 'withdelete') === false)->andWhere('deleted')->eq(0)->fi() ->fetchAll('id'); - $allExecutions = $this->executionModel->dao->select('id,name,parent,grade')->from(TABLE_EXECUTION) + $allExecutions = $this->instance->dao->select('id,name,parent,grade')->from(TABLE_EXECUTION) ->where('type')->notin(array('program', 'project')) ->andWhere('deleted')->eq('0') ->andWhere('project')->eq($projectID) @@ -3021,9 +3021,9 @@ class executionModelTest extends baseTest $parents = array(); foreach($allExecutions as $exec) $parents[$exec->parent] = true; - $projectPairs = strpos($mode, 'withobject') !== false ? $this->executionModel->dao->select('id,name')->from(TABLE_PROJECT)->fetchPairs('id') : array(); + $projectPairs = strpos($mode, 'withobject') !== false ? $this->instance->dao->select('id,name')->from(TABLE_PROJECT)->fetchPairs('id') : array(); - return $this->executionModel->buildExecutionPairs($mode, $allExecutions, $executions, $parents, $projectPairs); + return $this->instance->buildExecutionPairs($mode, $allExecutions, $executions, $parents, $projectPairs); } /** @@ -3037,14 +3037,14 @@ class executionModelTest extends baseTest */ public function processProductPlansTest(array $productIdList, string $param = ''): array { - $plans = $this->executionModel->dao->select('t1.id,t1.title,t1.product,t1.parent,t1.begin,t1.end,t1.branch,t2.type as productType')->from(TABLE_PRODUCTPLAN)->alias('t1') + $plans = $this->instance->dao->select('t1.id,t1.title,t1.product,t1.parent,t1.begin,t1.end,t1.branch,t2.type as productType')->from(TABLE_PRODUCTPLAN)->alias('t1') ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t2.id=t1.product') ->where('t1.product')->in($productIdList) ->andWhere('t1.deleted')->eq(0) ->orderBy('t1.begin desc, t1.id desc') ->fetchAll('id'); - return $this->executionModel->processProductPlans($plans, $param); + return $this->instance->processProductPlans($plans, $param); } /** @@ -3058,10 +3058,10 @@ class executionModelTest extends baseTest */ public function afterImportBugTest(int $taskID, int $bugID): bool { - $task = $this->executionModel->loadModel('task')->getByID($taskID); - $bug = $this->executionModel->loadModel('bug')->getByID($bugID); + $task = $this->instance->loadModel('task')->getByID($taskID); + $bug = $this->instance->loadModel('bug')->getByID($bugID); - return $this->executionModel->afterImportBug($task, $bug); + return $this->instance->afterImportBug($task, $bug); } /** @@ -3082,11 +3082,11 @@ class executionModelTest extends baseTest $storyGroups = array(); foreach($stories as $story) $storyGroups[$story->product][$story->module][$story->id] = $story; - $taskGroups = $this->executionModel->getTaskGroups($executionID); + $taskGroups = $this->instance->getTaskGroups($executionID); $node = (object)$fullTrees[0]; if(!isset($node->id)) $node->id = 0; - return $this->executionModel->processStoryNode($node, $storyGroups, $taskGroups, 0); + return $this->instance->processStoryNode($node, $storyGroups, $taskGroups, 0); } /** @@ -3104,9 +3104,9 @@ class executionModelTest extends baseTest $storyGroups = array(); foreach($stories as $story) $storyGroups[$story->product][$story->module][$story->id] = $story; - $taskGroups = $this->executionModel->getTaskGroups($executionID); + $taskGroups = $this->instance->getTaskGroups($executionID); - $result = $this->executionModel->processStoryNode($node, $storyGroups, $taskGroups, $executionID); + $result = $this->instance->processStoryNode($node, $storyGroups, $taskGroups, $executionID); if(dao::isError()) return dao::getError(); return $result; @@ -3128,8 +3128,8 @@ class executionModelTest extends baseTest $node = (object)$fullTrees[0]; if(!isset($node->id)) $node->id = 0; - $taskGroups = $this->executionModel->getTaskGroups($executionID); - return $this->executionModel->processTaskNode($node, $taskGroups); + $taskGroups = $this->instance->getTaskGroups($executionID); + return $this->instance->processTaskNode($node, $taskGroups); } /** @@ -3143,8 +3143,8 @@ class executionModelTest extends baseTest */ public function batchProcessNameTest(int $projectID, int $count): array|int { - $project = $this->executionModel->loadModel('project')->getByID($projectID); - $executions = $this->executionModel->dao->select('*')->from(TABLE_EXECUTION) + $project = $this->instance->loadModel('project')->getByID($projectID); + $executions = $this->instance->dao->select('*')->from(TABLE_EXECUTION) ->where('deleted')->eq(0) ->andWhere('type')->in('sprint,stage,kanban') ->andWhere('project')->eq($projectID) @@ -3165,18 +3165,18 @@ class executionModelTest extends baseTest */ public function afterUnlinkStoryTest(int $executionID, int $storyID, int $count): array|int { - $execution = $this->executionModel->getByID($executionID); - $this->executionModel->afterUnlinkStory($execution, $storyID); + $execution = $this->instance->getByID($executionID); + $this->instance->afterUnlinkStory($execution, $storyID); if(dao::isError()) return dao::getError(); if($count == 1) { - $object = $this->executionModel->dao->select('*')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('execution')->eq($executionID)->fetchAll(); + $object = $this->instance->dao->select('*')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('execution')->eq($executionID)->fetchAll(); return count($object); } else { - return $this->executionModel->dao->select('*')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('execution')->eq($executionID)->fetchAll(); + return $this->instance->dao->select('*')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('execution')->eq($executionID)->fetchAll(); } } @@ -3188,8 +3188,8 @@ class executionModelTest extends baseTest */ public function generateRowTest() { - $executions = $this->executionModel->getStatData(); - return $this->executionModel->generateRow($executions, array(), array()); + $executions = $this->instance->getStatData(); + return $this->instance->generateRow($executions, array(), array()); } /** @@ -3200,10 +3200,10 @@ class executionModelTest extends baseTest */ public function appendTasksTest() { - $executions = $this->executionModel->getStatData(0, 'all', 0, 0, true); + $executions = $this->instance->getStatData(0, 'all', 0, 0, true); if(empty($executions[0]->tasks)) return false; - return $this->executionModel->appendTasks($executions[0]->tasks, array()); + return $this->instance->appendTasks($executions[0]->tasks, array()); } /** @@ -3217,12 +3217,12 @@ class executionModelTest extends baseTest */ public function processTasksTest(int $executionID, int $count): array|int { - $tasks = $this->executionModel->dao->select('*')->from(TABLE_TASK) + $tasks = $this->instance->dao->select('*')->from(TABLE_TASK) ->where('deleted')->eq(0) ->andWhere('execution')->eq($executionID) ->fetchAll('id'); - $tasks = $this->executionModel->processTasks($tasks); + $tasks = $this->instance->processTasks($tasks); return $count ? count($tasks) : $tasks; } @@ -3236,7 +3236,7 @@ class executionModelTest extends baseTest */ public function createMainLibTest(int $executionID, string $type = 'sprint'): object|array { - $libID = $this->executionModel->createMainLib(1, $executionID, $type); + $libID = $this->instance->createMainLib(1, $executionID, $type); if(dao::isError()) { @@ -3245,7 +3245,7 @@ class executionModelTest extends baseTest else { if(!$libID) return array(); - $object = $this->executionModel->dao->select('*')->from(TABLE_DOCLIB)->where('id')->eq($libID)->fetch(); + $object = $this->instance->dao->select('*')->from(TABLE_DOCLIB)->where('id')->eq($libID)->fetch(); return $object; } } @@ -3261,7 +3261,7 @@ class executionModelTest extends baseTest */ public function addExecutionMembersTest(int $executionID, array $members): object|array { - $this->executionModel->addExecutionMembers($executionID, $members); + $this->instance->addExecutionMembers($executionID, $members); if(dao::isError()) { @@ -3269,7 +3269,7 @@ class executionModelTest extends baseTest } else { - return $this->executionModel->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq('execution')->fetchAll(); + return $this->instance->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq('execution')->fetchAll(); } } @@ -3283,7 +3283,7 @@ class executionModelTest extends baseTest */ public function getPairsByListTest(string $executionIdList): string|array { - $executions = $this->executionModel->getPairsByList(explode(',', $executionIdList)); + $executions = $this->instance->getPairsByList(explode(',', $executionIdList)); if(dao::isError()) return dao::getError(); return implode(',', $executions); @@ -3299,7 +3299,7 @@ class executionModelTest extends baseTest */ public function getChildIdGroupTest(string $parentIdList): string|array { - $executions = $this->executionModel->getChildIdGroup(explode(',', $parentIdList)); + $executions = $this->instance->getChildIdGroup(explode(',', $parentIdList)); if(dao::isError()) return dao::getError(); $return = ''; @@ -3324,7 +3324,7 @@ class executionModelTest extends baseTest public function checkAccessTest(int $executionID, array $executions) { if(!isset($executions[$executionID])) return (int)key($executions); - return $this->executionModel->checkAccess($executionID, $executions); + return $this->instance->checkAccess($executionID, $executions); } /** @@ -3339,8 +3339,8 @@ class executionModelTest extends baseTest */ public function getSwitcherTest(int $executionID, string $module, string $method): bool { - $executionName = $this->executionModel->dao->select('name')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('name'); - $output = $this->executionModel->getSwitcher($executionID, $module, $method); + $executionName = $this->instance->dao->select('name')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('name'); + $output = $this->instance->getSwitcher($executionID, $module, $method); if(!$output) return false; return strpos($output, $output) !== false; @@ -3356,8 +3356,8 @@ class executionModelTest extends baseTest */ public function getToAndCcListTest(int $executionID): array { - $execution = $this->executionModel->getByID($executionID); - $return = $this->executionModel->getToAndCcList($execution); + $execution = $this->instance->getByID($executionID); + $return = $this->instance->getToAndCcList($execution); return $return; } @@ -3372,8 +3372,8 @@ class executionModelTest extends baseTest */ public function deleteTest(int $executionID = 0) { - $this->executionModel->delete(TABLE_EXECUTION, $executionID); - return $this->executionModel->dao->select('deleted')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('deleted'); + $this->instance->delete(TABLE_EXECUTION, $executionID); + return $this->instance->dao->select('deleted')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('deleted'); } /** @@ -3385,7 +3385,7 @@ class executionModelTest extends baseTest */ public function getByBuildTest($buildID = 0) { - $result = $this->executionModel->getByBuild((int)$buildID); + $result = $this->instance->getByBuild((int)$buildID); if(dao::isError()) return dao::getError(); return $result; @@ -3403,8 +3403,8 @@ class executionModelTest extends baseTest */ public function buildCaseSearchFormTest(array $products, int $queryID, string $actionURL, int $executionID): string { - $this->executionModel->loadModel('testcase'); - $this->executionModel->buildCaseSearchForm($products, $queryID, $actionURL, $executionID); + $this->instance->loadModel('testcase'); + $this->instance->buildCaseSearchForm($products, $queryID, $actionURL, $executionID); return 'executionCase'; } @@ -3513,7 +3513,7 @@ class executionModelTest extends baseTest */ public function buildStoryTreeTest(array $stories, array $taskGroups, int $executionID, object $node, int $parentID = 0) { - $result = $this->executionModel->buildStoryTree($stories, $taskGroups, $executionID, $node, $parentID); + $result = $this->instance->buildStoryTree($stories, $taskGroups, $executionID, $node, $parentID); if(dao::isError()) return dao::getError(); return $result; @@ -3532,7 +3532,7 @@ class executionModelTest extends baseTest { global $tester; - $oldExecution = $this->executionModel->getByID($executionID); + $oldExecution = $this->instance->getByID($executionID); if(empty($oldExecution)) return 0; // 模拟不同的测试场景 @@ -3583,7 +3583,7 @@ class executionModelTest extends baseTest ->fetch('count'); // 调用updateTeam方法 - $this->executionModel->updateTeam($executionID, $oldExecution, $execution); + $this->instance->updateTeam($executionID, $oldExecution, $execution); // 获取更新后的团队成员数量 $afterCount = $tester->dao->select('count(*) as count')->from(TABLE_TEAM) @@ -3628,7 +3628,7 @@ class executionModelTest extends baseTest $selfAndChildren = $selfAndChildrenList[$executionID]; - $result = $this->executionModel->changeStatus2Doing($executionID, $selfAndChildren); + $result = $this->instance->changeStatus2Doing($executionID, $selfAndChildren); if(dao::isError()) return dao::getError(); @@ -3646,7 +3646,7 @@ class executionModelTest extends baseTest { if($executionID <= 0) return false; - $execution = $this->executionModel->dao->select('id,status,realBegan,lastEditedBy,lastEditedDate') + $execution = $this->instance->dao->select('id,status,realBegan,lastEditedBy,lastEditedDate') ->from(TABLE_EXECUTION) ->where('id')->eq($executionID) ->fetch();