diff --git a/module/testcase/control.php b/module/testcase/control.php index 099307d103..693c97c0b6 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1602,8 +1602,10 @@ class testcase extends control { if($_POST) { - $configResult = $this->testcase->saveXmindConfig(); - if($configResult['result'] == 'fail') return $this->send($configResult); + $configList = $this->testcaseZen->buildXmindConfig(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $configResult = $this->testcase->saveXmindConfig($configList); $imoduleID = $this->post->imodule ? $this->post->imoduleID : 0; $context = $this->testcase->getXmindExport($productID, $imoduleID, $branch); @@ -1686,7 +1688,7 @@ class testcase extends control * @access public * @return void */ - public function importXmind(int $productID, int|string $branch) + public function importXmind(int $productID, string $branch) { if($_FILES) { @@ -1694,8 +1696,9 @@ class testcase extends control /* 保存xmind配置。*/ /* Sav xmind config. */ - $configResult = $this->testcase->saveXmindConfig(); - if($configResult['result'] == 'fail') return $this->send($configResult); + $configList = $this->testcaseZen->buildXmindConfig(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + $configResult = $this->testcase->saveXmindConfig($configList); /* 检查扩展名。*/ /* Check extension name of file. */ diff --git a/module/testcase/lang/de.php b/module/testcase/lang/de.php index 155c129c7e..95dfa814c0 100644 --- a/module/testcase/lang/de.php +++ b/module/testcase/lang/de.php @@ -288,6 +288,7 @@ $lang->testcase->errorFileFormat = 'File format error'; $lang->testcase->moduleSelector = 'Module Selection'; $lang->testcase->errorImportBadProduct = 'Product does not exist, import error'; $lang->testcase->errorSceneNotExist = 'Scene [%d] not exists'; +$lang->testcase->errorXmindConfig = "%s characteristic character can only be 1-10 letters."; $lang->testcase->save = 'Save'; $lang->testcase->close = 'Close'; diff --git a/module/testcase/lang/en.php b/module/testcase/lang/en.php index 4a062bdc74..122f76027d 100644 --- a/module/testcase/lang/en.php +++ b/module/testcase/lang/en.php @@ -288,6 +288,7 @@ $lang->testcase->errorFileFormat = 'File format error'; $lang->testcase->moduleSelector = 'Module Selection'; $lang->testcase->errorImportBadProduct = 'Product does not exist, import error'; $lang->testcase->errorSceneNotExist = 'Scene [%d] not exists'; +$lang->testcase->errorXmindConfig = "%s characteristic character can only be 1-10 letters."; $lang->testcase->save = 'Save'; $lang->testcase->close = 'Close'; diff --git a/module/testcase/lang/fr.php b/module/testcase/lang/fr.php index d8eace9bb9..2df0adb8d1 100644 --- a/module/testcase/lang/fr.php +++ b/module/testcase/lang/fr.php @@ -288,6 +288,7 @@ $lang->testcase->errorFileFormat = 'File format error'; $lang->testcase->moduleSelector = 'Module Selection'; $lang->testcase->errorImportBadProduct = 'Product does not exist, import error'; $lang->testcase->errorSceneNotExist = 'Scene [%d] not exists'; +$lang->testcase->errorXmindConfig = "%s characteristic character can only be 1-10 letters."; $lang->testcase->save = 'Save'; $lang->testcase->close = 'Close'; diff --git a/module/testcase/lang/zh-cn.php b/module/testcase/lang/zh-cn.php index b0b1141285..b5b844d148 100644 --- a/module/testcase/lang/zh-cn.php +++ b/module/testcase/lang/zh-cn.php @@ -288,6 +288,7 @@ $lang->testcase->errorFileFormat = '文件格式错误'; $lang->testcase->moduleSelector = '模块选择'; $lang->testcase->errorImportBadProduct = '产品不存在,导入错误'; $lang->testcase->errorSceneNotExist = '场景[%d]不存在'; +$lang->testcase->errorXmindConfig = "%s特征字符串只能是1-10个字母"; $lang->testcase->save = '保存'; $lang->testcase->close = '关闭'; diff --git a/module/testcase/model.php b/module/testcase/model.php index ff4522ca9d..b62dd48731 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -2615,7 +2615,7 @@ class testcaseModel extends model return $result; } - $sceneIds[$tmpId] = array("id"=>$result['sceneID'], "tmpPId"=>$tmpPId); + $sceneIds[$tmpId] = array("id" => $result['sceneID'], "tmpPId" => $tmpPId); } $testcaseList = $this->post->testcaseList; @@ -2631,12 +2631,12 @@ class testcaseModel extends model return $result; } - $sceneIds[$tmpId] = array("id"=>$result['testcaseID'], "tmpPId"=>$tmpPId); + $sceneIds[$tmpId] = array("id" => $result['testcaseID'], "tmpPId" => $tmpPId); } $this->dao->commit(); - return array("result"=>"success","message"=>1); + return array('result' => 'success', 'message' => 1); } /** @@ -3021,59 +3021,15 @@ class testcaseModel extends model } /** + * 存储 xmind 配置。 * Save xmind config. * + * @param array $configList * @access public * @return array */ - function saveXmindConfig() + function saveXmindConfig(array $configList): array { - $configList = array(); - - $module = $this->post->module; - if(isset($module) && !empty($module)) - { - if(!$this->checkConfigValue($module)) return array('result' => 'fail', 'message' => '模块特征字符串只能是1-10个字母'); - $configList[] = array('key'=>'module','value'=>$module); - } - - $scene = $this->post->scene; - if(isset($scene) && !empty($scene)) - { - if(!$this->checkConfigValue($scene)) return array('result' => 'fail', 'message' => '场景特征字符串只能是1-10个字母'); - $configList[] = array('key'=>'scene','value'=>$scene); - } - - $case = $this->post->case; - if(isset($case) && !empty($case)) - { - if(!$this->checkConfigValue($case)) return array('result' => 'fail', 'message' => '测试用例特征字符串只能是1-10个字母'); - $configList[] = array('key'=>'case','value'=>$case); - } - - $pri = $this->post->pri; - if(isset($pri) && !empty($pri)) - { - if(!$this->checkConfigValue($pri)) return array('result' => 'fail', 'message' => '优先级特征字符串只能是1-10个字母'); - $configList[] = array('key'=>'pri','value'=>$pri); - } - - $group = $this->post->group; - if(isset($group) && !empty($group)) - { - if(!$this->checkConfigValue($group)) return array('result' => 'fail', 'message' => '步骤分组特征字符串只能是1-10个字母'); - $configList[] = array('key'=>'group','value'=>$group); - } - - $map = array(); - $map[strtolower($module)] = true; - $map[strtolower($scene)] = true; - $map[strtolower($case)] = true; - $map[strtolower($pri)] = true; - $map[strtolower($group)] = true; - - if(count($map) < 5) return array('result' => 'fail', 'message' => '特征字符串不能重复'); - $this->dao->begin(); $this->dao->delete()->from(TABLE_CONFIG) diff --git a/module/testcase/test/model/savexmindconfig.php b/module/testcase/test/model/savexmindconfig.php new file mode 100644 index 0000000000..061792ad1c --- /dev/null +++ b/module/testcase/test/model/savexmindconfig.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +saveXmindConfig(); +cid=1 +pid=1 + + +*/ + +$module = array('key' => 'module', 'value' => 'M'); +$scene = array('key' => 'scene', 'value' => 'S'); +$case = array('key' => 'case', 'value' => 'C'); +$pri = array('key' => 'pri', 'value' => 'P'); +$group = array('key' => 'group', 'value' => 'G'); + +$configList1 = array($module, $scene); +$configList2 = array($scene, $case); +$configList3 = array($case, $pri); +$configList4 = array($pri, $group); +$configList5 = array($group, $module); + +$testcase = new testCaseTest(); +r($testcase->saveXmindConfigTest($configList1)) && p() && e('module:M,scene:S'); // 测试存储 xmind 导出的配置 module scene +r($testcase->saveXmindConfigTest($configList2)) && p() && e('scene:S,case:C'); // 测试存储 xmind 导出的配置 scene case +r($testcase->saveXmindConfigTest($configList3)) && p() && e('case:C,pri:P'); // 测试存储 xmind 导出的配置 case pri +r($testcase->saveXmindConfigTest($configList4)) && p() && e('pri:P,group:G'); // 测试存储 xmind 导出的配置 pri group +r($testcase->saveXmindConfigTest($configList5)) && p() && e('group:G,module:M'); // 测试存储 xmind 导出的配置 group pri diff --git a/module/testcase/test/testcase.class.php b/module/testcase/test/testcase.class.php index fbd52ae81a..e2217a61ae 100644 --- a/module/testcase/test/testcase.class.php +++ b/module/testcase/test/testcase.class.php @@ -1131,4 +1131,25 @@ class testcaseTest return trim($return); } + + /** + * 测试插入文件。 + * Test insert files. + * + * @param array $caseIdList + * @access public + * @return string + */ + public function saveXmindConfigTest(array $configList): string + { + $this->objectModel->saveXmindConfig($configList); + + if(dao::isError()) return dao::getError()[0]; + + $return = ''; + global $tester; + $configs = $tester->dao->select('*')->from(TABLE_CONFIG)->where('section')->eq('xmind')->andWhere('module')->eq('testcase')->andWhere('owner')->eq($tester->app->user->account)->fetchAll('id'); + foreach($configs as $config) $return .= "{$config->key}:{$config->value},"; + return trim($return, ','); + } } diff --git a/module/testcase/ui/exportxmind.html.php b/module/testcase/ui/exportxmind.html.php index ba5eaef350..92f30776d7 100644 --- a/module/testcase/ui/exportxmind.html.php +++ b/module/testcase/ui/exportxmind.html.php @@ -14,7 +14,6 @@ set::title($lang->testcase->exportXmind); form ( - set::target('_self'), on::submit('setDownloading'), formGroup ( diff --git a/module/testcase/zen.php b/module/testcase/zen.php index 19ef586cac..300e4446f1 100644 --- a/module/testcase/zen.php +++ b/module/testcase/zen.php @@ -1748,6 +1748,52 @@ class testcaseZen extends testcase return $cases; } + /** + * 检查 xmind 配置。 + * Build xmind config. + * + * @access protected + * @return array|bool + */ + protected function buildXmindConfig(): array|bool + { + $configList = array(); + + $module = $this->post->module; + if(!empty($module)) $configList[] = array('key' => 'module', 'value' => $module); + + $scene = $this->post->scene; + if(!empty($scene)) $configList[] = array('key' => 'scene', 'value' => $scene); + + $case = $this->post->case; + if(!empty($case)) $configList[] = array('key' => 'case', 'value' => $case); + + $pri = $this->post->pri; + if(!empty($pri)) $configList[] = array('key' => 'pri', 'value' => $pri); + + $group = $this->post->group; + if(!empty($group)) $configList[] = array('key' => 'group', 'value' => $group); + + $configErrors = array(); + foreach($configList as $config) + { + $key = $config['key']; + $value = $config['value']; + if(!$this->testcase->checkConfigValue($value)) $configErrors[$key][] = sprintf($this->lang->testcase->errorXmindConfig, $this->lang->testcase->{$key}); + } + if(!empty($configErrors)) dao::$errors = $configErrors; + + $map = array(); + $map[strtolower($module)] = true; + $map[strtolower($scene)] = true; + $map[strtolower($case)] = true; + $map[strtolower($pri)] = true; + $map[strtolower($group)] = true; + + if(count($map) < 5 && count($map) > 0) dao::$errors['message'][] = '特征字符串不能重复'; + return !dao::isError() ? $configList : false; + } + /** * 初始化用例数据。 * Initialize the testcase.