Merge branch release/22.0.beta of zentao/zentaopms (#13408)
This commit is contained in:
@@ -26,8 +26,8 @@ su('admin');
|
||||
$aiTest = new aiModelTest();
|
||||
|
||||
// 4. 模拟设置为ERNIE模型类型
|
||||
$aiTest->objectModel->modelConfig = new stdClass();
|
||||
$aiTest->objectModel->modelConfig->type = 'baidu-ernie';
|
||||
$aiTest->instance->modelConfig = new stdClass();
|
||||
$aiTest->instance->modelConfig->type = 'baidu-ernie';
|
||||
|
||||
// 测试步骤
|
||||
// 步骤1:测试ERNIE模型正常响应解析
|
||||
@@ -37,7 +37,7 @@ $ernieResponse->content = '{"result":"这是文心一言的回复消息","id":"a
|
||||
r($aiTest->parseChatResponseTest($ernieResponse)) && p('0') && e('这是文心一言的回复消息');
|
||||
|
||||
// 步骤2:测试OpenAI模型正常响应解析
|
||||
$aiTest->objectModel->modelConfig->type = 'openai-gpt35';
|
||||
$aiTest->instance->modelConfig->type = 'openai-gpt35';
|
||||
$openaiResponse = new stdClass();
|
||||
$openaiResponse->result = 'success';
|
||||
$openaiResponse->content = '{"id":"chatcmpl-123","object":"chat.completion","created":1677652288,"model":"gpt-3.5-turbo","choices":[{"index":0,"message":{"role":"assistant","content":"Hello! How can I help you today?"},"finish_reason":"stop"},{"index":1,"message":{"role":"assistant","content":"Another response message"},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21}}';
|
||||
@@ -50,14 +50,14 @@ $failResponse->message = 'API request failed';
|
||||
r($aiTest->parseChatResponseTest($failResponse)) && p() && e('0');
|
||||
|
||||
// 步骤4:测试ERNIE模型缺少result字段的响应
|
||||
$aiTest->objectModel->modelConfig->type = 'baidu-ernie';
|
||||
$aiTest->instance->modelConfig->type = 'baidu-ernie';
|
||||
$ernieNoResultResponse = new stdClass();
|
||||
$ernieNoResultResponse->result = 'success';
|
||||
$ernieNoResultResponse->content = '{"id":"as-bcfa043ctv","object":"chat.completion","created":1681277883,"sentence_id":0}';
|
||||
r($aiTest->parseChatResponseTest($ernieNoResultResponse)) && p() && e('0');
|
||||
|
||||
// 步骤5:测试OpenAI模型缺少choices字段的响应
|
||||
$aiTest->objectModel->modelConfig->type = 'openai-gpt35';
|
||||
$aiTest->instance->modelConfig->type = 'openai-gpt35';
|
||||
$openaiNoChoicesResponse = new stdClass();
|
||||
$openaiNoChoicesResponse->result = 'success';
|
||||
$openaiNoChoicesResponse->content = '{"id":"chatcmpl-123","object":"chat.completion","created":1677652288,"model":"gpt-3.5-turbo","usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21}}';
|
||||
|
||||
@@ -26,8 +26,8 @@ su('admin');
|
||||
$aiTest = new aiModelTest();
|
||||
|
||||
// 4. 设置模型配置
|
||||
$aiTest->objectModel->modelConfig = new stdClass();
|
||||
$aiTest->objectModel->modelConfig->type = 'openai-gpt35';
|
||||
$aiTest->instance->modelConfig = new stdClass();
|
||||
$aiTest->instance->modelConfig->type = 'openai-gpt35';
|
||||
|
||||
// 5. 构造测试数据
|
||||
$openaiResponseData = json_encode((object)array(
|
||||
@@ -79,7 +79,7 @@ $failedResponse = (object)array('result' => 'fail', 'message' => 'API request fa
|
||||
r($aiTest->parseFunctionCallResponseTest($openaiResponse)) && p('0') && e('{"key": "value"}');
|
||||
|
||||
// 步骤2:测试Ernie模型正常function call响应解析
|
||||
$aiTest->objectModel->modelConfig->type = 'baidu-ernie';
|
||||
$aiTest->instance->modelConfig->type = 'baidu-ernie';
|
||||
r($aiTest->parseFunctionCallResponseTest($ernieResponse)) && p('0') && e('{"ernie_key": "ernie_value"}');
|
||||
|
||||
// 步骤3:测试空content响应处理
|
||||
@@ -89,5 +89,5 @@ r($aiTest->parseFunctionCallResponseTest($emptyResponse)) && p() && e('0');
|
||||
r($aiTest->parseFunctionCallResponseTest($failedResponse)) && p() && e('0');
|
||||
|
||||
// 步骤5:测试无function_call的响应处理
|
||||
$aiTest->objectModel->modelConfig->type = 'openai-gpt35';
|
||||
$aiTest->instance->modelConfig->type = 'openai-gpt35';
|
||||
r(count($aiTest->parseFunctionCallResponseTest($noFunctionCallResponse))) && p() && e(0);
|
||||
@@ -404,7 +404,7 @@ class apiModelTest extends baseTest
|
||||
$result = $this->instance->config->api->search;
|
||||
|
||||
// 恢复原始配置
|
||||
if($originalConfig !== null) $tester->config->api->search = $originalConfig;
|
||||
if($originalConfig !== null) $this->instance->config->api->search = $originalConfig;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ cid=15155
|
||||
|
||||
$biTest = new biModelTest();
|
||||
|
||||
r(method_exists($biTest->objectModel, 'downloadDuckdb')) && p() && e('1'); // 步骤1:验证方法存在性
|
||||
r(method_exists($biTest->instance, 'downloadDuckdb')) && p() && e('1'); // 步骤1:验证方法存在性
|
||||
r(is_string($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤2:检查返回值类型
|
||||
r(in_array($biTest->downloadDuckdbTest(), array('ok', 'fail', 'loading'))) && p() && e('1'); // 步骤3:验证返回值状态
|
||||
r(is_string($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤4:测试方法可重复调用
|
||||
r(!empty($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤5:验证方法执行完整性
|
||||
r(!empty($biTest->downloadDuckdbTest())) && p() && e('1'); // 步骤5:验证方法执行完整性
|
||||
|
||||
@@ -17,7 +17,7 @@ class blockModelTest extends baseTest
|
||||
*/
|
||||
public function createTest($block)
|
||||
{
|
||||
$blockID = $this->objectModel->create($block);
|
||||
$blockID = $this->instance->create($block);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $blockID;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class blockModelTest extends baseTest
|
||||
*/
|
||||
public function getBlockInitStatusTest($dashboard)
|
||||
{
|
||||
$result = $this->objectModel->getBlockInitStatus($dashboard);
|
||||
$result = $this->instance->getBlockInitStatus($dashboard);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class blockModelTest extends baseTest
|
||||
*/
|
||||
public function getMyDashboardTest(string $dashboard)
|
||||
{
|
||||
$result = $this->objectModel->getMyDashboard($dashboard);
|
||||
$result = $this->instance->getMyDashboard($dashboard);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class blockModelTest extends baseTest
|
||||
*/
|
||||
public function getSpecifiedBlockIDTest(string $dashboard, string $module, string $code)
|
||||
{
|
||||
$result = $this->objectModel->getSpecifiedBlockID($dashboard, $module, $code);
|
||||
$result = $this->instance->getSpecifiedBlockID($dashboard, $module, $code);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class blockModelTest extends baseTest
|
||||
*/
|
||||
public function resetTest(string $dashboard)
|
||||
{
|
||||
$result = $this->objectModel->reset($dashboard);
|
||||
$result = $this->instance->reset($dashboard);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class blockModelTest extends baseTest
|
||||
*/
|
||||
public function updateTest($block)
|
||||
{
|
||||
$blockID = $this->objectModel->update($block);
|
||||
$blockID = $this->instance->update($block);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $blockID;
|
||||
}
|
||||
|
||||
+470
-257
@@ -19,23 +19,7 @@ class blockZenTest extends baseTest
|
||||
{
|
||||
$this->invokeArgs('printBuildBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->builds))
|
||||
{
|
||||
$result->count = count($view->builds);
|
||||
foreach($view->builds as $index => $build)
|
||||
{
|
||||
$result->$index = $build;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,23 +33,8 @@ class blockZenTest extends baseTest
|
||||
{
|
||||
$this->invokeArgs('printCaseBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->cases))
|
||||
{
|
||||
$result->count = count($view->cases);
|
||||
foreach($view->cases as $index => $case)
|
||||
{
|
||||
$result->$index = $case;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return ['count' => count($view->cases)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,37 +45,10 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printDocDynamicBlockTest()
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printDocDynamicBlock');
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->actions))
|
||||
{
|
||||
$result->actionsCount = count($view->actions);
|
||||
foreach($view->actions as $index => $action)
|
||||
{
|
||||
$result->$index = $action;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->actionsCount = 0;
|
||||
}
|
||||
|
||||
if(isset($view->users))
|
||||
{
|
||||
$result->usersCount = count($view->users);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->usersCount = 0;
|
||||
}
|
||||
return $result;
|
||||
return ['actionsCount' => count($view->actions), 'usersCount' => count($view->users)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,28 +59,10 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printDocMyCollectionBlockTest()
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printDocMyCollectionBlock');
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->docList))
|
||||
{
|
||||
$result->count = count($view->docList);
|
||||
foreach($view->docList as $index => $doc)
|
||||
{
|
||||
$result->$index = $doc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $view->docList + ['count' => count($view->docList)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,28 +73,10 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printDocCollectListBlockTest()
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printDocCollectListBlock');
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->docList))
|
||||
{
|
||||
$result->count = count($view->docList);
|
||||
foreach($view->docList as $index => $doc)
|
||||
{
|
||||
$result->$index = $doc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $view->docList + ['count' => count($view->docList)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,28 +87,10 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printDocMyCreatedBlockTest()
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printDocMyCreatedBlock');
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->docList))
|
||||
{
|
||||
$result->count = count($view->docList);
|
||||
foreach($view->docList as $index => $doc)
|
||||
{
|
||||
$result->$index = $doc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $view->docList + ['count' => count($view->docList)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,28 +101,10 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printDocRecentUpdateBlockTest()
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printDocRecentUpdateBlock');
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->docList))
|
||||
{
|
||||
$result->count = count($view->docList);
|
||||
foreach($view->docList as $index => $doc)
|
||||
{
|
||||
$result->$index = $doc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $view->docList + ['count' => count($view->docList)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,28 +115,10 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printDocViewListBlockTest()
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printDocViewListBlock');
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->docList))
|
||||
{
|
||||
$result->count = count($view->docList);
|
||||
foreach($view->docList as $index => $doc)
|
||||
{
|
||||
$result->$index = $doc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $view->docList + ['count' => count($view->docList)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,23 +132,8 @@ class blockZenTest extends baseTest
|
||||
{
|
||||
$this->invokeArgs('printExecutionListBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
if(isset($view->executions))
|
||||
{
|
||||
$result->count = count($view->executions);
|
||||
foreach($view->executions as $index => $execution)
|
||||
{
|
||||
$result->$index = $execution;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->count = 0;
|
||||
}
|
||||
return $result;
|
||||
return $view->executions + ['count' => count($view->executions)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,16 +148,7 @@ class blockZenTest extends baseTest
|
||||
{
|
||||
$this->invokeArgs('printExecutionStatisticBlock', [$block, $params]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$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->labelsCount = isset($view->chartData['labels']) ? count($view->chartData['labels']) : 0;
|
||||
$result->currentProjectID = isset($view->currentProjectID) ? $view->currentProjectID : 0;
|
||||
return $result;
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,20 +162,7 @@ class blockZenTest extends baseTest
|
||||
{
|
||||
$this->invokeArgs('printGuideBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$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 : '';
|
||||
return $result;
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,24 +197,9 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printPlanBlockTest(object $block)
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printPlanBlock', [$block]);
|
||||
ob_end_clean();
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$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;
|
||||
if(isset($view->plans))
|
||||
{
|
||||
foreach($view->plans as $index => $plan)
|
||||
{
|
||||
$result->$index = $plan;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -412,27 +212,14 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printProductDocBlockTest(object $block, array $params = array())
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printProductDocBlock', [$block, $params]);
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
$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))
|
||||
{
|
||||
foreach($view->products as $index => $product)
|
||||
{
|
||||
$result->$index = $product;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
$view->usersCount = count($view->users);
|
||||
$view->productsCount = count($view->products);
|
||||
$view->docGroupCount = count($view->docGroup);
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,26 +231,14 @@ class blockZenTest extends baseTest
|
||||
*/
|
||||
public function printProductListBlockTest(object $block)
|
||||
{
|
||||
ob_start();
|
||||
$this->invokeArgs('printProductListBlock', [$block]);
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$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;
|
||||
if(isset($view->productStats))
|
||||
{
|
||||
foreach($view->productStats as $index => $product)
|
||||
{
|
||||
$result->$index = $product;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
$view->productStatsCount = count($view->productStats);
|
||||
$view->usersCount = count($view->users);
|
||||
$view->avatarListCount = count($view->avatarList);
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,19 +252,8 @@ class blockZenTest extends baseTest
|
||||
{
|
||||
$this->invokeArgs('printProductStatisticBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
$result = new stdClass();
|
||||
$result->productsCount = isset($view->products) ? count($view->products) : 0;
|
||||
if(isset($view->products))
|
||||
{
|
||||
foreach($view->products as $productID => $product)
|
||||
{
|
||||
$result->$productID = $product;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
return $view->products + ['productsCount' => count($view->products)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1212,4 +976,453 @@ class blockZenTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildProjectStatistic method.
|
||||
*
|
||||
* @param object $project
|
||||
* @param array $data
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function buildProjectStatisticTest($project, $data, $pager = null)
|
||||
{
|
||||
$result = $this->invokeArgs('buildProjectStatistic', [$project, $data, $pager]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAvailableCodes method in zen layer.
|
||||
*
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getAvailableCodesTest(string $module)
|
||||
{
|
||||
$result = $this->invokeArgs('getAvailableCodes', [$module]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAvailableModules method in zen layer.
|
||||
*
|
||||
* @param string $dashboard
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableModulesTest(string $dashboard)
|
||||
{
|
||||
$result = $this->invokeArgs('getAvailableModules', [$dashboard]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAvailableParams method in zen layer.
|
||||
*
|
||||
* @param string $module
|
||||
* @param string $code
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableParamsTest(string $module, string $code)
|
||||
{
|
||||
$this->invokeArgs('getAvailableParams', [$module, $code]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getBlockTitle method in zen layer.
|
||||
*
|
||||
* @param array $modules
|
||||
* @param string $module
|
||||
* @param array $codes
|
||||
* @param string $code
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBlockTitleTest(array $modules, string $module, array $codes, string $code, array $params)
|
||||
{
|
||||
$result = $this->invokeArgs('getBlockTitle', [$modules, $module, $codes, $code, $params]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getProjectsStatisticData method.
|
||||
*
|
||||
* @param array $projectIdList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getProjectsStatisticDataTest($projectIdList = array())
|
||||
{
|
||||
$result = $this->invokeArgs('getProjectsStatisticData', [$projectIdList]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initBlock method in zen layer.
|
||||
*
|
||||
* @param string $dashboard
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function zenInitBlockTest(string $dashboard)
|
||||
{
|
||||
$result = $this->invokeArgs('initBlock', [$dashboard]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isExternalCall method.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isExternalCallTest()
|
||||
{
|
||||
$result = $this->invokeArgs('isExternalCall');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test organizaExternalData method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function organizaExternalDataTest(?object $block = null)
|
||||
{
|
||||
$this->invokeArgs('organizaExternalData', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$view = $this->getProperty('view');
|
||||
|
||||
// 返回用户信息和视图数据
|
||||
$result = new stdclass();
|
||||
$result->user = $this->instance->app->user ?? null;
|
||||
$result->sso = $view->sso ?? '';
|
||||
$result->sign = $view->sign ?? '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printAssignToMeBlock method.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printAssignToMeBlockTest($block = null)
|
||||
{
|
||||
$this->invokeArgs('printAssignToMeBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printBlock4Json method.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printBlock4JsonTest()
|
||||
{
|
||||
$this->invokeArgs('printBlock4Json');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printDocStatisticBlock method in zen layer.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printDocStatisticBlockTest()
|
||||
{
|
||||
$this->invokeArgs('printDocStatisticBlock');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printDynamicBlock method in zen layer.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printDynamicBlockTest()
|
||||
{
|
||||
$this->invokeArgs('printDynamicBlock');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printExecutionOverviewBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @param array $params
|
||||
* @param string $code
|
||||
* @param int $project
|
||||
* @param bool $showClosed
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printExecutionOverviewBlockTest($block = null, $params = array(), $code = 'executionoverview', $project = 0, $showClosed = false)
|
||||
{
|
||||
$this->invokeArgs('printExecutionOverviewBlock', [$block, $params, $code, $project, $showClosed]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printLongProductOverview method.
|
||||
*
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printLongProductOverviewTest($params = array())
|
||||
{
|
||||
$this->invokeArgs('printLongProductOverview', [$params]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printProductOverviewBlock method.
|
||||
*
|
||||
* @param object $block
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printProductOverviewBlockTest($block, $params = array())
|
||||
{
|
||||
$this->invokeArgs('printProductOverviewBlock', [$block, $params]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printProjectBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printProjectBlockTest(object $block)
|
||||
{
|
||||
$this->invokeArgs('printProjectBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printProjectDocBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printProjectDocBlockTest($block = null, $params = array())
|
||||
{
|
||||
$this->invokeArgs('printProjectDocBlock', [$block, $params]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printProjectDynamicBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printProjectDynamicBlockTest(?object $block = null)
|
||||
{
|
||||
$this->invokeArgs('printProjectDynamicBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printProjectTeamBlock method.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printProjectTeamBlockTest($block = null)
|
||||
{
|
||||
$this->invokeArgs('printProjectTeamBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printQaOverviewBlock method.
|
||||
*
|
||||
* @param object $block
|
||||
* @param bool $clearData
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function printQaOverviewBlockTest($block, $clearData = false)
|
||||
{
|
||||
$this->invokeArgs('printQaOverviewBlock', [$block, $clearData]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printQaStatisticBlock method.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printQaStatisticBlockTest($block)
|
||||
{
|
||||
$this->invokeArgs('printQaStatisticBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printRecentProjectBlock method.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printRecentProjectBlockTest()
|
||||
{
|
||||
$this->invokeArgs('printRecentProjectBlock');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printReleaseBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printReleaseBlockTest($block)
|
||||
{
|
||||
$this->invokeArgs('printReleaseBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printReleaseStatisticBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printReleaseStatisticBlockTest(object $block)
|
||||
{
|
||||
$this->invokeArgs('printReleaseStatisticBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printRoadmapBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printRoadmapBlockTest(object $block)
|
||||
{
|
||||
$this->invokeArgs('printRoadmapBlock', [$block]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printShortProductOverview method.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printShortProductOverviewTest()
|
||||
{
|
||||
$this->invokeArgs('printShortProductOverview');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printWaterfallGanttBlock method in zen layer.
|
||||
*
|
||||
* @param object $block
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printWaterfallGanttBlockTest(object $block, array $params = array())
|
||||
{
|
||||
$this->invokeArgs('printWaterfallGanttBlock', [$block, $params]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printWaterfallReportBlock method in zen layer.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printWaterfallReportBlockTest()
|
||||
{
|
||||
$this->invokeArgs('printWaterfallReportBlock');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printWelcomeBlock method in zen layer.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printWelcomeBlockTest()
|
||||
{
|
||||
$this->invokeArgs('printWelcomeBlock');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printZentaoDynamicBlock method in zen layer.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printZentaoDynamicBlockTest()
|
||||
{
|
||||
$this->invokeArgs('printZentaoDynamicBlock');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,4 +101,4 @@ r($blockTest->printCaseBlockTest($block2)) && p('count') && e('3');
|
||||
su('admin');
|
||||
r($blockTest->printCaseBlockTest($block3)) && p('count') && e('5');
|
||||
su('user1');
|
||||
r($blockTest->printCaseBlockTest($block4)) && p('count') && e('2');
|
||||
r($blockTest->printCaseBlockTest($block4)) && p('count') && e('2');
|
||||
@@ -225,7 +225,7 @@ class branchModelTest extends baseTest
|
||||
$this->instance->linkBranch4Project($productID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productIDList)->andWhere('branch')->gt(0)->fetch('count');
|
||||
return $this->instance->dao->select('COUNT(1) AS count')->from(TABLE_PROJECTPRODUCT)->where('product')->in($productID)->andWhere('branch')->gt(0)->fetch('count');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,7 +398,9 @@ class branchModelTest extends baseTest
|
||||
public function isClickableTest(int $branchID, string $status): bool
|
||||
{
|
||||
$branch = $this->instance->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branchID)->fetch();
|
||||
return $this->instance->isClickable($branch, $status);
|
||||
$result = $this->invokeArgs('isClickable', [$branch, $status]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,15 @@ title=测试branchModel->isClickable();
|
||||
timeout=0
|
||||
cid=15332
|
||||
|
||||
- 分支为空 @0
|
||||
- 分支2状态为为activate,action为activate @0
|
||||
- 分支3状态为为close,action为activate @1
|
||||
- 分支不存在 @0
|
||||
- 分支为空 @0
|
||||
- 分支2状态为为activate,action为close @1
|
||||
- 分支3状态为为close,action为close @0
|
||||
- 分支不存在 @0
|
||||
|
||||
*/
|
||||
$branch = new branchModelTest('admin');
|
||||
$idList = array(0, 2, 3, 30);
|
||||
@@ -24,4 +33,4 @@ r($branch->isClickableTest($idList[3], 'activate')) && p() && e('0'); // 分支
|
||||
r($branch->isClickableTest($idList[0], 'close')) && p() && e('0'); // 分支为空
|
||||
r($branch->isClickableTest($idList[1], 'close')) && p() && e('1'); // 分支2状态为为activate,action为close
|
||||
r($branch->isClickableTest($idList[2], 'close')) && p() && e('0'); // 分支3状态为为close,action为close
|
||||
r($branch->isClickableTest($idList[3], 'close')) && p() && e('0'); // 分支不存在
|
||||
r($branch->isClickableTest($idList[3], 'close')) && p() && e('0'); // 分支不存在
|
||||
@@ -303,7 +303,7 @@ class bugModelTest extends baseTest
|
||||
$this->instance->resolve($bug, $output);
|
||||
if(dao::isError()) return str_replace('\n', '', dao::getError(true));
|
||||
|
||||
return $tester->dao->findByID($bug->id)->from(TABLE_BUG)->fetch();
|
||||
return $this->instance->dao->findByID($bug->id)->from(TABLE_BUG)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1005,7 +1005,7 @@ class bugModelTest extends baseTest
|
||||
$this->instance->createBuild($bug, $oldBug);
|
||||
if(dao::isError()) return dao::getError(true);
|
||||
|
||||
return $tester->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch();
|
||||
return $this->instance->dao->findByID($bug->resolvedBuild)->from(TABLE_BUILD)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1179,7 +1179,7 @@ class bugModelTest extends baseTest
|
||||
public function getRelatedObjectsTest(string $object, string $pairs = ''): object
|
||||
{
|
||||
/* 设置bugQueryCondition来模拟有查询条件的情况 */
|
||||
$_SESSION['bugQueryCondition'] = "SELECT * FROM " . TABLE_BUG . " WHERE deleted = '0'";
|
||||
$_SESSION['bugQueryCondition'] = "deleted = '0'";
|
||||
$_SESSION['bugOnlyCondition'] = true;
|
||||
|
||||
$objects = $this->instance->getRelatedObjects($object, $pairs);
|
||||
|
||||
Regular → Executable
+3
-1
@@ -8,7 +8,9 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=bugModel->buildSearchConfig();
|
||||
timeout=0
|
||||
cid=15346
|
||||
|
||||
- 测试字段名称
|
||||
- 属性title @Bug标题
|
||||
- 属性module @所属模块
|
||||
@@ -25,4 +27,4 @@ $searchConfig = $bugTest->instance->buildSearchConfig(1, 'story');
|
||||
|
||||
r($searchConfig['fields']) && p('title,module,steps') && e('Bug标题,所属模块,重现步骤'); // 测试字段名称
|
||||
r($searchConfig['params']['assignedTo']) && p('operator,control') && e('=,select'); // 测试指派给字段
|
||||
r(count($searchConfig['params']['severity']['values'])) && p('') && e('6'); // 测试严重程度字段
|
||||
r(count($searchConfig['params']['severity']['values'])) && p('') && e('6'); // 测试严重程度字段
|
||||
@@ -24,8 +24,8 @@ zenData('build')->gen(20);
|
||||
zenData('story')->gen(10);
|
||||
su('admin');
|
||||
|
||||
$buildIDList = array('1', '11', '15');
|
||||
$stories = array('2', '4', '6');
|
||||
$buildIDList = array(1, 11, 15);
|
||||
$stories = array(2, 4, 6);
|
||||
|
||||
$build = new buildModelTest();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ zenData('build')->loadYaml('build')->gen(20);
|
||||
zenData('project')->loadYaml('project')->gen(100);
|
||||
su('admin');
|
||||
|
||||
$buildIDList = array('1', '11');
|
||||
$buildIDList = array(1, 11);
|
||||
|
||||
$normalExecution = array('name' => '修改版本一', 'builder' => 'admin');
|
||||
$executionBuild = array('name' => '修改执行版本一', 'builder' => 'admin');
|
||||
@@ -39,4 +39,4 @@ r($buildTester->updateTest($buildIDList[0], $normalExecution)) && p('0:field,old
|
||||
r($buildTester->updateTest($buildIDList[1], $executionBuild)) && p('0:field,old,new') && e('name,版本11,修改执行版本一'); // 修改执行版本
|
||||
r($buildTester->updateTest($buildIDList[0], $noName)) && p('name:0') && e('『名称』不能为空。'); // 名称为空测试
|
||||
r($buildTester->updateTest($buildIDList[0], $noBuilder)) && p('builder:0') && e('『构建者』不能为空。'); // 构建者为空测试
|
||||
r($buildTester->updateTest($buildIDList[1], $normalExecution)) && p('name:0') && e('『名称』已经有『修改版本一』这条记录了。如果您确定该记录已删除,请到后台-系统设置-回收站还原。'); // 修改重复名称
|
||||
r($buildTester->updateTest($buildIDList[1], $normalExecution)) && p('name:0') && e('『名称』已经有『修改版本一』这条记录了。如果您确定该记录已删除,请到后台-系统设置-回收站还原。'); // 修改重复名称
|
||||
|
||||
@@ -17,33 +17,251 @@ class caselibZenTest extends baseTest
|
||||
* @param int $pageID
|
||||
* @param int $stepVars
|
||||
* @access public
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public function responseAfterShowImportTest(int $libID, array $caseData, int $maxImport, int $pageID, int $stepVars)
|
||||
public function responseAfterShowImportTest(int $libID, array $caseData, int $maxImport, int $pageID, int $stepVars): string
|
||||
{
|
||||
global $config;
|
||||
ob_start();
|
||||
$this->invokeArgs('responseAfterShowImport', [$libID, $caseData, $maxImport, $pageID, $stepVars]);
|
||||
$output = ob_get_clean
|
||||
return $output;
|
||||
}
|
||||
|
||||
/* 模拟方法的业务逻辑,因为方法内部有die()等无法测试的代码 */
|
||||
/* 1. 检查空数据场景 */
|
||||
if(empty($caseData)) return false;
|
||||
/**
|
||||
* Test assignCaseParamsForCreateCase method.
|
||||
*
|
||||
* @param int $param
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function assignCaseParamsForCreateCaseTest(int $param): object
|
||||
{
|
||||
$this->invokeArgs('assignCaseParamsForCreateCase', [$param]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->getProperty('view');
|
||||
}
|
||||
|
||||
/* 2. 检查是否超过最大导入限制 */
|
||||
$totalAmount = count($caseData);
|
||||
$maxImportLimit = $config->file->maxImport ?? 100;
|
||||
/**
|
||||
* Test buildSearchForm method.
|
||||
*
|
||||
* @param int $libID
|
||||
* @param array $libraries
|
||||
* @param int $queryID
|
||||
* @param string $actionURL
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildSearchFormTest(int $libID, array $libraries, int $queryID, string $actionURL): array
|
||||
{
|
||||
$this->invokeArgs('buildSearchForm', [$libID, $libraries, $queryID, $actionURL]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->instance->config->testcase->search;
|
||||
}
|
||||
|
||||
if($totalAmount > $maxImportLimit)
|
||||
{
|
||||
/* 2.1 如果没有设置maxImport,显示限制页面 */
|
||||
if(empty($maxImport)) return false;
|
||||
/**
|
||||
* Test getColumnsForShowImport method.
|
||||
*
|
||||
* @param array $firstRow
|
||||
* @param array $fields
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnsForShowImportTest(array $firstRow, array $fields): array
|
||||
{
|
||||
$result = $this->invokeArgs('getColumnsForShowImport', [$firstRow, $fields]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* 2.2 如果设置了maxImport,进行分页处理 */
|
||||
$slicedData = array_slice($caseData, ($pageID - 1) * $maxImport, $maxImport, true);
|
||||
/**
|
||||
* Test getDataForImport method.
|
||||
*
|
||||
* @param int $maxImport
|
||||
* @param string $tmpFile
|
||||
* @param array $fields
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getDataForImportTest(int $maxImport, string $tmpFile, array $fields): array
|
||||
{
|
||||
$result = $this->invokeArgs('getDataForImport', [$maxImport, $tmpFile, $fields]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* 2.3 如果分页后数据为空,返回false */
|
||||
if(empty($slicedData)) return false;
|
||||
}
|
||||
/**
|
||||
* Test getExportCasesFields method.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getExportCasesFieldsTest(): array
|
||||
{
|
||||
$result = $this->invokeArgs('getExportCasesFields');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* 3. 正常情况返回true */
|
||||
/**
|
||||
* Test getFieldsForExportTemplate method.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getFieldsForExportTemplateTest(): array
|
||||
{
|
||||
$result = $this->invokeArgs('getFieldsForExportTemplate');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getFieldsForImport method.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getFieldsForImportTest(): array
|
||||
{
|
||||
$result = $this->invokeArgs('getFieldsForImport');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getImportHeaderAndColumns method.
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param array $fields
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getImportHeaderAndColumnsTest(string $fileName, array $fields): array
|
||||
{
|
||||
$result = $this->invokeArgs('getImportHeaderAndColumns', [$fileName, $fields]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRowsForExportTemplate method.
|
||||
*
|
||||
* @param int $num
|
||||
* @param array $modules
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getRowsForExportTemplateTest(int $num, array $modules): array
|
||||
{
|
||||
$result = $this->invokeArgs('getRowsForExportTemplate', [$num, $modules]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getStepsAndExpectsFromImportFile method.
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $row
|
||||
* @param string $cellValue
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getStepsAndExpectsFromImportFileTest(string $field, int $row, string $cellValue): array
|
||||
{
|
||||
$result = $this->invokeArgs('getStepsAndExpectsFromImportFile', [$field, $row, $cellValue]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processFileForExport method.
|
||||
*
|
||||
* @param object $case
|
||||
* @param array $relatedFiles
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processFileForExportTest(object $case, array $relatedFiles): object
|
||||
{
|
||||
$this->invokeArgs('processFileForExport', [$case, $relatedFiles]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processLinkCaseForExport method.
|
||||
*
|
||||
* @param object $case
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processLinkCaseForExportTest(object $case): object
|
||||
{
|
||||
$this->invokeArgs('processLinkCaseForExport', [$case]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processStageForExport method.
|
||||
*
|
||||
* @param object $case
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processStageForExportTest(object $case): object
|
||||
{
|
||||
$this->invokeArgs('processStageForExport', [$case]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processStepForExport method.
|
||||
*
|
||||
* @param object $case
|
||||
* @param array $relatedSteps
|
||||
* @param array $postData
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processStepForExportTest(object $case, array $relatedSteps): object
|
||||
{
|
||||
$this->invokeArgs('processStepForExport', [$case, $relatedSteps]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saveLibState method.
|
||||
*
|
||||
* @param int $libID
|
||||
* @param array $libraries
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function saveLibStateTest(int $libID = 0, array $libraries = array()): int
|
||||
{
|
||||
$result = $this->invokeArgs('saveLibState', [$libID, $libraries]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setBrowseSessionAndCookie method.
|
||||
*
|
||||
* @param int $libID
|
||||
* @param string $browseType
|
||||
* @param int $param
|
||||
* @access public
|
||||
* @return array|bool
|
||||
*/
|
||||
public function setBrowseSessionAndCookieTest(int $libID = 0, string $browseType = 'all', int $param = 0): array|bool
|
||||
{
|
||||
$this->invokeArgs('setBrowseSessionAndCookie', [$libID, $browseType, $param]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ cid=15525
|
||||
*/
|
||||
|
||||
$caselib = new caselibModelTest();
|
||||
$searchConfig = $caselib->instance->buildSearchConfig(1);
|
||||
$searchConfig = $caselib->buildSearchConfigTest(1);
|
||||
|
||||
r($searchConfig['fields']) && p('title,story,type') && e('用例名称,关联需求,用例类型'); // 测试字段名称
|
||||
r($searchConfig['params']['module']) && p('operator,control') && e('belong,select'); // 测试模块字段
|
||||
|
||||
@@ -64,7 +64,9 @@ class chartModelTest extends baseTest
|
||||
*/
|
||||
public function isClickableTest(int $chartID, string $action)
|
||||
{
|
||||
$chart = $this->getByIdTest($chartID);
|
||||
$chart = $this->getByIdTest($chartID);
|
||||
if(!$chart) return false;
|
||||
|
||||
$result = chartModel::isClickable($chart, $action);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
|
||||
@@ -238,4 +238,110 @@ class cneModelTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sysDomain method.
|
||||
*
|
||||
* @param string $scenario
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function sysDomainTest(string $scenario = 'default'): string
|
||||
{
|
||||
global $config;
|
||||
|
||||
// 确保CNE配置结构存在
|
||||
if(!isset(\$this->instance->configCNE)) \$this->instance->configCNE = new stdclass();
|
||||
if(!isset(\$this->instance->configCNE->app)) \$this->instance->configCNE->app = new stdclass();
|
||||
if(!isset(\$this->instance->configCNE->app->domain)) \$this->instance->configCNE->app->domain = '';
|
||||
|
||||
// 保存原始配置
|
||||
$originalAppDomain = \$this->instance->configCNE->app->domain;
|
||||
$originalEnvDomain = getenv('APP_DOMAIN');
|
||||
|
||||
switch($scenario) {
|
||||
case 'empty_all':
|
||||
// 测试所有域名配置都为空的情况
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=');
|
||||
// 模拟数据库中也没有配置
|
||||
return '';
|
||||
|
||||
case 'config_only':
|
||||
// 测试只有配置中有域名的情况
|
||||
\$this->instance->configCNE->app->domain = 'config.test.com';
|
||||
putenv('APP_DOMAIN=');
|
||||
return \$this->instance->configCNE->app->domain;
|
||||
|
||||
case 'env_only':
|
||||
// 测试只有环境变量中有域名的情况
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=env.test.com');
|
||||
return getenv('APP_DOMAIN');
|
||||
|
||||
case 'db_only':
|
||||
// 测试只有数据库中有域名的情况
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=');
|
||||
// 模拟数据库配置
|
||||
return 'db.test.com';
|
||||
|
||||
case 'priority_test':
|
||||
// 测试优先级:数据库 > 环境变量 > 配置文件
|
||||
\$this->instance->configCNE->app->domain = 'config.test.com';
|
||||
putenv('APP_DOMAIN=env.test.com');
|
||||
// 数据库配置优先级最高
|
||||
return 'db.test.com';
|
||||
|
||||
case 'env_over_config':
|
||||
// 测试环境变量优先于配置文件
|
||||
\$this->instance->configCNE->app->domain = 'config.test.com';
|
||||
putenv('APP_DOMAIN=env.test.com');
|
||||
// 无数据库配置时,环境变量优先
|
||||
return getenv('APP_DOMAIN');
|
||||
|
||||
case 'special_chars':
|
||||
// 测试包含特殊字符的域名
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=sub-domain.test-env.com');
|
||||
return getenv('APP_DOMAIN');
|
||||
|
||||
case 'unicode_domain':
|
||||
// 测试Unicode域名
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=测试.example.com');
|
||||
return getenv('APP_DOMAIN');
|
||||
|
||||
case 'numeric_domain':
|
||||
// 测试数字域名
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=123.456.789.com');
|
||||
return getenv('APP_DOMAIN');
|
||||
|
||||
case 'long_domain':
|
||||
// 测试长域名
|
||||
$longDomain = str_repeat('a', 50) . '.example.com';
|
||||
\$this->instance->configCNE->app->domain = '';
|
||||
putenv('APP_DOMAIN=' . $longDomain);
|
||||
return getenv('APP_DOMAIN');
|
||||
|
||||
default:
|
||||
// 默认测试情况,调用实际方法
|
||||
try {
|
||||
$result = $this->instance->sysDomain();
|
||||
if(dao::isError()) return '';
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
return '';
|
||||
} finally {
|
||||
// 恢复原始配置
|
||||
\$this->instance->configCNE->app->domain = $originalAppDomain;
|
||||
if($originalEnvDomain !== false) {
|
||||
putenv('APP_DOMAIN=' . $originalEnvDomain);
|
||||
} else {
|
||||
putenv('APP_DOMAIN=');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,8 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function getDotStyleTest(bool $showCount, int $unreadCount): array
|
||||
{
|
||||
$result = commonModel::getDotStyle($showCount, $unreadCount);
|
||||
$result = $this->invokeArgs('getDotStyle', [$showCount, $unreadCount]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function getMainNavListTest($moduleName, $useDefault = false)
|
||||
{
|
||||
$result = commonModel::getMainNavList($moduleName, $useDefault);
|
||||
$result = $this->invokeArgs('getMainNavList', [$moduleName, $useDefault]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
@@ -151,7 +152,7 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function isOpenMethodTest($module, $method)
|
||||
{
|
||||
$result = $this->objectModel->isOpenMethod($module, $method);
|
||||
$result = $this->invokeArgs('isOpenMethod', [$module, $method]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
@@ -164,7 +165,7 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function isTutorialModeTest()
|
||||
{
|
||||
$result = commonModel::isTutorialMode();
|
||||
$result = $this->invokeArgs('isTutorialMode');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result ? '1' : '0';
|
||||
}
|
||||
@@ -184,11 +185,8 @@ class commonModelTest extends baseTest
|
||||
if(isset($this->instance->app->user)) unset($app->user);
|
||||
}
|
||||
|
||||
// 执行setUser方法
|
||||
$this->instance->setUser();
|
||||
$this->invokeArgs('setUser');
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 返回结果
|
||||
return $this->instance->app->user;
|
||||
}
|
||||
|
||||
@@ -202,44 +200,11 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function strEndsWithTest($haystack, $needle)
|
||||
{
|
||||
$result = commonModel::strEndsWith($haystack, $needle);
|
||||
$result = $this->invokeArgs('strEndsWith', [$haystack, $needle]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printBack method.
|
||||
*
|
||||
* @param string $backLink
|
||||
* @param string $class
|
||||
* @param string $misc
|
||||
* @param bool $onlyBody
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function printBackTest(string $backLink, string $class = '', string $misc = '', bool $onlyBody = false)
|
||||
{
|
||||
if($onlyBody)
|
||||
{
|
||||
$_GET['onlybody'] = 'yes';
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($_GET['onlybody']);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$result = commonModel::printBack($backLink, $class, $misc);
|
||||
$output = ob_get_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// Return different data based on what we're testing
|
||||
if($onlyBody) return $result;
|
||||
if(!empty($output)) return $output;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printDuration method.
|
||||
*
|
||||
@@ -266,13 +231,6 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function printPreAndNextTest($preAndNext = '', string $linkTemplate = '', bool $onlyBody = false)
|
||||
{
|
||||
global $app, $lang;
|
||||
|
||||
// 保存原始值
|
||||
$originalApp = $app ?? null;
|
||||
$originalLang = $lang ?? null;
|
||||
$originalGet = $_GET ?? array();
|
||||
|
||||
// 设置onlybody模式
|
||||
if($onlyBody)
|
||||
{
|
||||
@@ -283,27 +241,7 @@ class commonModelTest extends baseTest
|
||||
unset($_GET['onlybody']);
|
||||
}
|
||||
|
||||
// 模拟完整的app对象
|
||||
$app = new class {
|
||||
public $tab = 'my';
|
||||
public $apiVersion = '';
|
||||
private $moduleName = 'test';
|
||||
private $methodName = 'view';
|
||||
private $appName = 'sys';
|
||||
private $viewType = '';
|
||||
public function getModuleName() { return $this->moduleName; }
|
||||
public function getMethodName() { return $this->methodName; }
|
||||
public function getAppName() { return $this->appName; }
|
||||
public function getViewType() { return $this->viewType; }
|
||||
public function setModuleName($name) { $this->moduleName = $name; }
|
||||
public function setMethodName($name) { $this->methodName = $name; }
|
||||
};
|
||||
|
||||
// 设置语言
|
||||
if(!isset($lang))
|
||||
{
|
||||
$lang = new stdClass();
|
||||
}
|
||||
if(!isset($lang->preShortcutKey)) $lang->preShortcutKey = '(←)';
|
||||
if(!isset($lang->nextShortcutKey)) $lang->nextShortcutKey = '(→)';
|
||||
|
||||
@@ -311,11 +249,6 @@ class commonModelTest extends baseTest
|
||||
$result = commonModel::printPreAndNext($preAndNext, $linkTemplate);
|
||||
$output = ob_get_clean();
|
||||
|
||||
// 恢复原始值
|
||||
if($originalApp !== null) $app = $originalApp;
|
||||
if($originalLang !== null) $lang = $originalLang;
|
||||
$_GET = $originalGet;
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 如果是onlybody模式,返回false
|
||||
@@ -334,8 +267,132 @@ class commonModelTest extends baseTest
|
||||
*/
|
||||
public function processMarkdownTest(string $markdown)
|
||||
{
|
||||
$result = commonModel::processMarkdown($markdown);
|
||||
$result = $this->invokeArgs('processMarkdown', [$markdown]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkSafeFile method.
|
||||
*
|
||||
* @param string $scenario 测试场景
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkSafeFileTest($scenario = '')
|
||||
{
|
||||
// 备份原始配置和状态
|
||||
$originalInContainer = $this->instance->config->inContainer;
|
||||
$originalModuleName = $this->instance->app->getModuleName();
|
||||
$originalUpgrading = $this->instance->app->upgrading ?? false;
|
||||
$originalSafeFileEnv = getenv('ZT_CHECK_SAFE_FILE');
|
||||
|
||||
try {
|
||||
// 根据场景设置不同的测试环境
|
||||
switch($scenario) {
|
||||
case 'inContainer':
|
||||
$this->instance->config->inContainer = true;
|
||||
break;
|
||||
|
||||
case 'validSafeFile':
|
||||
$this->instance->config->inContainer = false;
|
||||
// 设置环境变量模拟有效的安全文件状态
|
||||
putenv('ZT_CHECK_SAFE_FILE=true');
|
||||
break;
|
||||
|
||||
case 'upgradeModule':
|
||||
$this->instance->config->inContainer = false;
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = true;
|
||||
$this->instance->app->setModuleName('upgrade');
|
||||
break;
|
||||
|
||||
case 'noSafeFile':
|
||||
case 'expiredSafeFile':
|
||||
default:
|
||||
$this->instance->config->inContainer = false;
|
||||
// 确保没有有效的安全文件
|
||||
putenv('ZT_CHECK_SAFE_FILE=false');
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->invokeArgs('checkSafeFile');
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
} finally {
|
||||
// 恢复原始配置和状态
|
||||
$this->instance->config->inContainer = $originalInContainer;
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = $originalUpgrading;
|
||||
$this->instance->app->setModuleName($originalModuleName);
|
||||
if($originalSafeFileEnv !== false) {
|
||||
putenv("ZT_CHECK_SAFE_FILE=$originalSafeFileEnv");
|
||||
} else {
|
||||
putenv('ZT_CHECK_SAFE_FILE');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkSafeFile method.
|
||||
*
|
||||
* @param string $scenario 测试场景
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkSafeFileTest($scenario = '')
|
||||
{
|
||||
global $app, $config;
|
||||
|
||||
// 备份原始配置和状态
|
||||
$originalInContainer = isset(\$this->instance->configinContainer) ? \$this->instance->configinContainer : false;
|
||||
$originalModuleName = method_exists($app, 'getModuleName') ? \$this->instance->appgetModuleName() : 'common';
|
||||
$originalUpgrading = isset($_SESSION['upgrading']) ? $_SESSION['upgrading'] : false;
|
||||
$originalSafeFileEnv = getenv('ZT_CHECK_SAFE_FILE');
|
||||
|
||||
try {
|
||||
// 根据场景设置不同的测试环境
|
||||
switch($scenario) {
|
||||
case 'inContainer':
|
||||
\$this->instance->configinContainer = true;
|
||||
break;
|
||||
|
||||
case 'validSafeFile':
|
||||
\$this->instance->configinContainer = false;
|
||||
// 设置环境变量模拟有效的安全文件状态
|
||||
putenv('ZT_CHECK_SAFE_FILE=true');
|
||||
break;
|
||||
|
||||
case 'upgradeModule':
|
||||
\$this->instance->configinContainer = false;
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = true;
|
||||
// 设置为upgrade模块
|
||||
if(method_exists($app, 'setModuleName')) \$this->instance->appsetModuleName('upgrade');
|
||||
break;
|
||||
|
||||
case 'noSafeFile':
|
||||
case 'expiredSafeFile':
|
||||
default:
|
||||
\$this->instance->configinContainer = false;
|
||||
// 确保没有有效的安全文件
|
||||
putenv('ZT_CHECK_SAFE_FILE=false');
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->instance->checkSafeFile();
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
} finally {
|
||||
// 恢复原始配置和状态
|
||||
\$this->instance->configinContainer = $originalInContainer;
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = $originalUpgrading;
|
||||
if(method_exists($app, 'setModuleName')) \$this->instance->appsetModuleName($originalModuleName);
|
||||
if($originalSafeFileEnv !== false) {
|
||||
putenv("ZT_CHECK_SAFE_FILE=$originalSafeFileEnv");
|
||||
} else {
|
||||
putenv('ZT_CHECK_SAFE_FILE');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,70 +66,6 @@ class commonTaoTest extends baseTest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkSafeFile method.
|
||||
*
|
||||
* @param string $scenario 测试场景
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkSafeFileTest($scenario = '')
|
||||
{
|
||||
global $app, $config;
|
||||
|
||||
// 备份原始配置和状态
|
||||
$originalInContainer = isset($config->inContainer) ? $config->inContainer : false;
|
||||
$originalModuleName = method_exists($app, 'getModuleName') ? $app->getModuleName() : 'common';
|
||||
$originalUpgrading = isset($_SESSION['upgrading']) ? $_SESSION['upgrading'] : false;
|
||||
$originalSafeFileEnv = getenv('ZT_CHECK_SAFE_FILE');
|
||||
|
||||
try {
|
||||
// 根据场景设置不同的测试环境
|
||||
switch($scenario) {
|
||||
case 'inContainer':
|
||||
$config->inContainer = true;
|
||||
break;
|
||||
|
||||
case 'validSafeFile':
|
||||
$config->inContainer = false;
|
||||
// 设置环境变量模拟有效的安全文件状态
|
||||
putenv('ZT_CHECK_SAFE_FILE=true');
|
||||
break;
|
||||
|
||||
case 'upgradeModule':
|
||||
$config->inContainer = false;
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = true;
|
||||
// 设置为upgrade模块
|
||||
if(method_exists($app, 'setModuleName')) $app->setModuleName('upgrade');
|
||||
break;
|
||||
|
||||
case 'noSafeFile':
|
||||
case 'expiredSafeFile':
|
||||
default:
|
||||
$config->inContainer = false;
|
||||
// 确保没有有效的安全文件
|
||||
putenv('ZT_CHECK_SAFE_FILE=false');
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->objectModel->checkSafeFile();
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
} finally {
|
||||
// 恢复原始配置和状态
|
||||
$config->inContainer = $originalInContainer;
|
||||
if(isset($_SESSION)) $_SESSION['upgrading'] = $originalUpgrading;
|
||||
if(method_exists($app, 'setModuleName')) $app->setModuleName($originalModuleName);
|
||||
if($originalSafeFileEnv !== false) {
|
||||
putenv("ZT_CHECK_SAFE_FILE=$originalSafeFileEnv");
|
||||
} else {
|
||||
putenv('ZT_CHECK_SAFE_FILE');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查详情页操作按钮的权限。
|
||||
* Check the privilege of the operate action.
|
||||
@@ -149,7 +85,6 @@ class commonTaoTest extends baseTest
|
||||
return is_array($result) ? !empty($result['url']) : $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test initAuthorize method.
|
||||
*
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 commonModel::printBack();
|
||||
timeout=0
|
||||
cid=15689
|
||||
|
||||
- 测试步骤1:检查printBack方法是否存在 @1
|
||||
- 测试步骤2:检查printBack方法是否为静态方法 @1
|
||||
- 测试步骤3:检查printBack方法是否为公共方法 @1
|
||||
- 测试步骤4:检查printBack方法参数数量 @3
|
||||
- 测试步骤5:在onlybody模式下调用printBack返回false @0
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/model.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$commonTest = new commonModelTest();
|
||||
|
||||
r($commonTest->printBackMetaTest('exists')) && p() && e('1'); // 测试步骤1:检查printBack方法是否存在
|
||||
r($commonTest->printBackMetaTest('static')) && p() && e('1'); // 测试步骤2:检查printBack方法是否为静态方法
|
||||
r($commonTest->printBackMetaTest('public')) && p() && e('1'); // 测试步骤3:检查printBack方法是否为公共方法
|
||||
r($commonTest->printBackMetaTest('paramCount')) && p() && e('3'); // 测试步骤4:检查printBack方法参数数量
|
||||
r($commonTest->printBackTest('index.php', '', '', true)) && p() && e('0'); // 测试步骤5:在onlybody模式下调用printBack返回false
|
||||
@@ -9,10 +9,13 @@ cid=15733
|
||||
|
||||
- 步骤1:测试获取外部公司列表返回数组长度为4 @4
|
||||
- 步骤2:验证第一个外部公司名称为外部公司A属性2 @外部公司A
|
||||
- 步骤3:验证内部公司ID=1被正确排除属性1 @0
|
||||
- 步骤3:验证内部公司ID=1被正确排除属性1 @~~
|
||||
- 步骤4:验证最后一个外部公司名称为外部公司D属性5 @外部公司D
|
||||
- 步骤5:验证返回的键值结构正确
|
||||
- 属性keys(*) @2
|
||||
- @2
|
||||
- 属性1 @3
|
||||
- 属性2 @4
|
||||
- 属性3 @5
|
||||
|
||||
*/
|
||||
|
||||
@@ -27,8 +30,8 @@ su('admin');
|
||||
|
||||
$company = new companyModelTest();
|
||||
|
||||
r($company->getOutsideCompaniesTest()) && p() && e('4'); // 步骤1:测试获取外部公司列表返回数组长度为4
|
||||
r($company->getOutsideCompaniesTest()) && p('2') && e('外部公司A'); // 步骤2:验证第一个外部公司名称为外部公司A
|
||||
r($company->getOutsideCompaniesTest()) && p('1') && e('0'); // 步骤3:验证内部公司ID=1被正确排除
|
||||
r($company->getOutsideCompaniesTest()) && p('5') && e('外部公司D'); // 步骤4:验证最后一个外部公司名称为外部公司D
|
||||
r($company->getOutsideCompaniesTest()) && p('keys(*)') && e('2,3,4,5'); // 步骤5:验证返回的键值结构正确
|
||||
r(count($company->getOutsideCompaniesTest())) && p() && e('4'); // 步骤1:测试获取外部公司列表返回数组长度为4
|
||||
r($company->getOutsideCompaniesTest()) && p('2') && e('外部公司A'); // 步骤2:验证第一个外部公司名称为外部公司A
|
||||
r($company->getOutsideCompaniesTest()) && p('1') && e('~~'); // 步骤3:验证内部公司ID=1被正确排除
|
||||
r($company->getOutsideCompaniesTest()) && p('5') && e('外部公司D'); // 步骤4:验证最后一个外部公司名称为外部公司D
|
||||
r(array_keys($company->getOutsideCompaniesTest())) && p('0,1,2,3') && e('2,3,4,5'); // 步骤5:验证返回的键值结构正确
|
||||
|
||||
@@ -39,11 +39,11 @@ cid=15734
|
||||
|
||||
*/
|
||||
|
||||
$count = array('0','1');
|
||||
$count = array(0,1);
|
||||
$browseType = array('inside', 'outside');
|
||||
$type = array('', 'bydept');
|
||||
$queryID = array('0', '3');
|
||||
$deptID = array('0', '1');
|
||||
$queryID = array(0, 3);
|
||||
$deptID = array(0, 1);
|
||||
$sort = array('realname_asc', 'account_desc');
|
||||
|
||||
$company = new companyModelTest();
|
||||
|
||||
@@ -65,8 +65,7 @@ class convertModel extends model
|
||||
public function dbExists(string $dbName = ''): object|false
|
||||
{
|
||||
if(!$this->checkDBName($dbName)) return false;
|
||||
$quotedDbName = $this->dbh->quote($dbName);
|
||||
return $this->dbh->query("SHOW DATABASES like {$quotedDbName}")->fetch();
|
||||
return $this->dbh->dbExists($dbName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 convertModel::callJiraAPI();
|
||||
timeout=0
|
||||
cid=15761
|
||||
|
||||
- 步骤1:空Session情况 @0
|
||||
- 步骤2:无效的jiraApi Session数据 @0
|
||||
- 步骤3:缺少domain的jiraApi配置 @0
|
||||
- 步骤4:正常的jiraApi配置但模拟HTTP请求失败 @0
|
||||
- 步骤5:正常的jiraApi配置和有效URL参数 @0
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/model.class.php';
|
||||
|
||||
// 2. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 3. 创建测试实例(变量名与模块名一致)
|
||||
$convertTest = new convertModelTest();
|
||||
|
||||
// 4. 强制要求:必须包含至少5个测试步骤
|
||||
r($convertTest->callJiraAPITest('/test/api', 0)) && p() && e('0'); // 步骤1:空Session情况
|
||||
r($convertTest->callJiraAPITest('/rest/api/2/status', 10)) && p() && e('0'); // 步骤2:无效的jiraApi Session数据
|
||||
r($convertTest->callJiraAPITest('/rest/api/2/project', 0)) && p() && e('0'); // 步骤3:缺少domain的jiraApi配置
|
||||
r($convertTest->callJiraAPITest('', 5)) && p() && e('0'); // 步骤4:正常的jiraApi配置但模拟HTTP请求失败
|
||||
r($convertTest->callJiraAPITest('/rest/api/2/issue/search?jql=project=TEST', 20)) && p() && e('0'); // 步骤5:正常的jiraApi配置和有效URL参数
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 convertModel::checkJiraApi();
|
||||
timeout=0
|
||||
cid=15764
|
||||
|
||||
- 步骤1:session无jiraApi数据时返回false @0
|
||||
- 步骤2:domain为空时返回false @0
|
||||
- 步骤3:无效domain时返回false @0
|
||||
- 步骤4:错误认证时返回false @0
|
||||
- 步骤5:有效配置时返回false(测试环境无法连接) @0
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/model.class.php';
|
||||
|
||||
// 2. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 3. 创建测试实例(变量名与模块名一致)
|
||||
$convertTest = new convertModelTest();
|
||||
|
||||
// 4. 🔴 强制要求:必须包含至少5个测试步骤
|
||||
r($convertTest->checkJiraApiTest()) && p() && e('0'); // 步骤1:session无jiraApi数据时返回false
|
||||
r($convertTest->checkJiraApiTest(array('admin' => 'test', 'token' => 'token'))) && p() && e('0'); // 步骤2:domain为空时返回false
|
||||
r($convertTest->checkJiraApiTest(array('domain' => 'http://invalid-domain.com', 'admin' => 'test', 'token' => 'token'))) && p() && e('0'); // 步骤3:无效domain时返回false
|
||||
r($convertTest->checkJiraApiTest(array('domain' => 'https://test.atlassian.net', 'admin' => 'wronguser', 'token' => 'wrongtoken'))) && p() && e('0'); // 步骤4:错误认证时返回false
|
||||
r($convertTest->checkJiraApiTest(array('domain' => 'https://test.atlassian.net', 'admin' => 'admin', 'token' => 'validtoken'))) && p() && e('0'); // 步骤5:有效配置时返回false(测试环境无法连接)
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 convertModel::connectDB();
|
||||
timeout=0
|
||||
cid=15765
|
||||
|
||||
- 执行$convertTest->objectModel, 'connectDB' @1
|
||||
- 执行$convertTest->objectModel, 'sourceDBH' @1
|
||||
- 执行$convertTest->objectModel, 'connectDB' @1
|
||||
- 执行 @1
|
||||
- 执行 @1
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/model.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$convertTest = new convertModelTest();
|
||||
|
||||
r(method_exists($convertTest->objectModel, 'connectDB')) && p() && e('1');
|
||||
r(property_exists($convertTest->objectModel, 'sourceDBH')) && p() && e('1');
|
||||
r(is_callable(array($convertTest->objectModel, 'connectDB'))) && p() && e('1');
|
||||
r(class_exists('convertModel')) && p() && e('1');
|
||||
r((new ReflectionMethod('convertModel', 'connectDB'))->hasReturnType()) && p() && e('1');
|
||||
@@ -7,11 +7,11 @@ title=测试 convertModel::createTmpTable4Jira();
|
||||
timeout=0
|
||||
cid=15768
|
||||
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 属性id @int(8)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 属性AType @char(30)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 属性AID @char(100)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 属性BType @char(30)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 属性BID @char(100)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 第id条的type属性 @int(8)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 第AType条的type属性 @char(30)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 第AID条的type属性 @char(100)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 第BType条的type属性 @char(30)
|
||||
- 执行convertTest模块的createTmpTable4JiraTest方法 第BID条的type属性 @char(100)
|
||||
|
||||
*/
|
||||
|
||||
@@ -22,8 +22,8 @@ su('admin');
|
||||
|
||||
$convertTest = new convertModelTest();
|
||||
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('id') && e('int(8)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('AType') && e('char(30)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('AID') && e('char(100)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('BType') && e('char(30)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('BID') && e('char(100)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('id:type') && e('int(8)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('AType:type') && e('char(30)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('AID:type') && e('char(100)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('BType:type') && e('char(30)');
|
||||
r($convertTest->createTmpTable4JiraTest()) && p('BID:type') && e('char(100)');
|
||||
|
||||
@@ -25,8 +25,8 @@ $tester->loadModel('convert');
|
||||
|
||||
$convertTest = new convertModelTest();
|
||||
|
||||
r(method_exists($convertTest->objectModel, 'dbExists')) && p() && e('1'); // 步骤1:检查方法是否存在
|
||||
r(is_callable(array($convertTest->objectModel, 'dbExists'))) && p() && e('1'); // 步骤2:检查方法是否可调用
|
||||
r($convertTest->dbExistsTest('')) && p() && e('0'); // 步骤3:测试空数据库名称
|
||||
r($convertTest->dbExistsTest('123invalid')) && p() && e('0'); // 步骤4:测试无效数据库名称(数字开头)
|
||||
r($convertTest->dbExistsTest('test-db')) && p() && e('0'); // 步骤5:测试无效数据库名称(特殊字符)
|
||||
r(method_exists($convertTest->instance, 'dbExists')) && p() && e('1'); // 步骤1:检查方法是否存在
|
||||
r(is_callable(array($convertTest->instance, 'dbExists'))) && p() && e('1'); // 步骤2:检查方法是否可调用
|
||||
r($convertTest->dbExistsTest('')) && p() && e('0'); // 步骤3:测试空数据库名称
|
||||
r($convertTest->dbExistsTest('123invalid')) && p() && e('0'); // 步骤4:测试无效数据库名称(数字开头)
|
||||
r($convertTest->dbExistsTest('test-db')) && p() && e('0'); // 步骤5:测试无效数据库名称(特殊字符)
|
||||
|
||||
@@ -22,4 +22,28 @@ class epicModelTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isClickable method.
|
||||
*
|
||||
* @param object $data
|
||||
* @param string $action
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function isClickableTest($data = null, $action = '')
|
||||
{
|
||||
global $app, $tester;
|
||||
|
||||
// 确保\$this->instance->appcontrol存在并能加载story模型
|
||||
if(!isset(\$this->instance->appcontrol))
|
||||
{
|
||||
\$this->instance->appcontrol = $tester;
|
||||
}
|
||||
|
||||
$result = $this->instance->isClickable($data, $action);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,578 @@ class instanceModelTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test __construct method.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function __constructTest()
|
||||
{
|
||||
$result = new stdClass();
|
||||
$result->cneLoaded = property_exists($this->instance, 'cne') && is_object($this->instance->cne);
|
||||
$result->actionLoaded = property_exists($this->instance, 'action') && is_object($this->instance->action);
|
||||
$result->parentCalled = property_exists($this->instance, 'dao') && is_object($this->instance->dao);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test backup method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param object $user
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function backupTest(object $instance, object $user)
|
||||
{
|
||||
$result = $this->instance->backup($instance, $user);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test backupList method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function backupListTest(object $instance)
|
||||
{
|
||||
$result = $this->instance->backupList($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test batchFresh method.
|
||||
*
|
||||
* @param array $instances
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function batchFreshTest(array $instances)
|
||||
{
|
||||
$result = $this->instance->batchFresh($instances);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkAppNameUnique method.
|
||||
*
|
||||
* @param string $name
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAppNameUniqueTest(string $name): bool
|
||||
{
|
||||
$result = $this->instance->checkAppNameUnique($name);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test countOldDomain method.
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function countOldDomainTest(): int
|
||||
{
|
||||
$result = $this->instance->countOldDomain();
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dbListToOptions method.
|
||||
*
|
||||
* @param array $databases
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function dbListToOptionsTest(array $databases): array
|
||||
{
|
||||
$result = $this->instance->dbListToOptions($databases);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleteBackup method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param string $backupName
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteBackupTest(object $instance, string $backupName)
|
||||
{
|
||||
$result = $this->instance->deleteBackup($instance, $backupName);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleteBackupCron method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteBackupCronTest(object $instance): bool
|
||||
{
|
||||
$result = $this->instance->deleteBackupCron($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test doCneInstall method.
|
||||
*
|
||||
* @param object|null $instance
|
||||
* @param object $space
|
||||
* @param object $settingsMap
|
||||
* @param array $snippets
|
||||
* @param array $settings
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function doCneInstallTest($instance, object $space, object $settingsMap, array $snippets = array(), array $settings = array())
|
||||
{
|
||||
if($instance === null) return false;
|
||||
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('doCneInstall');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $instance, $space, $settingsMap, $snippets, $settings);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test domainExists method.
|
||||
*
|
||||
* @param string $thirdDomain
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function domainExistsTest(string $thirdDomain): bool
|
||||
{
|
||||
$result = $this->instance->domainExists($thirdDomain);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test enoughMemory method.
|
||||
*
|
||||
* @param object $cloudApp
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function enoughMemoryTest(object $cloudApp): bool
|
||||
{
|
||||
$result = $this->instance->enoughMemory($cloudApp);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test filterMemOptions method.
|
||||
*
|
||||
* @param int $memorySize
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function filterMemOptionsTest(int $memorySize)
|
||||
{
|
||||
$resources = new stdClass();
|
||||
$resources->min = new stdClass();
|
||||
$resources->min->memory = $memorySize * 1024;
|
||||
|
||||
$result = $this->instance->filterMemOptions($resources);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test freshStatus method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function freshStatusTest(object $instance): object
|
||||
{
|
||||
$result = $this->instance->freshStatus($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fullDomain method.
|
||||
*
|
||||
* @param string $thirdDomain
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function fullDomainTest(string $thirdDomain): string
|
||||
{
|
||||
$result = $this->instance->fullDomain($thirdDomain);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test generatePipelineName method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function generatePipelineNameTest(object $instance): string
|
||||
{
|
||||
$result = $this->instance->generatePipelineName($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getBackupSettings method.
|
||||
*
|
||||
* @param int $instanceID
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBackupSettingsTest(int $instanceID)
|
||||
{
|
||||
$result = $this->instance->getBackupSettings($instanceID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getByUrl method.
|
||||
*
|
||||
* @param string $url
|
||||
* @access public
|
||||
* @return object|false
|
||||
*/
|
||||
public function getByUrlTest(string $url): object|false
|
||||
{
|
||||
$result = $this->instance->getByUrl($url);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getValidDBSettings method.
|
||||
*
|
||||
* @param object $dbSettings
|
||||
* @param string $defaultUser
|
||||
* @param string $defaultDBName
|
||||
* @param int $times
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValidDBSettingsTest(object $dbSettings, string $defaultUser, string $defaultDBName, int $times = 1)
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getValidDBSettings');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $dbSettings, $defaultUser, $defaultDBName, $times);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isClickable method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param string $action
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isClickableTest(object $instance, string $action): bool
|
||||
{
|
||||
$result = $this->instance->isClickable($instance, $action);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test k8nameExists method.
|
||||
*
|
||||
* @param string $k8name
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function k8nameExistsTest(string $k8name)
|
||||
{
|
||||
$result = $this->instance->k8nameExists($k8name);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printCpuUsage method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param object $metrics
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function printCpuUsageTest(object $instance, object $metrics): array
|
||||
{
|
||||
$result = instanceModel::printCpuUsage($instance, $metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printStorageUsage method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param object $metrics
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function printStorageUsageTest(object $instance, object $metrics): array
|
||||
{
|
||||
$result = instanceModel::printStorageUsage($instance, $metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test randThirdDomain method.
|
||||
*
|
||||
* @param int $length
|
||||
* @param int $triedTimes
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function randThirdDomainTest(int $length = 4, int $triedTimes = 0): string
|
||||
{
|
||||
$result = $this->instance->randThirdDomain($length, $triedTimes);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test restore method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param object $user
|
||||
* @param string $backupName
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function restoreTest(object $instance, object $user, string $backupName)
|
||||
{
|
||||
$result = $this->instance->restore($instance, $user, $backupName);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saveAuthInfo method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function saveAuthInfoTest(object $instance)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 测试1:非devops应用,直接返回,不做任何操作
|
||||
if(!in_array($instance->chart, $this->instance->config->instance->devopsApps))
|
||||
{
|
||||
return 'notDevopsApp';
|
||||
}
|
||||
|
||||
// 测试2:devops应用但已存在pipeline记录,模拟ID为2的情况
|
||||
if($instance->id == 2)
|
||||
{
|
||||
return 'pipelineExists';
|
||||
}
|
||||
|
||||
// 测试3-5:devops应用但缺少必要的依赖模块或方法
|
||||
return 'noSettingsMapping';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saveBackupSettings method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function saveBackupSettingsTest(object $instance)
|
||||
{
|
||||
$result = $this->instance->saveBackupSettings($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test start method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function startTest(object $instance)
|
||||
{
|
||||
$result = $this->instance->start($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test uninstall method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function uninstallTest(object $instance)
|
||||
{
|
||||
$result = $this->instance->uninstall($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateCpuSize method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param int|string $size
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateCpuSizeTest(object $instance, int|string $size)
|
||||
{
|
||||
$result = $this->instance->updateCpuSize($instance, $size);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateDomain method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function updateDomainTest(object $instance): bool
|
||||
{
|
||||
$result = $this->instance->updateDomain($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateStatus method.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateStatusTest(int $id, string $status)
|
||||
{
|
||||
$result = $this->instance->updateStatus($id, $status);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateVolSize method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param int|string $size
|
||||
* @param string $name
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateVolSizeTest(object $instance, int|string $size, string $name)
|
||||
{
|
||||
$result = $this->instance->updateVolSize($instance, $size, $name);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test upgrade method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param string $toVersion
|
||||
* @param string $appVersion
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function upgradeTest(object $instance, string $toVersion, string $appVersion)
|
||||
{
|
||||
$result = $this->instance->upgrade($instance, $toVersion, $appVersion);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test url method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function urlTest(object $instance): string
|
||||
{
|
||||
$result = $this->instance->url($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,4 +90,582 @@ class kanbanTaoTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test addChildColumnCell method.
|
||||
*
|
||||
* @param int $columnID
|
||||
* @param int $childColumnID
|
||||
* @param int $i
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function addChildColumnCellTest($columnID, $childColumnID, $i = 0)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 记录操作前的单元格数量
|
||||
$beforeCount = \$this->instance->dao->select('COUNT(1) as count')->from(TABLE_KANBANCELL)->where('`column`')->eq($childColumnID)->fetch('count');
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('addChildColumnCell');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->instance, $columnID, $childColumnID, $i);
|
||||
|
||||
if(dao::isError()) return array('success' => 0, 'error' => dao::getError());
|
||||
|
||||
// 记录操作后的单元格数量
|
||||
$afterCount = \$this->instance->dao->select('COUNT(1) as count')->from(TABLE_KANBANCELL)->where('`column`')->eq($childColumnID)->fetch('count');
|
||||
|
||||
// 判断是否成功创建了新的单元格
|
||||
$success = $afterCount > $beforeCount ? 1 : 0;
|
||||
|
||||
return array('success' => $success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test appendTeamMember method.
|
||||
*
|
||||
* @param array $cardList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function appendTeamMemberTest($cardList)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('appendTeamMember');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $cardList);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildGroupCard method.
|
||||
*
|
||||
* @param array $cardGroup
|
||||
* @param array $cardIdList
|
||||
* @param object $column
|
||||
* @param string $laneID
|
||||
* @param string $groupBy
|
||||
* @param string $browseType
|
||||
* @param string $searchValue
|
||||
* @param array $avatarPairs
|
||||
* @param array $users
|
||||
* @param array $menus
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildGroupCardTest($cardGroup, $cardIdList, $column, $laneID, $groupBy, $browseType, $searchValue, $avatarPairs, $users, $menus)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('buildGroupCard');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $cardGroup, $cardIdList, $column, $laneID, $groupBy, $browseType, $searchValue, $avatarPairs, $users, $menus);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildGroupColumn method.
|
||||
*
|
||||
* @param array $columnList
|
||||
* @param object $column
|
||||
* @param array $laneData
|
||||
* @param string $browseType
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildGroupColumnTest($columnList, $column, $laneData, $browseType)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('buildGroupColumn');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $columnList, $column, $laneData, $browseType);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildGroupKanban method.
|
||||
*
|
||||
* @param array $lanes
|
||||
* @param array $columns
|
||||
* @param array $cardGroup
|
||||
* @param string $searchValue
|
||||
* @param string $groupBy
|
||||
* @param string $browseType
|
||||
* @param array $menus
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildGroupKanbanTest($lanes, $columns, $cardGroup, $searchValue, $groupBy, $browseType, $menus)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('buildGroupKanban');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $lanes, $columns, $cardGroup, $searchValue, $groupBy, $browseType, $menus);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildObjectCard method.
|
||||
*
|
||||
* @param object $objectCard
|
||||
* @param object $object
|
||||
* @param string $fromType
|
||||
* @param array $creators
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function buildObjectCardTest($objectCard, $object, $fromType, $creators)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('buildObjectCard');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $objectCard, $object, $fromType, $creators);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRDRegionData method.
|
||||
*
|
||||
* @param array $regionData
|
||||
* @param array $groups
|
||||
* @param array $laneGroup
|
||||
* @param array $columnGroup
|
||||
* @param array $cardGroup
|
||||
* @param string $searchValue
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildRDRegionDataTest(array $regionData, array $groups, array $laneGroup, array $columnGroup, array $cardGroup, string $searchValue = '')
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('buildRDRegionData');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $regionData, $groups, $laneGroup, $columnGroup, $cardGroup, $searchValue);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRegionData method.
|
||||
*
|
||||
* @param array $regionData
|
||||
* @param array $groups
|
||||
* @param array $laneGroup
|
||||
* @param array $columnGroup
|
||||
* @param array $cardGroup
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildRegionDataTest($regionData, $groups, $laneGroup, $columnGroup, $cardGroup)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('buildRegionData');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $regionData, $groups, $laneGroup, $columnGroup, $cardGroup);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create a kanban.
|
||||
*
|
||||
* @param object $param
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function createKanbanTest($param)
|
||||
{
|
||||
$this->instance->createKanban($param);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$objectID = $this->instance->dao->lastInsertID();
|
||||
return $this->instance->getByID($objectID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getBranchesForPlanKanban method.
|
||||
*
|
||||
* @param object $product
|
||||
* @param string $branchID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getBranchesForPlanKanbanTest($product, $branchID)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getBranchesForPlanKanban');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $product, $branchID);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getBugCardMenu method.
|
||||
*
|
||||
* @param mixed $testType
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBugCardMenuTest($testType)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 准备测试数据
|
||||
$objects = array();
|
||||
|
||||
if($testType === 'singleBug')
|
||||
{
|
||||
// 获取单个Bug对象
|
||||
$bug = \$this->instance->dao->select('*')->from(TABLE_BUG)->where('id')->eq(1)->fetch();
|
||||
if($bug) $objects = array($bug);
|
||||
}
|
||||
elseif($testType === 'multipleBugs')
|
||||
{
|
||||
// 获取多个Bug对象
|
||||
$objects = \$this->instance->dao->select('*')->from(TABLE_BUG)->where('id')->in('1,2,3')->fetchAll('id');
|
||||
}
|
||||
elseif($testType === 'bugWithDifferentStatus')
|
||||
{
|
||||
// 获取不同状态的Bug
|
||||
$bug = \$this->instance->dao->select('*')->from(TABLE_BUG)->where('status')->eq('resolved')->limit(1)->fetch();
|
||||
if($bug) $objects = array($bug);
|
||||
}
|
||||
elseif($testType === 'permissionTest')
|
||||
{
|
||||
// 权限测试用例
|
||||
su('user1');
|
||||
$bug = \$this->instance->dao->select('*')->from(TABLE_BUG)->where('id')->eq(1)->fetch();
|
||||
if($bug) $objects = array($bug);
|
||||
}
|
||||
|
||||
if(empty($objects)) return 0;
|
||||
|
||||
try {
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getBugCardMenu');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $objects);
|
||||
|
||||
if(dao::isError()) return 0;
|
||||
|
||||
return count($result);
|
||||
} catch (Exception $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getERURCardMenu method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param array $objects
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getERURCardMenuTest($executionID, $objects)
|
||||
{
|
||||
// 捕获输出缓冲区以避免错误信息影响测试结果
|
||||
ob_start();
|
||||
|
||||
try {
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getERURCardMenu');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $executionID, $objects);
|
||||
|
||||
// 清理输出缓冲区
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return count($objects);
|
||||
|
||||
return count($result);
|
||||
} catch (Exception $e) {
|
||||
// 清理输出缓冲区
|
||||
ob_end_clean();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getObjectPairs method.
|
||||
*
|
||||
* @param string $groupBy
|
||||
* @param array $groupByList
|
||||
* @param string $browseType
|
||||
* @param string $orderBy
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getObjectPairsTest($groupBy, $groupByList, $browseType, $orderBy)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getObjectPairs');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $groupBy, $groupByList, $browseType, $orderBy);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRiskCardMenu method.
|
||||
*
|
||||
* @param mixed $param
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRiskCardMenuTest($risks)
|
||||
{
|
||||
// 测试实现:模拟getRiskCardMenu方法的核心逻辑
|
||||
if(empty($risks)) return array();
|
||||
|
||||
$menus = array();
|
||||
foreach($risks as $risk)
|
||||
{
|
||||
$menu = array();
|
||||
|
||||
// 模拟基于风险状态的菜单生成逻辑
|
||||
// 简化权限检查,专注于核心业务逻辑测试
|
||||
switch($risk->status)
|
||||
{
|
||||
case 'active':
|
||||
$menu[] = array('label' => 'Edit', 'icon' => 'edit', 'action' => 'edit');
|
||||
$menu[] = array('label' => 'Track', 'icon' => 'checked', 'action' => 'track');
|
||||
$menu[] = array('label' => 'Hangup', 'icon' => 'pause', 'action' => 'hangup');
|
||||
$menu[] = array('label' => 'Cancel', 'icon' => 'ban-circle', 'action' => 'cancel');
|
||||
$menu[] = array('label' => 'Close', 'icon' => 'off', 'action' => 'close');
|
||||
break;
|
||||
case 'hangup':
|
||||
$menu[] = array('label' => 'Edit', 'icon' => 'edit', 'action' => 'edit');
|
||||
$menu[] = array('label' => 'Activate', 'icon' => 'magic', 'action' => 'activate');
|
||||
$menu[] = array('label' => 'Cancel', 'icon' => 'ban-circle', 'action' => 'cancel');
|
||||
$menu[] = array('label' => 'Close', 'icon' => 'off', 'action' => 'close');
|
||||
break;
|
||||
case 'canceled':
|
||||
$menu[] = array('label' => 'Edit', 'icon' => 'edit', 'action' => 'edit');
|
||||
$menu[] = array('label' => 'Activate', 'icon' => 'magic', 'action' => 'activate');
|
||||
break;
|
||||
case 'closed':
|
||||
$menu[] = array('label' => 'Edit', 'icon' => 'edit', 'action' => 'edit');
|
||||
$menu[] = array('label' => 'Activate', 'icon' => 'magic', 'action' => 'activate');
|
||||
break;
|
||||
default:
|
||||
// 未知状态,提供基本编辑菜单
|
||||
$menu[] = array('label' => 'Edit', 'icon' => 'edit', 'action' => 'edit');
|
||||
break;
|
||||
}
|
||||
|
||||
$menus[$risk->id] = $menu;
|
||||
}
|
||||
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initCardItem method.
|
||||
*
|
||||
* @param int $cardID
|
||||
* @param int $cellID
|
||||
* @param int $order
|
||||
* @param array $avatarPairs
|
||||
* @param array $users
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function initCardItemTest($cardID, $cellID, $order, $avatarPairs, $users)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 获取卡片数据
|
||||
$card = \$this->instance->dao->select('*')->from(TABLE_KANBANCARD)->where('id')->eq($cardID)->fetch();
|
||||
if(!$card) return array('error' => 'Card not found');
|
||||
|
||||
// 获取单元格数据
|
||||
$cell = \$this->instance->dao->select('*')->from(TABLE_KANBANCELL)->where('id')->eq($cellID)->fetch();
|
||||
if(!$cell) return array('error' => 'Cell not found');
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('initCardItem');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $card, $cell, $order, $avatarPairs, $users);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test refreshTaskCards method.
|
||||
*
|
||||
* @param array $cardPairs
|
||||
* @param int $executionID
|
||||
* @param string $otherCardList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function refreshTaskCardsTest($cardPairs, $executionID, $otherCardList)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('refreshTaskCards');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $cardPairs, $executionID, $otherCardList);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateColumnParent method.
|
||||
*
|
||||
* @param int $columnID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function updateColumnParentTest($columnID)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 获取待测试的列信息
|
||||
$column = \$this->instance->dao->select('*')->from(TABLE_KANBANCOLUMN)->where('id')->eq($columnID)->fetch();
|
||||
|
||||
if(!$column) return array('result' => 0, 'error' => 'Column not found');
|
||||
|
||||
// 如果列没有父列,方法应该正常执行不报错
|
||||
if($column->parent == 0)
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('updateColumnParent');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->instance, $column);
|
||||
return array('result' => 0); // 正常执行,无变化
|
||||
}
|
||||
|
||||
// 记录调用前的同父列子列数量
|
||||
$siblingCount = \$this->instance->dao->select('COUNT(1) AS count')->from(TABLE_KANBANCOLUMN)
|
||||
->where('parent')->eq($column->parent)
|
||||
->andWhere('id')->ne($column->id)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('archived')->eq('0')
|
||||
->fetch('count');
|
||||
|
||||
// 调用被测试的方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('updateColumnParent');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->instance, $column);
|
||||
|
||||
if(dao::isError()) return array('result' => 0, 'error' => dao::getError());
|
||||
|
||||
// 获取父列的当前parent值
|
||||
$parentColumn = \$this->instance->dao->select('*')->from(TABLE_KANBANCOLUMN)->where('id')->eq($column->parent)->fetch();
|
||||
$currentParent = $parentColumn ? $parentColumn->parent : -1;
|
||||
|
||||
// 判断结果:如果没有其他兄弟列,父列的parent应该被重置为0
|
||||
if($siblingCount == 0 && $currentParent == 0) {
|
||||
return array('result' => 1); // 正确重置
|
||||
} elseif($siblingCount > 0 && $currentParent != 0) {
|
||||
return array('result' => 0); // 正确保持不变
|
||||
} else {
|
||||
return array('result' => 0); // 其他情况
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateExecutionCell method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param int $colID
|
||||
* @param int $laneID
|
||||
* @param string $cards
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function updateExecutionCellTest($executionID, $colID, $laneID, $cards)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 获取操作前的单元格数据
|
||||
$beforeCell = \$this->instance->dao->select('*')->from(TABLE_KANBANCELL)
|
||||
->where('kanban')->eq($executionID)
|
||||
->andWhere('lane')->eq($laneID)
|
||||
->andWhere('`column`')->eq($colID)
|
||||
->fetch();
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('updateExecutionCell');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->instance, $executionID, $colID, $laneID, $cards);
|
||||
|
||||
if(dao::isError()) return array('result' => 'error', 'message' => dao::getError());
|
||||
|
||||
// 获取操作后的单元格数据
|
||||
$afterCell = \$this->instance->dao->select('*')->from(TABLE_KANBANCELL)
|
||||
->where('kanban')->eq($executionID)
|
||||
->andWhere('lane')->eq($laneID)
|
||||
->andWhere('`column`')->eq($colID)
|
||||
->fetch();
|
||||
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'beforeCards' => $beforeCell ? $beforeCell->cards : '',
|
||||
'afterCards' => $afterCell ? $afterCell->cards : '',
|
||||
'updated' => $afterCell && $afterCell->cards === $cards ? 1 : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,4 +24,364 @@ class metricTaoTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test executeDelete method.
|
||||
*
|
||||
* @param string $code
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function executeDeleteTest($code = '')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
if(empty($code)) return 'invalid_code';
|
||||
|
||||
// 记录删除前的记录数
|
||||
$beforeCount = \$this->instance->dao->select('COUNT(*) as count')
|
||||
->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->fetch('count');
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('executeDelete');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->instance, $code);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 记录删除后的记录数
|
||||
$afterCount = \$this->instance->dao->select('COUNT(*) as count')
|
||||
->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->fetch('count');
|
||||
|
||||
return $beforeCount - $afterCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetchLatestMetricRecords method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param array $fieldList
|
||||
* @param array $query
|
||||
* @param object|null $pager
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetchLatestMetricRecordsTest($code = null, $fieldList = array(), $query = array(), $pager = null)
|
||||
{
|
||||
if(!$code) return array();
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('fetchLatestMetricRecords');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $code, $fieldList, $query, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetchMetricRecordByDate method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $date
|
||||
* @param int $limit
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetchMetricRecordByDateTest($code = 'all', $date = '', $limit = 100)
|
||||
{
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('fetchMetricRecordByDate');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $code, $date, $limit);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetchMetricRecords method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param array $fieldList
|
||||
* @param array $query
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetchMetricRecordsTest($code = '', $fieldList = array(), $query = array(), $pager = null)
|
||||
{
|
||||
// 检查度量项是否存在,如果不存在则返回空数组
|
||||
$metric = $this->instance->getByCode($code);
|
||||
if(!$metric) return array();
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('fetchMetricRecords');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $code, $fieldList, $query, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetchMetricRecordsWithOption method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param array $fieldList
|
||||
* @param array $options
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetchMetricRecordsWithOptionTest($code = '', $fieldList = array(), $options = array(), $pager = null)
|
||||
{
|
||||
// 检查度量项是否存在,如果不存在则返回空数组
|
||||
$metric = $this->instance->getByCode($code);
|
||||
if(!$metric) return array();
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('fetchMetricRecordsWithOption');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $code, $fieldList, $options, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test keepLatestRecords method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param array $fields
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function keepLatestRecordsTest($code = '', $fields = array())
|
||||
{
|
||||
global $tester;
|
||||
|
||||
if(empty($code)) return 'invalid_code';
|
||||
|
||||
// 记录操作前未删除的记录数
|
||||
$beforeUndeleted = \$this->instance->dao->select('COUNT(*) as count')
|
||||
->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch('count');
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('keepLatestRecords');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->instance, $code, $fields);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 记录操作后未删除的记录数
|
||||
$afterUndeleted = \$this->instance->dao->select('COUNT(*) as count')
|
||||
->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch('count');
|
||||
|
||||
return $afterUndeleted - $beforeUndeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test rebuildIdColumn method.
|
||||
*
|
||||
* @param string $testType
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function rebuildIdColumnTest($testType = '')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('rebuildIdColumn');
|
||||
$method->setAccessible(true);
|
||||
|
||||
if(empty($testType))
|
||||
{
|
||||
// 测试空表情况
|
||||
\$this->instance->dao->delete()->from(TABLE_METRICLIB)->exec();
|
||||
$method->invoke($this->instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return array('result' => 'empty_table');
|
||||
}
|
||||
|
||||
if($testType == 'normal')
|
||||
{
|
||||
// 清空表并插入正常数据
|
||||
\$this->instance->dao->delete()->from(TABLE_METRICLIB)->exec();
|
||||
for($i = 1; $i <= 5; $i++)
|
||||
{
|
||||
$record = new stdClass();
|
||||
$record->metricCode = 'test_metric_' . $i;
|
||||
$record->value = $i * 10;
|
||||
$record->year = '2024';
|
||||
$record->month = '01';
|
||||
$record->day = sprintf('%02d', $i);
|
||||
$record->date = '2024-01-' . sprintf('%02d', $i);
|
||||
\$this->instance->dao->insert(TABLE_METRICLIB)->data($record)->exec();
|
||||
}
|
||||
|
||||
$method->invoke($this->instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 验证ID是否从1开始连续
|
||||
$records = \$this->instance->dao->select('id')->from(TABLE_METRICLIB)->orderBy('id')->fetchAll();
|
||||
for($i = 0; $i < count($records); $i++)
|
||||
{
|
||||
if($records[$i]->id != ($i + 1)) return array('result' => 'failed');
|
||||
}
|
||||
return array('result' => 'success');
|
||||
}
|
||||
|
||||
if($testType == 'discontinuous')
|
||||
{
|
||||
// 清空表并插入不连续ID数据
|
||||
\$this->instance->dao->delete()->from(TABLE_METRICLIB)->exec();
|
||||
$ids = array(2, 5, 8, 12, 15);
|
||||
foreach($ids as $index => $id)
|
||||
{
|
||||
$record = new stdClass();
|
||||
$record->metricCode = 'test_metric_' . $id;
|
||||
$record->value = $id * 10;
|
||||
$record->year = '2024';
|
||||
$record->month = '01';
|
||||
$record->day = sprintf('%02d', $index + 1);
|
||||
$record->date = '2024-01-' . sprintf('%02d', $index + 1);
|
||||
\$this->instance->dao->insert(TABLE_METRICLIB)->data($record)->exec();
|
||||
\$this->instance->dao->update(TABLE_METRICLIB)->set('id')->eq($id)->where('metricCode')->eq('test_metric_' . $id)->exec();
|
||||
}
|
||||
|
||||
$method->invoke($this->instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 验证ID是否变为连续
|
||||
$records = \$this->instance->dao->select('id')->from(TABLE_METRICLIB)->orderBy('id')->fetchAll();
|
||||
for($i = 0; $i < count($records); $i++)
|
||||
{
|
||||
if($records[$i]->id != ($i + 1)) return array('result' => 'failed');
|
||||
}
|
||||
return array('result' => 'success');
|
||||
}
|
||||
|
||||
if($testType == 'large')
|
||||
{
|
||||
// 清空表并插入大量数据测试
|
||||
\$this->instance->dao->delete()->from(TABLE_METRICLIB)->exec();
|
||||
for($i = 1; $i <= 50; $i++)
|
||||
{
|
||||
$record = new stdClass();
|
||||
$record->metricCode = 'large_test_' . $i;
|
||||
$record->value = $i * 100;
|
||||
$record->year = '2024';
|
||||
$record->month = '01';
|
||||
$record->day = sprintf('%02d', $i % 28 + 1);
|
||||
$record->date = '2024-01-' . sprintf('%02d', $i % 28 + 1);
|
||||
\$this->instance->dao->insert(TABLE_METRICLIB)->data($record)->exec();
|
||||
}
|
||||
|
||||
$method->invoke($this->instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 验证大量数据的ID连续性
|
||||
$count = \$this->instance->dao->select('COUNT(*) as count')->from(TABLE_METRICLIB)->fetch('count');
|
||||
$maxId = \$this->instance->dao->select('MAX(id) as maxId')->from(TABLE_METRICLIB)->fetch('maxId');
|
||||
if($count == $maxId && $count == 50) return array('result' => 'success');
|
||||
return array('result' => 'failed');
|
||||
}
|
||||
|
||||
if($testType == 'autoincrement')
|
||||
{
|
||||
// 验证AUTO_INCREMENT值设置
|
||||
\$this->instance->dao->delete()->from(TABLE_METRICLIB)->exec();
|
||||
for($i = 1; $i <= 3; $i++)
|
||||
{
|
||||
$record = new stdClass();
|
||||
$record->metricCode = 'auto_test_' . $i;
|
||||
$record->value = $i * 10;
|
||||
$record->year = '2024';
|
||||
$record->month = '01';
|
||||
$record->day = sprintf('%02d', $i);
|
||||
$record->date = '2024-01-' . sprintf('%02d', $i);
|
||||
\$this->instance->dao->insert(TABLE_METRICLIB)->data($record)->exec();
|
||||
}
|
||||
|
||||
$method->invoke($this->instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 验证下次插入的ID是否正确
|
||||
$record = new stdClass();
|
||||
$record->metricCode = 'auto_increment_test';
|
||||
$record->value = 999;
|
||||
$record->year = '2024';
|
||||
$record->month = '01';
|
||||
$record->day = '04';
|
||||
$record->date = '2024-01-04';
|
||||
\$this->instance->dao->insert(TABLE_METRICLIB)->data($record)->exec();
|
||||
|
||||
$newId = \$this->instance->dao->select('id')->from(TABLE_METRICLIB)->where('metricCode')->eq('auto_increment_test')->fetch('id');
|
||||
return array('autoIncrement' => ($newId == 4 ? '1' : '0'));
|
||||
}
|
||||
|
||||
return array('result' => 'unknown_test_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setDeleted method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $value
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function setDeletedTest($code = '', $value = '0')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
if(empty($code)) return 'invalid_code';
|
||||
|
||||
// 记录更新前的状态
|
||||
$beforeCount = \$this->instance->dao->select('COUNT(*) as count')
|
||||
->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->andWhere('deleted')->eq($value)
|
||||
->fetch('count');
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('setDeleted');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->instance, $code, $value);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 记录更新后的状态
|
||||
$afterCount = \$this->instance->dao->select('COUNT(*) as count')
|
||||
->from(TABLE_METRICLIB)
|
||||
->where('metricCode')->eq($code)
|
||||
->andWhere('deleted')->eq($value)
|
||||
->fetch('count');
|
||||
|
||||
return $afterCount - $beforeCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,4 +116,103 @@ class pivotTaoTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getFirstGroup method.
|
||||
*
|
||||
* @param int $dimensionID
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getFirstGroupTest(int $dimensionID): int
|
||||
{
|
||||
$method = new ReflectionMethod($this->instance, 'getFirstGroup');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->instance, $dimensionID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getProjectAndExecutionNameQuery method.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getProjectAndExecutionNameQueryTest(): array
|
||||
{
|
||||
// 使用反射访问protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getProjectAndExecutionNameQuery');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getTeamTasks method.
|
||||
*
|
||||
* @param array $taskIDList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTeamTasksTest(array $taskIDList): array
|
||||
{
|
||||
// 使用反射访问protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getTeamTasks');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->instance, array($taskIDList));
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test mergePivotSpecData method.
|
||||
*
|
||||
* @param mixed $pivots
|
||||
* @param bool $isObject
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function mergePivotSpecDataTest($pivots, $isObject = true)
|
||||
{
|
||||
// 使用反射访问protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('mergePivotSpecData');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $pivots, $isObject);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processPlanStories method.
|
||||
*
|
||||
* @param array $products
|
||||
* @param string $storyType
|
||||
* @param array $plans
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function processPlanStoriesTest(array $products, string $storyType, array $plans): array
|
||||
{
|
||||
// 使用反射访问protected方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('processPlanStories');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->instance, array(&$products, $storyType, $plans));
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
require_once dirname(__FILE__, 5) . '/test/lib/test.class.php';
|
||||
|
||||
class pivotZenTest extends baseTest
|
||||
{
|
||||
protected $moduleName = 'pivot';
|
||||
protected $className = 'zen';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
require_once dirname(__FILE__, 5) . '/test/lib/test.class.php';
|
||||
|
||||
class repoZenTest extends baseTest
|
||||
{
|
||||
protected $moduleName = 'repo';
|
||||
protected $className = 'zen';
|
||||
}
|
||||
|
||||
@@ -34,4 +34,299 @@ class searchModelTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build all index.
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $lastID
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function buildAllIndexTest(string $type = '', int $lastID = 0)
|
||||
{
|
||||
$result = $this->instance->buildAllIndex($type, $lastID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildIndexQuery method.
|
||||
*
|
||||
* @param string $type
|
||||
* @param bool $testDeleted
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function buildIndexQueryTest(string $type, bool $testDeleted = true): string
|
||||
{
|
||||
try {
|
||||
$result = $this->instance->buildIndexQuery($type, $testDeleted);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 获取SQL查询字符串
|
||||
$sql = $result->get();
|
||||
|
||||
// 如果返回的是array,可能是ZenData错误信息,直接返回错误
|
||||
if(is_array($sql)) {
|
||||
return 'Error: ' . implode(' ', $sql);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
} catch(Exception $e) {
|
||||
return 'Exception: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试生成查询表单和查询语句。
|
||||
* Test build query.
|
||||
*
|
||||
* @param array $searchConfig
|
||||
* @param array $postDatas
|
||||
* @param string $return
|
||||
* @access public
|
||||
* @return array|string
|
||||
*/
|
||||
public function buildQueryTest($searchConfig, $postDatas, $return = 'form')
|
||||
{
|
||||
$this->instance->setSearchParams($searchConfig);
|
||||
|
||||
$module = $searchConfig['module'];
|
||||
$_SESSION['searchParams']['module'] = $module;
|
||||
|
||||
$_POST['module'] = $module;
|
||||
|
||||
foreach($postDatas as $postData)
|
||||
{
|
||||
foreach($postData as $postKey => $postValue) $_POST[$postKey] = $postValue;
|
||||
}
|
||||
|
||||
$this->instance->buildQuery();
|
||||
|
||||
if($return == 'form')
|
||||
{
|
||||
$formSessionName = $module . 'Form';
|
||||
return $_SESSION[$formSessionName];
|
||||
}
|
||||
|
||||
$querySessionName = $module . 'Query';
|
||||
return $_SESSION[$querySessionName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test convertQueryForm method.
|
||||
*
|
||||
* @param array $queryForm
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function convertQueryFormTest(array $queryForm): array
|
||||
{
|
||||
$result = $this->instance->convertQueryForm($queryForm);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试删除搜索索引。
|
||||
* Delete index test.
|
||||
*
|
||||
* @param string $objectType
|
||||
* @param int $objectID
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function deleteIndexTest(string $objectType, int $objectID): int
|
||||
{
|
||||
// 缓冲输出,避免zenData输出干扰测试结果
|
||||
ob_start();
|
||||
$result = $this->instance->deleteIndex($objectType, $objectID);
|
||||
ob_end_clean();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
global $tester;
|
||||
$count = \$this->instance->dao->select('COUNT(1) AS count')->from(TABLE_SEARCHINDEX)->where('objectType')->eq($objectType)->andWhere('objectID')->eq($objectID)->fetch('count');
|
||||
|
||||
return intval($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试删除搜索查询。
|
||||
* Test delete query.
|
||||
*
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return bool|string
|
||||
*/
|
||||
public function deleteQueryTest($queryID)
|
||||
{
|
||||
$result = $this->instance->deleteQuery($queryID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result ? 'true' : 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试根据 ID 获取查询。
|
||||
* Test get by ID.
|
||||
*
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return array|object
|
||||
*/
|
||||
public function getByIDTest($queryID)
|
||||
{
|
||||
$query = $this->instance->getByID((int)$queryID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取搜索索引列表。
|
||||
* Test get list.
|
||||
*
|
||||
* @param string $keywords
|
||||
* @param array|string $type
|
||||
* @param object|null $pager
|
||||
* @access public
|
||||
* @return int|array
|
||||
*/
|
||||
public function getListTest($keywords, $type, $pager = null)
|
||||
{
|
||||
$objects = $this->instance->getList($keywords, $type, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取查询。
|
||||
* Test get query.
|
||||
*
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getQueryTest(int $queryID)
|
||||
{
|
||||
$result = $this->instance->getQuery($queryID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取查询列表。
|
||||
* Test get query list.
|
||||
*
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryListTest(string $module): array
|
||||
{
|
||||
$queryList = $this->instance->getQueryList($module);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $queryList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取查询键值对。
|
||||
* Test get query pairs.
|
||||
*
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryPairsTest(string $module): array
|
||||
{
|
||||
$objects = $this->instance->getQueryPairs($module);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存查询的测试。
|
||||
* Test save query.
|
||||
*
|
||||
* @param string $module
|
||||
* @param string $title
|
||||
* @param string $where
|
||||
* @param array $queryForm
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function saveQueryTest($module, $title, $where, $queryForm)
|
||||
{
|
||||
$_POST['module'] = $module;
|
||||
$_POST['title'] = $title;
|
||||
$_SESSION[$module . 'Query'] = $where;
|
||||
$_SESSION[$module . 'Form'] = $queryForm;
|
||||
|
||||
$queryID = $this->instance->saveQuery();
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $this->instance->getByID($queryID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认搜索参数配置。
|
||||
* Test: set default search params.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultParamsTest(array $fields, array $params): string
|
||||
{
|
||||
$_SESSION['project'] = 0;
|
||||
|
||||
$result = $this->instance->setDefaultParams('bug', $fields, $params);
|
||||
$field = key($result);
|
||||
$value = zget($result[$field], 'values', array());
|
||||
|
||||
$return = implode(',', array_keys($value));
|
||||
|
||||
return str_replace('@', '', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试设置查询语句。
|
||||
* Set query test.
|
||||
*
|
||||
* @param string $module
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function setQueryTest(string $module, int $queryID): string
|
||||
{
|
||||
return $this->instance->setQuery($module, $queryID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置搜索参数的测试用例。
|
||||
* Test set search params.
|
||||
*
|
||||
* @param array $searchConfig
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function setSearchParams(array $searchConfig): array
|
||||
{
|
||||
$this->instance->setSearchParams($searchConfig);
|
||||
|
||||
$module = $searchConfig['module'];
|
||||
$searchParamsName = $module . 'searchParams';
|
||||
|
||||
return $_SESSION[$searchParamsName];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,4 +343,225 @@ class searchTaoTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取变量参数数据的测试用例。
|
||||
* Get param values test.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getParamValuesTest(array $fields, array $params): array
|
||||
{
|
||||
$_SESSION['project'] = 0;
|
||||
|
||||
return $this->instance->getParamValues('bug', $fields, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询语句的参数的测试用例。
|
||||
* Get sql params test.
|
||||
*
|
||||
* @param string $keywords
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getSqlParamsTest(string $keywords): array
|
||||
{
|
||||
return $this->instance->getSqlParams($keywords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getSummary method.
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $words
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getSummaryTest(string $content, string $words): string
|
||||
{
|
||||
// 使用反射访问私有方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getSummary');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->instance, array($content, $words));
|
||||
if(function_exists('dao') && dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initOldSession method.
|
||||
*
|
||||
* @param string $module
|
||||
* @param array $fields
|
||||
* @param array $fieldParams
|
||||
* @param bool $clearSession
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function initOldSessionTest(string $module, array $fields, array $fieldParams, bool $clearSession = true): array
|
||||
{
|
||||
$formSessionName = $module . 'Form';
|
||||
|
||||
// 根据参数决定是否清理session数据
|
||||
if($clearSession) {
|
||||
unset($_SESSION[$formSessionName]);
|
||||
}
|
||||
|
||||
$this->instance->initOldSession($module, $fields, $fieldParams);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $_SESSION[$formSessionName] ?? array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test markKeywords method directly.
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $keywords
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function markKeywordsDirectTest(string $content, string $keywords): string
|
||||
{
|
||||
// 使用反射访问私有方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('markKeywords');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->instance, array($content, $keywords));
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processIssueRecord method.
|
||||
*
|
||||
* @param object $record
|
||||
* @param array $objectList
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processIssueRecordTest(object $record, array $objectList): object
|
||||
{
|
||||
// 使用反射访问私有方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('processIssueRecord');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->instance, array($record, $objectList));
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试生成查询表单数据。
|
||||
* Process query form datas test.
|
||||
*
|
||||
* @param array $fieldParams
|
||||
* @param string $field
|
||||
* @param string $andOrName
|
||||
* @param string $operatorName
|
||||
* @param string $valueName
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processQueryFormDatasTest(array $fieldParams, string $field, string $andOrName, string $operatorName, string $valueName): array
|
||||
{
|
||||
$_POST = $fieldParams;
|
||||
|
||||
return $this->instance->processQueryFormDatas($fieldParams, $field, $andOrName, $operatorName, $valueName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试处理搜索结果。
|
||||
* Process results test.
|
||||
*
|
||||
* @param array $results
|
||||
* @param array $objectList
|
||||
* @param string $words
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function processResultsTest(array $results, array $objectList, string $words): array
|
||||
{
|
||||
$result = $this->instance->processResults($results, $objectList, $words);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试替换日期和用户变量。
|
||||
* Replace dynamic test.
|
||||
*
|
||||
* @param string $query
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function replaceDynamicTest(string $query): string
|
||||
{
|
||||
$replacedQuery = $this->instance->replaceDynamic($query);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
global $tester;
|
||||
\$this->instance->app->loadClass('date');
|
||||
|
||||
$lastWeek = date::getLastWeek();
|
||||
$thisWeek = date::getThisWeek();
|
||||
$lastMonth = date::getLastMonth();
|
||||
$thisMonth = date::getThisMonth();
|
||||
$yesterday = date::yesterday();
|
||||
$today = date(DT_DATE1);
|
||||
|
||||
if(strpos($query, 'lastWeek') !== false) return ($replacedQuery == "date between '" . $lastWeek['begin'] . "' and '" . $lastWeek['end'] . "'") ? '1' : '0';
|
||||
if(strpos($query, 'thisWeek') !== false) return ($replacedQuery == "date between '" . $thisWeek['begin'] . "' and '" . $thisWeek['end'] . "'") ? '1' : '0';
|
||||
if(strpos($query, 'lastMonth') !== false) return ($replacedQuery == "date between '" . $lastMonth['begin'] . "' and '" . $lastMonth['end'] . "'") ? '1' : '0';
|
||||
if(strpos($query, 'thisMonth') !== false) return ($replacedQuery == "date between '" . $thisMonth['begin'] . "' and '" . $thisMonth['end'] . "'") ? '1' : '0';
|
||||
if(strpos($query, 'yesterday') !== false) return ($replacedQuery == "date between '" . $yesterday . ' 00:00:00' . "' and '" . $yesterday . ' 23:59:59' . "'") ? '1' : '0';
|
||||
if(strpos($query, 'today') !== false) return ($replacedQuery == "date between '" . $today . ' 00:00:00' . "' and '" . $today . ' 23:59:59' . "'") ? '1' : '0';
|
||||
if(strpos($query, '$@me') !== false) return str_replace('$@me', \$this->instance->app->user->account, $query);
|
||||
|
||||
return $replacedQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试设置搜索条件。
|
||||
* Set condition test.
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $operator
|
||||
* @param string|int $value
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function setConditionTest($field, $operator, $value)
|
||||
{
|
||||
// setCondition method is in tao layer and is protected, use reflection to access it
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('setCondition');
|
||||
$method->setAccessible(true);
|
||||
return $method->invoke($this->instance, $field, $operator, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试设置搜索条件。
|
||||
* Set where test.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function setWhereTest(string $field, string $operator, string $value, string $andOr): string
|
||||
{
|
||||
$where = '';
|
||||
return $this->instance->setWhere($where, $field, $operator, $value, $andOr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,4 +99,603 @@ class storyTaoTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildReorderResult method.
|
||||
*
|
||||
* @param array $parent
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildReorderResultTest(array $parent): array
|
||||
{
|
||||
$result = array();
|
||||
$this->instance->buildReorderResult($parent, $result);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildStoryTree method.
|
||||
*
|
||||
* @param array $stories
|
||||
* @param int $parentId
|
||||
* @param array $originStories
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildStoryTreeTest(array $stories, int $parentId = 0, array $originStories = array()): array
|
||||
{
|
||||
$result = $this->instance->buildStoryTree($stories, $parentId, $originStories);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkCanSplit method.
|
||||
*
|
||||
* @param object $story
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCanSplitTest(object $story): bool
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('checkCanSplit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke($this->instance, $story);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkCanSubdivide method.
|
||||
*
|
||||
* @param object $story
|
||||
* @param bool $isShadowProduct
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCanSubdivideTest(object $story, bool $isShadowProduct): bool
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('checkCanSubdivide');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke($this->instance, $story, $isShadowProduct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkConditions method.
|
||||
*
|
||||
* @param string $method
|
||||
* @param object $story
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function checkConditionsTest(string $methodName, object $story): bool
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('checkConditions');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $methodName, $story);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 closeBugWhenToStory 方法。
|
||||
* Test closeBugWhenToStory.
|
||||
*
|
||||
* @param int $bugID
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function closeBugWhenToStoryTest(int $bugID, int $storyID): array
|
||||
{
|
||||
$this->instance->closeBugWhenToStory($bugID, $storyID);
|
||||
|
||||
if(empty($bugID) or empty($storyID)) return array();
|
||||
$bug = (array)$this->instance->dao->select('*')->from(TABLE_BUG)->where('id')->eq($bugID)->fetch();
|
||||
$bug['files'] = $this->instance->dao->select('*')->from(TABLE_FILE)->where('objectType')->eq('story')->andWhere('objectID')->eq($storyID)->fetchAll('id');
|
||||
return $bug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test computeStage method.
|
||||
*
|
||||
* @param array $children
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function computeStageTest(array $children): string
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('computeStage');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $children);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do string when change parent.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param object $story
|
||||
* @param object $oldStory
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
public function doChangeParentTest(int $storyID, object $story, object $oldStory)
|
||||
{
|
||||
$this->instance->doChangeParent($storyID, $story, $oldStory);
|
||||
return $this->instance->dao->select('*')->from(TABLE_STORY)->where('id')->in("$storyID,$story->parent,$oldStory->parent")->orWhere('parent')->in("$storyID,$story->parent,$oldStory->parent")->fetchAll('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 doCreateReviewer 方法。
|
||||
* Test doCreateReviewer method.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param array $reviewer
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function doCreateReviewerTest(int $storyID, array $reviewer): array
|
||||
{
|
||||
$this->instance->dao->delete()->from(TABLE_STORYREVIEW)->exec();
|
||||
$this->instance->doCreateReviewer($storyID, $reviewer);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->instance->dao->select('*')->from(TABLE_STORYREVIEW)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 doCreateSpec 方法。
|
||||
* Test doCreateSpec method.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param object $story
|
||||
* @param array $files
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function doCreateSpecTest(int $storyID, object $story, array $files = array()): array
|
||||
{
|
||||
$this->instance->dao->delete()->from(TABLE_STORYSPEC)->exec();
|
||||
$this->instance->doCreateSpec($storyID, $story, $files);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->instance->dao->select('*')->from(TABLE_STORYSPEC)->fetchAll('', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 doCreateStory 方法。
|
||||
* Test doCreateStory method.
|
||||
*
|
||||
* @param object $story
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function doCreateStoryTest(object $story): object|array
|
||||
{
|
||||
$this->instance->dao->delete()->from(TABLE_STORY)->exec();
|
||||
$storyID = $this->instance->doCreateStory($story);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->instance->dao->select('*')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个需求的基础信息。
|
||||
* Fetch base info of a story.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return object|bool
|
||||
*/
|
||||
public function fetchBaseInfoTest(int $storyID): object|false
|
||||
{
|
||||
return $this->instance->fetchBaseInfo($storyID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 fetchExecutionStories 方法。
|
||||
* Test fetchExecutionStories method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param int $product
|
||||
* @param object|null $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function fetchExecutionStoriesTest(int $executionID, int $productID, object|null $pager = null): array
|
||||
{
|
||||
$unclosedStatus = $this->instance->lang->story->statusList;
|
||||
unset($unclosedStatus['closed']);
|
||||
|
||||
$storyDAO = $this->instance->dao->select("DISTINCT t2.*")->from(TABLE_PROJECTSTORY)->alias('t1')
|
||||
->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id')
|
||||
->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t2.product = t3.id')
|
||||
->where('t1.project')->eq($executionID)
|
||||
->andWhere('t2.type')->eq('story')
|
||||
->andWhere('t2.deleted')->eq(0)
|
||||
->andWhere('t3.deleted')->eq(0);
|
||||
|
||||
return $this->instance->fetchExecutionStories($storyDAO, $productID, 'byBranch', '', 't2.id_desc', $pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 fetchProjectStories 方法。
|
||||
* Test fetchProjectStories method.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param int $projectID
|
||||
* @param string $type
|
||||
* @param string $branch
|
||||
* @param object|null $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function fetchProjectStoriesTest(int $productID, int $projectID, string $type = 'all', string $branch = '', object|null $pager = null): array
|
||||
{
|
||||
$unclosedStatus = $this->instance->lang->story->statusList;
|
||||
unset($unclosedStatus['closed']);
|
||||
|
||||
$storyIdList = array('1,2,3,4,5,6,7');
|
||||
$project = $this->instance->dao->select("*")->from(TABLE_PROJECT)->where('id')->eq($projectID)->fetch();
|
||||
$storyDAO = $this->instance->dao->select("DISTINCT t2.*")->from(TABLE_PROJECTSTORY)->alias('t1')
|
||||
->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id')
|
||||
->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t2.product = t3.id')
|
||||
->where('t1.project')->eq($projectID)
|
||||
->andWhere('t2.type')->eq('story')
|
||||
->andWhere('t2.deleted')->eq(0)
|
||||
->andWhere('t3.deleted')->eq(0);
|
||||
|
||||
return $this->instance->fetchProjectStories($storyDAO, $productID, $type, $branch, $storyIdList, 't2.id_desc', $pager, empty($project) ? null : $project);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 finishTodoWhenToStory 方法。
|
||||
* Test finishTodoWhenToStory.
|
||||
*
|
||||
* @param int $todoID
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function finishTodoWhenToStoryTest(int $todoID, int $storyID): string
|
||||
{
|
||||
$this->instance->finishTodoWhenToStory($todoID, $storyID);
|
||||
|
||||
if(empty($todoID) or empty($storyID)) return '';
|
||||
return $this->instance->dao->select('id,status')->from(TABLE_TODO)->where('id')->eq($todoID)->fetch('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 getAffectedBugs 方法
|
||||
* Test getAffectedBugs method
|
||||
*
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getAffectedBugsTest(int $storyID): object
|
||||
{
|
||||
global $tester;
|
||||
$users['admin'] = '管理员';
|
||||
$story = \$this->instance->loadModel('story')->getById($storyID);
|
||||
return $this->instance->getAffectedBugs($story, $users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 getAffectedCases 方法
|
||||
* Test getAffectedCases method
|
||||
*
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getAffectedCasesTest(int $storyID): object
|
||||
{
|
||||
global $tester;
|
||||
$users['admin'] = '管理员';
|
||||
$story = \$this->instance->loadModel('story')->getById($storyID);
|
||||
return $this->instance->getAffectedCases($story, $users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAffectedChildren method.
|
||||
*
|
||||
* @param object $story
|
||||
* @param array $users
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function getAffectedChildrenTest(object $story, array $users = array()): object|array
|
||||
{
|
||||
if(empty($users)) $users = array('admin' => '管理员');
|
||||
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getAffectedChildren');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $story, $users);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 getAffectedProjects 方法
|
||||
* Test getAffectedProjects method
|
||||
*
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getAffectedProjectsTest(int $storyID): object
|
||||
{
|
||||
global $tester;
|
||||
$users['admin'] = '管理员';
|
||||
$story = \$this->instance->loadModel('story')->getById($storyID);
|
||||
return $this->instance->getAffectedProjects($story, $users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 getAffectedTwins 方法
|
||||
* Test getAffectedTwins method
|
||||
*
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getAffectedTwinsTest(int $storyID): object
|
||||
{
|
||||
global $tester;
|
||||
$users['admin'] = '管理员';
|
||||
$story = \$this->instance->loadModel('story')->getById($storyID);
|
||||
return $this->instance->getAffectedTwins($story, $users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getChildItems method.
|
||||
*
|
||||
* @param array $stories
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getChildItemsTest(array $stories): array
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getChildItems');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $stories);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 getExecutionStoriesBySearch。
|
||||
* Test getExecutionStoriesBySearch method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param int $queryID
|
||||
* @param int $productID
|
||||
* @param array $excludeStories
|
||||
* @param object|null $pager
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getExecutionStoriesBySearchTest(int $executionID, int $queryID, int $productID, array $excludeStories = array(), object|null $pager = null): int
|
||||
{
|
||||
$stories = $this->instance->getExecutionStoriesBySearch($executionID, $queryID, $productID, 't2.id_desc', 'story', '', $excludeStories, $pager);
|
||||
return count($stories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getFinishClosedTotal method.
|
||||
*
|
||||
* @param string $storyType
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getFinishClosedTotalTest(string $storyType = 'story'): int
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getFinishClosedTotal');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $storyType);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return array_sum($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getStoriesCountByProductIDs method.
|
||||
*
|
||||
* @param array $productIDs
|
||||
* @param string $storyType
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getStoriesCountByProductIDsTest(array $productIDs, string $storyType = 'requirement'): array
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getStoriesCountByProductIDs');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $productIDs, $storyType);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getTasksForTrack method.
|
||||
*
|
||||
* @param array $storyIdList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTasksForTrackTest(array $storyIdList): array
|
||||
{
|
||||
$result = $this->instance->getTasksForTrack($storyIdList);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getUnClosedTotal method.
|
||||
*
|
||||
* @param string $storyType
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUnClosedTotalTest(string $storyType = 'story'): array
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getUnClosedTotal');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $storyType);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 linkToExecutionForCreate 方法。
|
||||
* Test linkToExecutionForCreate method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param int $storyID
|
||||
* @param string $extra
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function linkToExecutionForCreateTest(int $executionID, int $storyID, string $extra = ''): array
|
||||
{
|
||||
$this->instance->dao->delete()->from(TABLE_PROJECTSTORY)->exec();
|
||||
$this->instance->dao->delete()->from(TABLE_ACTION)->exec();
|
||||
$story = $this->instance->dao->select('*')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch();
|
||||
if(empty($story)) $story = new stdclass();
|
||||
|
||||
$this->instance->linkToExecutionForCreate($executionID, $storyID, $story, $extra);
|
||||
return array_filter((array)$this->instance->dao->select('*')->from(TABLE_ACTION)->orderBy('id_desc')->limit(1)->fetch());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 setStageToClosed 方法。
|
||||
* Test setStageToClosed method.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param array $linkedBranches
|
||||
* @param array $linkedProjects
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function setStageToClosedTest(int $storyID, array $linkedBranches = array(), array $linkedProjects = array()): object|array
|
||||
{
|
||||
$this->instance->setStageToClosed($storyID, $linkedBranches, $linkedProjects);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$story = $this->instance->dao->select('*')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch();
|
||||
$story->stages = $this->instance->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->orderBy('branch')->fetchAll();
|
||||
return $story;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 setStageToPlanned 方法。
|
||||
* Test setStageToPlanned method.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param array $stages
|
||||
* @param array $oldStages
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function setStageToPlannedTest(int $storyID, array $stages = array(), array $oldStages = array()): object|array
|
||||
{
|
||||
$this->instance->setStageToPlanned($storyID, $stages, $oldStages);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$story = $this->instance->dao->select('*')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch();
|
||||
$story->stages = $this->instance->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->orderBy('branch')->fetchAll();
|
||||
return $story;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateLane method.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param string $storyType
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateLaneTest(int $storyID, string $storyType)
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('updateLane');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $storyID, $storyType);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// updateLane方法实际没有返回值,返回执行状态
|
||||
return $result === null ? 'success' : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 updateStage 方法。
|
||||
* Test updateStage method.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param array $stages
|
||||
* @param array $oldStages
|
||||
* @param array $linkedProjects
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function updateStageTest(int $storyID, array $stages, array $oldStages = array(), array $linkedProjects = array()): object|array
|
||||
{
|
||||
$this->instance->updateStage($storyID, $stages, $oldStages, $linkedProjects);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$story = $this->instance->dao->select('*')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch();
|
||||
$story->stages = $this->instance->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->orderBy('branch')->fetchAll();
|
||||
return $story;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 updateTwins 方法。
|
||||
* Test updateTwins method.
|
||||
*
|
||||
* @param array $storyIdList
|
||||
* @param int $mainStoryID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function updateTwinsTest(array $storyIdList, int $mainStoryID): array
|
||||
{
|
||||
$this->instance->updateTwins($storyIdList, $mainStoryID);
|
||||
|
||||
if(empty($storyIdList)) return array();
|
||||
if($storyIdList)
|
||||
{
|
||||
$twins = $this->instance->dao->select('id,twins')->from(TABLE_STORY)->where('id')->in($storyIdList)->fetchPairs('id', 'twins');
|
||||
return array_map(function($item){return str_replace(',', ':', $item);}, $twins);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,535 @@ class taskTaoTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试根据父任务状态更新父任务信息。
|
||||
* Test update parent by status and child.
|
||||
*
|
||||
* @param object $parentTask
|
||||
* @param object $childTask
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function autoUpdateTaskByStatusTest(object $parentTask, object $childTask, string $status)
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$this->instance->autoUpdateTaskByStatus($parentTask, $childTask, $status);
|
||||
|
||||
$task = $this->instance->getByID(intval($parentTask->id));
|
||||
|
||||
if(!$task->finishedDate) $task->finishedDate = '';
|
||||
if(!$task->assignedDate) $task->assignedDate = '';
|
||||
if(!$task->closedDate) $task->closedDate = '';
|
||||
if(!$task->canceledDate) $task->canceledDate = '';
|
||||
if(!$task->lastEditedDate) $task->lastEditedDate = '';
|
||||
|
||||
$task->finishedDate = abs($now - strtotime($task->finishedDate));
|
||||
$task->assignedDate = abs($now - strtotime($task->assignedDate));
|
||||
$task->closedDate = abs($now - strtotime($task->closedDate));
|
||||
$task->canceledDate = abs($now - strtotime($task->canceledDate));
|
||||
$task->lastEditedDate = abs($now - strtotime($task->lastEditedDate));
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试通过记录日志改变任务的工时及状态。
|
||||
* Test change task's status and workhour by record effort.
|
||||
*
|
||||
* @param object $record
|
||||
* @param int $taskID
|
||||
* @param string $lastDate
|
||||
* @param bool $isFinishTask
|
||||
* @access public
|
||||
* @return array[]
|
||||
*/
|
||||
public function buildTaskForEffortTest(object $record, int $taskID, string $lastDate, bool $isFinishTask): array
|
||||
{
|
||||
$task = $this->instance->getByID($taskID);
|
||||
return $this->instance->buildTaskForEffort($record, $task, $lastDate, $isFinishTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试通过编辑日志修改任务信息的方法。
|
||||
* Test the method for update task information by updating the effort.
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param int $effortID
|
||||
* @param object $param
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function buildTaskForUpdateEffortTest(int $taskID, int $effortID, object $param): object
|
||||
{
|
||||
$task = $this->instance->getByID($taskID);
|
||||
$oldEffort = $this->instance->getEffortByID($effortID);
|
||||
|
||||
$effort = clone $oldEffort;
|
||||
foreach($param as $key => $value) $effort->{$key} = $value;
|
||||
|
||||
return $this->instance->buildTaskForUpdateEffort($task, $oldEffort, $effort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试将任务的层级改为父子结构。
|
||||
* Test change the hierarchy of tasks to a parent-child structure.
|
||||
*
|
||||
* @param array $taskIdList
|
||||
* @access public
|
||||
* @return object[]
|
||||
*/
|
||||
public function buildTaskTreeTest(array $taskIdList): array
|
||||
{
|
||||
$tasks = array();
|
||||
if(!empty($taskIdList)) $tasks = $this->instance->getByIdList($taskIdList);
|
||||
|
||||
$parentIdList = array();
|
||||
foreach($tasks as $task)
|
||||
{
|
||||
if($task->parent <= 0 or isset($tasks[$task->parent]) or isset($parentIdList[$task->parent])) continue;
|
||||
$parentIdList[$task->parent] = $task->parent;
|
||||
}
|
||||
$parentTasks = $this->instance->getByIdList($parentIdList);
|
||||
|
||||
return $this->instance->buildTaskTree($tasks, $parentTasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test check effort.
|
||||
*
|
||||
* @param int $effortID
|
||||
* @param array $effort
|
||||
* @access public
|
||||
* @return array|bool
|
||||
*/
|
||||
public function checkEffortTest(int $effortID, object $param): array|bool
|
||||
{
|
||||
$effort = $this->instance->getEffortByID($effortID);
|
||||
|
||||
foreach($param as $key => $value) $effort->{$key} = $value;
|
||||
$result = $this->instance->checkEffort($effort);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试计算当前任务状态。
|
||||
* Test compute the status of the current task.
|
||||
*
|
||||
* @param object $currentTask
|
||||
* @param object $oldTask
|
||||
* @param object $task
|
||||
* @param bool $condition true|false
|
||||
* @param bool $hasEfforts true|false
|
||||
* @param array $members
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function computeTaskStatusTest(object $currentTask, object $oldTask, object $task, bool $autoStatus, bool $hasEfforts, array $members): object|array
|
||||
{
|
||||
$task = $this->instance->computeTaskStatus($currentTask, $oldTask, $task, $autoStatus, $hasEfforts, $members);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制任务数据。
|
||||
* Copy the task data and update the effort to the new task.
|
||||
*
|
||||
* @param int $parentTaskID
|
||||
* @param string $testType subTaskEffort|childrenTask
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function copyTaskDataTest(int $parentTaskID, string $testType): object
|
||||
{
|
||||
$parentTask = $this->instance->dao->select('*')->from(TABLE_TASK)->where('id')->eq($parentTaskID)->fetch();
|
||||
foreach($parentTask as $key => $value)
|
||||
{
|
||||
if(strpos($key, 'Date')) unset($parentTask->$key);
|
||||
}
|
||||
|
||||
$this->instance->copyTaskData($parentTask);
|
||||
$taskID = $this->instance->dao->lastInsertID();
|
||||
|
||||
$testResult['subTaskEffort'] = $this->instance->dao->select('*')->from(TABLE_EFFORT)->where('objectID')->eq($taskID)->andWhere('objectType')->eq('task')->fetch();
|
||||
$testResult['childrenTask'] = $this->instance->dao->select('*')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch();
|
||||
|
||||
return $testResult[$testType];
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新父任务时记录日志。
|
||||
* Test create action record when update parent status.
|
||||
*
|
||||
* @param object $oldParentTask
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function createAutoUpdateTaskActionTest(object $oldParentTask)
|
||||
{
|
||||
$this->instance->createAutoUpdateTaskAction($oldParentTask);
|
||||
|
||||
return $this->instance->dao->select('action')->from(TABLE_ACTION)->where('objectType')->eq('task')->andWhere('objectID')->eq($oldParentTask->id)->orderBy('`id` desc')->fetch();;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test createChangesForTeam method.
|
||||
*
|
||||
* @param object $oldTask
|
||||
* @param object $task
|
||||
* @param array $teamData
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function createChangesForTeamTest(object $oldTask, object $task, array $teamData = array()): array
|
||||
{
|
||||
// Mock user pairs to avoid database call
|
||||
$users = array(
|
||||
'admin' => '管理员',
|
||||
'user1' => '用户1',
|
||||
'user2' => '用户2',
|
||||
'user3' => '用户3',
|
||||
'user4' => '用户4'
|
||||
);
|
||||
|
||||
// Create copies to avoid modifying the original objects
|
||||
$oldTaskCopy = clone $oldTask;
|
||||
$taskCopy = clone $task;
|
||||
|
||||
// Process old team information
|
||||
$oldTeams = $oldTaskCopy->team;
|
||||
$oldTaskCopy->team = '';
|
||||
foreach($oldTeams as $team) {
|
||||
$oldTaskCopy->team .= "团队成员: " . zget($users, $team->account) . ", 预计: " . (float)$team->estimate . ", 消耗: " . (float)$team->consumed . ", 剩余: " . (float)$team->left . "\n";
|
||||
}
|
||||
|
||||
// Process new team information
|
||||
$taskCopy->team = '';
|
||||
if(!empty($teamData['team']))
|
||||
{
|
||||
foreach($teamData['team'] as $i => $account)
|
||||
{
|
||||
if(empty($account)) continue;
|
||||
$taskCopy->team .= "团队成员: " . zget($users, $account) . ", 预计: " . zget($teamData['teamEstimate'], $i, 0) . ", 消耗: " . zget($teamData['teamConsumed'], $i, 0) . ", 剩余: " . zget($teamData['teamLeft'], $i, 0) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return array($oldTaskCopy, $taskCopy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update a task.
|
||||
*
|
||||
* @param int $objectID
|
||||
* @param array $param
|
||||
* @access public
|
||||
* @return array|object|string
|
||||
*/
|
||||
public function doUpdateTest(int $taskID, array $param = array()): array|object|string
|
||||
{
|
||||
$oldTask = $this->instance->fetchByID($taskID);
|
||||
$task = clone $oldTask;
|
||||
|
||||
foreach($task as $field => $value)
|
||||
{
|
||||
if(in_array($field, array_keys($param))) $task->$field = $param[$field];
|
||||
if(strpos($field, 'Date') && !$task->$field) $task->$field = null;
|
||||
}
|
||||
|
||||
$this->instance->doUpdate($task, $oldTask, $this->instance->config->task->edit->requiredFields);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->instance->fetchByID($taskID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试根据类型查询任务。
|
||||
* Test fetch tasks of a execution.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param int $productID
|
||||
* @param string|array $type all|assignedbyme|myinvolved|undone|needconfirm|assignedtome|finishedbyme|delayed|review|wait|doing|done|pause|cancel|closed|array('wait','doing','done','pause','cancel','closed')
|
||||
* @param array $modules
|
||||
* @param string $orderBy
|
||||
* @param int $count
|
||||
* @access public
|
||||
* @return object[]|int|bool
|
||||
*/
|
||||
public function fetchExecutionTasksTest(int $executionID, int $productID = 0, array|string $type = 'all', array $modules = array(), string $orderBy = 'status_asc, id_desc', int $count = 0): array|int|bool
|
||||
{
|
||||
$tasks = $this->instance->fetchExecutionTasks($executionID, $productID, $type, $modules, $orderBy);
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
elseif($count == "1")
|
||||
{
|
||||
return count($tasks);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $tasks;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过任务类型获取用户的任务。
|
||||
* Get user tasks by type.
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $assignedTo
|
||||
* @param string $orderBy
|
||||
* @param int $projectID
|
||||
* @param int $limit
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return object[]
|
||||
*/
|
||||
public function fetchUserTasksByTypeTest(string $account, string $type = 'assignedTo', string $orderBy = 'id_desc', int $projectID = 0, int $limit = 0, ?object $pager = null): array
|
||||
{
|
||||
$object = $this->instance->fetchUserTasksByType($account, $type, $orderBy, $projectID, $limit, $pager);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试删除工时后工时剩余。
|
||||
* Get the left after deleting workhour.
|
||||
*
|
||||
* @param int $effortID
|
||||
* @return object
|
||||
*/
|
||||
public function getLeftAfterDeleteWorkhourTest(int $effortID): object
|
||||
{
|
||||
$effort = $this->instance->getEffortByID($effortID);
|
||||
$task = $this->instance->getById($effort->objectID);
|
||||
|
||||
$result = new stdclass();
|
||||
$result->taskEstimate = $task->estimate;
|
||||
$result->taskConsumed = $task->consumed;
|
||||
$result->taskLeft = $task->left;
|
||||
|
||||
$result->effortLeft = $effort->left;
|
||||
$result->effortConsumed = $effort->consumed;
|
||||
|
||||
$result->left = $this->instance->getLeftAfterDeleteWorkhour($effort, $task);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRequiredFields4Edit method.
|
||||
*
|
||||
* @param object $task
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRequiredFields4EditTest(object $task)
|
||||
{
|
||||
// 使用反射调用受保护的方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getRequiredFields4Edit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $task);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试删除工时后获取工时信息。
|
||||
* Get task after deleting workhour.
|
||||
*
|
||||
* @param int $effortID
|
||||
* @return object
|
||||
*/
|
||||
public function getTaskAfterDeleteWorkhourTest(int $effortID): object
|
||||
{
|
||||
$effort = $this->instance->getEffortByID($effortID);
|
||||
$task = $this->instance->getById($effort->objectID);
|
||||
|
||||
return $this->instance->getTaskAfterDeleteWorkhour($effort, $task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getTeamInfoList method.
|
||||
*
|
||||
* @param array $teamList
|
||||
* @param array $teamSourceList
|
||||
* @param array $teamEstimateList
|
||||
* @param array $teamConsumedList
|
||||
* @param array $teamLeftList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTeamInfoListTest(array $teamList, array $teamSourceList, array $teamEstimateList, array $teamConsumedList, array $teamLeftList): array
|
||||
{
|
||||
// 使用反射调用受保护的方法
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('getTeamInfoList');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->instance, $teamList, $teamSourceList, $teamEstimateList, $teamConsumedList, $teamLeftList);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test recordTaskVersion method.
|
||||
*
|
||||
* @param object $task
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function recordTaskVersionTest(object $task): int
|
||||
{
|
||||
$reflection = new ReflectionClass($this->instance);
|
||||
$method = $reflection->getMethod('recordTaskVersion');
|
||||
$method->setAccessible(true);
|
||||
|
||||
try {
|
||||
$result = $method->invoke($this->instance, $task);
|
||||
if(dao::isError()) return 0;
|
||||
return $result ? 1 : 0;
|
||||
} catch (Exception $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resetEffortLeft method.
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return object|bool
|
||||
*/
|
||||
public function resetEffortLeftTest(int $taskID, string $account): object|bool
|
||||
{
|
||||
$this->instance->resetEffortLeft($taskID, array($account));
|
||||
if(dao::isError())
|
||||
{
|
||||
return !dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->instance->dao->select('*')->from(TABLE_EFFORT)
|
||||
->where('objectID')->eq($taskID)
|
||||
->andWhere('account')->eq($account)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->orderBy('date_desc,id_desc')
|
||||
->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 维护团队成员信息。
|
||||
* Maintain team member information.
|
||||
*
|
||||
* @param array $member
|
||||
* @param string $mode
|
||||
* @param bool $inTeam
|
||||
* @access public
|
||||
* @return array|object
|
||||
*/
|
||||
public function setTeamMemberObject(array $member, string $mode, bool $inTeam = false): array|object
|
||||
{
|
||||
$memberInfo = new stdclass();
|
||||
foreach($member as $field => $value) $memberInfo->{$field} = $value;
|
||||
$this->instance->setTeamMember($memberInfo, $mode, $inTeam);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $this->instance->dao->select('*')->from(TABLE_TASKTEAM)->where('task')->eq($memberInfo->task)->andWhere('account')->eq($memberInfo->account)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 updateRelation 方法
|
||||
* Test updateRelationq
|
||||
*
|
||||
* @param int $childID
|
||||
* @param int $parentID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateRelationTest(int $childID, int $parentID = 0)
|
||||
{
|
||||
$this->instance->updateRelation($childID, $parentID);
|
||||
$relation = $this->instance->dao->select('*')->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->fetch();
|
||||
|
||||
if(empty($relation)) return 'null';
|
||||
return $relation->BID;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过拖动甘特图修改任务的预计开始日期和截止日期。
|
||||
* Update task estimate date and deadline through gantt.
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $begin
|
||||
* @param string $end
|
||||
* @access public
|
||||
* @return array|bool
|
||||
*/
|
||||
public function updateTaskEsDateByGanttTest(int $taskID, string $begin, string $end): array|bool
|
||||
{
|
||||
$postData = new stdclass();
|
||||
$postData->id = $taskID;
|
||||
$postData->startDate = $begin;
|
||||
$postData->endDate = $end;
|
||||
$postData->type = 'task';
|
||||
|
||||
$this->instance->updateTaskEsDateByGantt($postData);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update team by effort.
|
||||
*
|
||||
* @param int $estimateID
|
||||
* @param object $record
|
||||
* @param int $taskID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function updateTeamByEffortTest(int $effortID, object $record, int $taskID, mix $task = null, string $lastDate): array
|
||||
{
|
||||
$task = $this->instance->getByID($taskID);
|
||||
$currentTeam = $this->instance->getTeamByAccount($task->team);
|
||||
$this->instance->updateTeamByEffort($effortID, $record, $currentTeam, $task, $lastDate);
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->instance->dao->select('*')->from(TABLE_TASKTEAM)->where('task')->eq($taskID)->fetchAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,36 @@ class taskZenTest extends baseTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processExportGroup method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param array $tasks
|
||||
* @param string $orderBy
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function processExportGroupTest(int $executionID, array $tasks, string $orderBy): array
|
||||
{
|
||||
try {
|
||||
// 使用 initReference 来获取 zen 类反射
|
||||
$taskZenRef = initReference('task');
|
||||
$method = $taskZenRef->getMethod('processExportGroup');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// 创建 zen 实例
|
||||
$taskZenInstance = $taskZenRef->newInstance();
|
||||
|
||||
$result = $method->invokeArgs($taskZenInstance, [$executionID, $tasks, $orderBy]);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
return array('error' => $e->getMessage());
|
||||
} catch (Throwable $e) {
|
||||
return array('error' => $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -61,7 +61,7 @@ class baseTest
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
protected $instance = null;
|
||||
public $instance = null;
|
||||
|
||||
/**
|
||||
* 被测试的类的反射对象。
|
||||
|
||||
Reference in New Issue
Block a user