* Refactor transfer model: setListValue method.

This commit is contained in:
tanghucheng
2023-12-19 03:15:47 -05:00
parent 3f6c6ed94b
commit d456e06920
5 changed files with 99 additions and 18 deletions
+5 -5
View File
@@ -14,7 +14,7 @@ $config->bug->dtable->fieldList['product']['display'] = false;
$config->bug->dtable->fieldList['product']['dataSource'] = array('module' => 'product', 'method' => 'getPairs', 'params' => ['mode' => '', 'programID' => 0, 'append' => '', 'shadow' => 'all']);
$config->bug->dtable->fieldList['module']['display'] = false;
$config->bug->dtable->fieldList['module']['dataSource'] = array('module' => 'tree', 'method' => 'getOptionMenu', 'params' => ['rootID' => '$productID', 'type' => 'bug', 'startModule' => 0, 'branch' => 'all']);
$config->bug->dtable->fieldList['module']['dataSource'] = array('module' => 'tree', 'method' => 'getOptionMenu', 'params' => ['rootID' => (int)'$productID', 'type' => 'bug', 'startModule' => 0, 'branch' => 'all']);
$config->bug->dtable->fieldList['title']['title'] = $lang->bug->title;
$config->bug->dtable->fieldList['title']['type'] = 'title';
@@ -54,7 +54,7 @@ $config->bug->dtable->fieldList['type']['sortType'] = true;
$config->bug->dtable->fieldList['branch']['title'] = $lang->bug->branch;
$config->bug->dtable->fieldList['branch']['type'] = 'text';
$config->bug->dtable->fieldList['branch']['group'] = 3;
$config->bug->dtable->fieldList['branch']['dataSource'] = array('module' => 'branch', 'method' => 'getPairs', 'params' => '$productID');
$config->bug->dtable->fieldList['branch']['dataSource'] = array('module' => 'branch', 'method' => 'getPairs', 'params' => ['productID' => (int)'$productID']);
$config->bug->dtable->fieldList['branch']['sortType'] = true;
$config->bug->dtable->fieldList['project']['title'] = $lang->bug->project;
@@ -66,7 +66,7 @@ $config->bug->dtable->fieldList['project']['sortType'] = true;
$config->bug->dtable->fieldList['execution']['title'] = $lang->bug->execution;
$config->bug->dtable->fieldList['execution']['type'] = 'text';
$config->bug->dtable->fieldList['execution']['group'] = 3;
$config->bug->dtable->fieldList['execution']['dataSource'] = array('module' => 'execution', 'method' =>'getPairs');
$config->bug->dtable->fieldList['execution']['dataSource'] = array('module' => 'execution', 'method' =>'getPairs', 'params' => ['projectID' => 0]);
$config->bug->dtable->fieldList['execution']['sortType'] = true;
$config->bug->dtable->fieldList['plan']['title'] = $lang->bug->plan;
@@ -78,7 +78,7 @@ $config->bug->dtable->fieldList['openedBuild']['title'] = $lang->bug->opene
$config->bug->dtable->fieldList['openedBuild']['type'] = 'text';
$config->bug->dtable->fieldList['openedBuild']['group'] = 3;
$config->bug->dtable->fieldList['openedBuild']['control'] = 'multiple';
$config->bug->dtable->fieldList['openedBuild']['dataSource'] = array('module' => 'build', 'method' =>'getBuildPairs', 'params' => '$productID&$branch&noempty,noterminate,nodone,withbranch');
$config->bug->dtable->fieldList['openedBuild']['dataSource'] = array('module' => 'build', 'method' =>'getBuildPairs', 'params' => ['productIdList' => (int)'$productID', 'branch' => '$branch', 'params' => 'noempty,noterminate,nodone,withbranch']);
$config->bug->dtable->fieldList['openedBuild']['sortType'] = true;
$config->bug->dtable->fieldList['openedBy']['title'] = $lang->bug->abbr->openedBy;
@@ -175,7 +175,7 @@ $config->bug->dtable->fieldList['story']['title'] = $lang->bug->story;
$config->bug->dtable->fieldList['story']['type'] = 'text';
$config->bug->dtable->fieldList['story']['link'] = array('module' => 'story', 'method' => 'view', 'params' => 'storyID={story}');
$config->bug->dtable->fieldList['story']['group'] = 8;
$config->bug->dtable->fieldList['story']['dataSource'] = array('module' => 'story', 'method' =>'getProductStoryPairs', 'params' => '$productID');
$config->bug->dtable->fieldList['story']['dataSource'] = array('module' => 'story', 'method' =>'getProductStoryPairs', 'params' => ['productIdList' => (int)'$productID']);
$config->bug->dtable->fieldList['story']['sortType'] = true;
$config->bug->dtable->fieldList['task']['title'] = $lang->bug->task;
+4 -4
View File
@@ -22,7 +22,7 @@ $config->testcase->dtable->fieldList['title']['data-app'] = $app->tab;
$config->testcase->dtable->fieldList['branch']['title'] = $lang->testcase->branch;
$config->testcase->dtable->fieldList['branch']['type'] = 'text';
$config->testcase->dtable->fieldList['branch']['group'] = 2;
$config->testcase->dtable->fieldList['branch']['dataSource'] = array('module' => 'branch', 'method' => 'getPairs', 'params' => '$productID');
$config->testcase->dtable->fieldList['branch']['dataSource'] = array('module' => 'branch', 'method' => 'getPairs', 'params' => ['productID' => (int)'$productID']);
$config->testcase->dtable->fieldList['pri']['title'] = $lang->testcase->pri;
$config->testcase->dtable->fieldList['pri']['type'] = 'pri';
@@ -57,7 +57,7 @@ $config->testcase->dtable->fieldList['story']['type'] = 'desc';
$config->testcase->dtable->fieldList['story']['link'] = array('module' => 'story', 'method' => 'view', 'params' => "storyID={story}");
$config->testcase->dtable->fieldList['story']['group'] = 3;
$config->testcase->dtable->fieldList['story']['control'] = 'select';
$config->testcase->dtable->fieldList['story']['dataSource'] = array('module' => 'story', 'method' => 'getProductStoryPairs', 'params' => '$productID&$branch');
$config->testcase->dtable->fieldList['story']['dataSource'] = array('module' => 'story', 'method' => 'getProductStoryPairs', 'params' => ['productIdList' => (int)'$productID', 'branch' => '$branch']);
$config->testcase->dtable->fieldList['keywords']['title'] = $lang->testcase->keywords;
$config->testcase->dtable->fieldList['keywords']['type'] = 'text';
@@ -139,11 +139,11 @@ $config->testcase->dtable->fieldList['lastEditedDate']['sortType'] = true;
$config->testcase->dtable->fieldList['product']['title'] = 'product';
$config->testcase->dtable->fieldList['product']['control'] = 'hidden';
$config->testcase->dtable->fieldList['product']['dataSource'] = array('module' => 'product', 'method' => 'getPairs', 'params' => '&0&&all');
$config->testcase->dtable->fieldList['product']['dataSource'] = array('module' => 'product', 'method' => 'getPairs', 'params' => ['mode' => '', 'programID' => 0, 'append' => '', 'shadow' => 'all']);
$config->testcase->dtable->fieldList['product']['display'] = false;
$config->testcase->dtable->fieldList['module']['control'] = 'select';
$config->testcase->dtable->fieldList['module']['dataSource'] = array('module' => 'testcase', 'method' => 'getDatatableModules', 'params' => '$productID');
$config->testcase->dtable->fieldList['module']['dataSource'] = array('module' => 'testcase', 'method' => 'getDatatableModules', 'params' => ['productID' => (int)'$productID']);
$config->testcase->dtable->fieldList['module']['display'] = false;
$config->testcase->dtable->fieldList['actions']['title'] = $lang->actions;
+23 -9
View File
@@ -216,11 +216,11 @@ class transferModel extends model
extract($fieldValue['dataSource']); // $module, $method, $params, $pairs, $sql, $lang
if(!empty($Module) and !empty($method))
if(!empty($module) and !empty($method))
{
$params = !empty($params) ? $params : '';
$pairs = !empty($pairs) ? $pairs : '';
$values = $this->transferTao->getSourceByModuleMethod($model, $Module, $method, $params, $pairs);
$values = $this->transferTao->getSourceByModuleMethod($model, $module, $method, $params, $pairs);
}
elseif(!empty($lang))
{
@@ -478,36 +478,50 @@ class transferModel extends model
}
/**
* 设置下拉字段数据。
* Set list value.
*
* @param int $module
* @param int $fieldList
* @param string $module
* @param array $fieldList
* @access public
* @return void/array
* @return array
*/
public function setListValue($module, $fieldList)
public function setListValue(string $module, array $fieldList)
{
$lists = array();
$this->commonActions($module);
if(!empty($this->moduleListFields))
{
$listFields = $this->moduleListFields;
/* 从fieldList和sysLangFields中为下拉字段赋值。*/
/* Set value from fieldList and sysLangFields. */
foreach($listFields as $field)
{
if(empty($field)) continue;
$listName = $field . 'List';
$listName = $field . 'List'; // 下拉字段以字段名 + List命名。
if(!empty($_POST[$listName])) continue;
$lists[$listName] = array();
if(!empty($fieldList[$field]))
{
$lists[$listName] = $fieldList[$field]['values'];
if(strpos($this->config->$module->sysLangFields, $field)) $lists[$listName] = implode(',', $fieldList[$field]['values']);
/* 从语言项里赋值。*/
/* Set value from lang. */
if(strpos($this->moduleConfig->sysLangFields, $field)) $lists[$listName] = implode(',', $fieldList[$field]['values']);
}
/* 将下拉字段赋值给excel->sysDataField。*/
/* Set value to excel->sysDataField. */
if(is_array($lists[$listName])) $this->config->excel->sysDataField[] = $field;
}
$lists['listStyle'] = $listFields;
}
/* 如果有级联字段,则加入级联字段列表(如用例的模块和相关需求)。*/
/* If has cascade field, add cascade field list. */
if(!empty($this->moduleConfig->cascade))
{
$lists = $this->getCascadeList($module, $lists);
@@ -0,0 +1,35 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/transfer.class.php';
zdTable('project')->gen(15);
zdTable('bug')->gen(10);
zdTable('case')->gen(10);
zdTable('story')->gen(10);
su('admin');
/**
title=测试 transfer->setListValue();
timeout=0
cid=1
- 测试导出bug类型字段的下拉值第typeList条的1属性 @代码错误
- 测试导出bug项目字段的下拉数量 @5
- 测试导出bug时下拉字段的数量 @10
- 测试导出用例时story字段的下拉数量 @5
- 测试导出用例时的级联字段第cascade条的story属性 @module
*/
$transfer = new transferTest();
$result1 = $transfer->setListValueTest('bug');
$result1['typeList'] = explode(',', $result1['typeList']);
r($result1) && p('typeList:1') && e('代码错误'); // 测试导出bug类型字段的下拉值
r(count($result1['projectList'])) && p('') && e('5'); // 测试导出bug项目字段的下拉数量
r(count($result1['listStyle'])) && p('') && e('10'); // 测试导出bug时下拉字段的数量
$result2 = $transfer->setListValueTest('testcase');
r(count($result2['storyList'])) && p('') && e('5'); // 测试导出用例时story字段的下拉数量
r($result2) && p('cascade:story') && e('module'); // 测试导出用例时的级联字段
+32
View File
@@ -54,4 +54,36 @@ class transferTest
if(!empty($result[$index]->files)) return 'File isset';
return 'No File';
}
/**
* 测试setListValue
* setListValueTest
*
* @param string $module
* @access public
* @return array
*/
public function setListValueTest(string $module = '')
{
global $tester, $app;
$app->methodName = 'ajaxgettbody';
$_SESSION['testcaseTransferParams']['productID'] = '0';
$_SESSION['testcaseTransferParams']['branch'] = '0';
$object = $tester->loadModel($module);
$fields = isset($object->config->$module->exportFields) ? $object->config->$module->exportFields : '';
$object->config->bug->listFields = "module,project,execution,story,severity,pri,type,os,browser,openedBuild";
if($module == 'testcase')
{
$app->config->testcase->cascade = array('story' => 'module');
$app->config->testcase->listFields = 'module,type,stage,pri,story,status,branch,results';
}
$fields = explode(',', $fields);
$fieldList = $this->objectModel->initFieldList($module, $fields);
return $this->objectModel->setListValue($module, $fieldList);
}
}