* Optimize create function on testtask.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
$config->testtask = new stdclass();
|
||||
$config->testtask->create = new stdclass();
|
||||
$config->testtask->edit = new stdclass();
|
||||
$config->testtask->create->requiredFields = 'build,begin,end,name';
|
||||
$config->testtask->create->requiredFields = 'product,status,build,begin,end,name';
|
||||
$config->testtask->edit->requiredFields = 'build,begin,end,name';
|
||||
|
||||
$config->testtask->actions = new stdclass();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
global $lang, $app;
|
||||
|
||||
$config->testtask->form = new stdclass();
|
||||
$config->testtask->form->create = array();
|
||||
$config->testtask->form->create['product'] = array('required' => true, 'type' => 'int', 'default' => '');
|
||||
$config->testtask->form->create['execution'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->testtask->form->create['build'] = array('required' => true, 'type' => 'string', 'default' => '');
|
||||
$config->testtask->form->create['type'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->testtask->form->create['owner'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->testtask->form->create['begin'] = array('required' => true, 'type' => 'date', 'default' => '');
|
||||
$config->testtask->form->create['end'] = array('required' => true, 'type' => 'date', 'default' => '');
|
||||
$config->testtask->form->create['status'] = array('required' => true, 'type' => 'string', 'default' => 'wait');
|
||||
$config->testtask->form->create['testreport'] = array('required' => false, 'type' => 'int', 'default' => '0');
|
||||
$config->testtask->form->create['name'] = array('required' => true, 'type' => 'string', 'default' => 0);
|
||||
$config->testtask->form->create['pri'] = array('required' => false, 'type' => 'int', 'default' => 3);
|
||||
$config->testtask->form->create['desc'] = array('required' => false, 'type' => 'string', 'default' => '', 'control' => 'editor');
|
||||
$config->testtask->form->create['mailto'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
+49
-41
@@ -212,6 +212,7 @@ class testtask extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建测试单页面和创建表单的提交。
|
||||
* Create a test task.
|
||||
*
|
||||
* @param int $productID
|
||||
@@ -221,67 +222,74 @@ class testtask extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function create($productID, $executionID = 0, $build = 0, $projectID = 0)
|
||||
public function create(int $productID, int $executionID = 0, int $build = 0, int $projectID = 0)
|
||||
{
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$taskID = $this->testtask->create($projectID);
|
||||
/* 表单数据的收集和组装。 */
|
||||
$formData = form::data($this->config->testtask->form->create)
|
||||
->setDefault('project', $projectID)
|
||||
->setDefault('createdBy', $this->app->user->account)
|
||||
->setDefault('createdDate', helper::now())
|
||||
->get();
|
||||
|
||||
$formData = $this->loadModel('file')->processImgURL($formData, $this->config->testtask->editor->create['id'], $this->post->uid);
|
||||
if($formData->execution)
|
||||
{
|
||||
$execution = $this->loadModel('execution')->getByID($formData->execution);
|
||||
$formData->projectID = $execution->project;
|
||||
}
|
||||
|
||||
/* 进行测试单数据插入操作。 */
|
||||
$taskID = $this->testtask->create($formData);
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
$this->loadModel('action')->create('testtask', $taskID, 'opened');
|
||||
|
||||
/* 插入数据后对上传的文件进行处理。 */
|
||||
$this->loadModel('file')->updateObjectID($this->post->uid, $taskID, 'testtask');
|
||||
$this->file->saveUpload('testtask', $taskID);
|
||||
|
||||
/* 执行工作流的扩展动作并返回提示消息。 */
|
||||
$message = $this->executeHooks($taskID);
|
||||
if($message) $this->lang->saveSuccess = $message;
|
||||
|
||||
if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $taskID));
|
||||
if(!$message) $message = $this->lang->saveSuccess;
|
||||
|
||||
/* 根据不同的应用生成不同的跳转链接。 */
|
||||
$task = $this->dao->findById($taskID)->from(TABLE_TESTTASK)->fetch();
|
||||
if($this->app->tab == 'project') $link = $this->createLink('project', 'testtask', "projectID=$task->project");
|
||||
if($this->app->tab == 'project') $link = $this->createLink('project', 'testtask', "projectID=$task->project");
|
||||
if($this->app->tab == 'execution') $link = $this->createLink('execution', 'testtask', "executionID=$task->execution");
|
||||
if($this->app->tab == 'qa') $link = $this->createLink('testtask', 'browse', "productID=" . $this->post->product);
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link));
|
||||
if($this->app->tab == 'qa') $link = $this->createLink('testtask', 'browse', "productID=" . $this->post->product);
|
||||
return $this->send(array('result' => 'success', 'message' => $message, 'load' => $link, 'id' => $taskID));
|
||||
}
|
||||
|
||||
$this->loadModel('project');
|
||||
if($executionID)
|
||||
{
|
||||
/* 根据所选迭代的类型,调整表单字段的文本显示。 */
|
||||
$execution = $this->loadModel('execution')->getByID($executionID);
|
||||
if(!empty($execution) and $execution->type == 'kanban') $this->lang->testtask->execution = str_replace($this->lang->execution->common, $this->lang->kanban->common, $this->lang->testtask->execution);
|
||||
}
|
||||
|
||||
if($projectID)
|
||||
{
|
||||
/* 如果是无迭代项目, 则获取影子迭代的迭代ID */
|
||||
$project = $this->loadModel('project')->getByID($projectID);
|
||||
if($project && !$project->multiple) $this->view->noMultipleExecutionID = $this->loadModel('execution')->getNoMultipleID($project->id);
|
||||
}
|
||||
|
||||
/* Set menu. */
|
||||
if($this->app->tab == 'project')
|
||||
{
|
||||
$this->project->setMenu($projectID);
|
||||
}
|
||||
elseif($this->app->tab == 'execution')
|
||||
{
|
||||
$this->loadModel('execution')->setMenu($executionID);
|
||||
}
|
||||
elseif($this->app->tab == 'qa')
|
||||
{
|
||||
$this->loadModel('qa')->setMenu($this->products, $productID);
|
||||
}
|
||||
|
||||
/* Create testtask from testtask of test.*/
|
||||
$productID = $productID ? $productID : key($this->products);
|
||||
$executions = empty($productID) ? array() : $this->loadModel('product')->getExecutionPairsByProduct($productID, '', 'id_desc', $projectID, 'stagefilter');
|
||||
$builds = empty($productID) ? array() : $this->loadModel('build')->getBuildPairs($productID, 'all', 'notrunk,withexecution', $projectID, 'project', '', false);
|
||||
|
||||
$execution = $this->loadModel('execution')->getByID($executionID);
|
||||
if(!empty($execution) and $execution->type == 'kanban') $this->lang->testtask->execution = str_replace($this->lang->execution->common, $this->lang->kanban->common, $this->lang->testtask->execution);
|
||||
|
||||
/* Set menu. */
|
||||
$productID = $this->product->saveState($productID, $this->products);
|
||||
|
||||
$project = $this->project->getByID($projectID);
|
||||
if($project && !$project->multiple) $this->view->noMultipleExecutionID = $this->loadModel('execution')->getNoMultipleID($project->id);
|
||||
|
||||
$this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testtask->create;
|
||||
$products = $this->testtaskZen->getProducts();
|
||||
$productID = $this->loadModel('product')->saveState($productID, $products);
|
||||
if($this->app->tab == 'project') $this->loadModel('project')->setMenu($projectID);
|
||||
if($this->app->tab == 'execution') $this->loadModel('execution')->setMenu($executionID);
|
||||
if($this->app->tab == 'qa') $this->loadModel('qa')->setMenu($products, $productID);
|
||||
|
||||
$this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testtask->create;
|
||||
$this->view->product = $this->product->getByID($productID);
|
||||
$this->view->projectID = $projectID;
|
||||
$this->view->executionID = $executionID;
|
||||
$this->view->executions = $executions;
|
||||
$this->view->builds = $builds;
|
||||
$this->view->executions = $productID ? $this->loadModel('product')->getExecutionPairsByProduct($productID, '', 'id_desc', $projectID, 'stagefilter') : array();
|
||||
$this->view->builds = $productID ? $this->loadModel('build')->getBuildPairs($productID, 'all', 'notrunk,withexecution', $projectID, 'project', '', false) : array();
|
||||
$this->view->build = $build;
|
||||
$this->view->testreports = array('') + $this->loadModel('testreport')->getPairs($productID);
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noclosed|qdfirst|nodeleted');
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
|
||||
+12
-29
@@ -14,46 +14,29 @@
|
||||
class testtaskModel extends model
|
||||
{
|
||||
/**
|
||||
* 创建一个测试单。
|
||||
* Create a test task.
|
||||
*
|
||||
* @param int $projectID
|
||||
* @param object $testtask
|
||||
* @access public
|
||||
* @return void
|
||||
* @return int|false
|
||||
*/
|
||||
function create($projectID = 0)
|
||||
function create(object $testtask): int|false
|
||||
{
|
||||
if($this->post->execution)
|
||||
{
|
||||
$execution = $this->loadModel('execution')->getByID($this->post->execution);
|
||||
$projectID = $execution->project;
|
||||
}
|
||||
|
||||
$task = fixer::input('post')
|
||||
->setDefault('build', '')
|
||||
->setDefault('project', $projectID)
|
||||
->setDefault('createdBy', $this->app->user->account)
|
||||
->setDefault('createdDate', helper::now())
|
||||
->stripTags($this->config->testtask->editor->create['id'], $this->config->allowedTags)
|
||||
->join('mailto', ',')
|
||||
->join('type', ',')
|
||||
->remove('files,labels,uid,contactListMenu')
|
||||
->get();
|
||||
|
||||
$task = $this->loadModel('file')->processImgURL($task, $this->config->testtask->editor->create['id'], $this->post->uid);
|
||||
$this->dao->insert(TABLE_TESTTASK)->data($task)
|
||||
$this->dao->insert(TABLE_TESTTASK)->data($testtask)
|
||||
->autoCheck($skipFields = 'begin,end')
|
||||
->batchcheck($this->config->testtask->create->requiredFields, 'notempty')
|
||||
->checkIF($task->begin != '', 'begin', 'date')
|
||||
->checkIF($task->end != '', 'end', 'date')
|
||||
->checkIF($task->end != '', 'end', 'ge', $task->begin)
|
||||
->checkIF(!empty($testtask->begin) && $testtask->begin != '', 'begin', 'date')
|
||||
->checkIF(!empty($testtask->end) && $testtask->end != '', 'end', 'date')
|
||||
->checkIF(!empty($testtask->begin) && $testtask->begin != '', 'end', 'ge', zget($testtask, 'begin', ''))
|
||||
->checkFlow()
|
||||
->exec();
|
||||
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$taskID = $this->dao->lastInsertID();
|
||||
$this->file->updateObjectID($this->post->uid, $taskID, 'testtask');
|
||||
$this->file->saveUpload('testtask', $taskID);
|
||||
$this->loadModel('action')->create('testtask', $taskID, 'opened');
|
||||
|
||||
return $taskID;
|
||||
}
|
||||
|
||||
@@ -1808,8 +1791,8 @@ class testtaskModel extends model
|
||||
public function getToAndCcList($testtask)
|
||||
{
|
||||
/* Set toList and ccList. */
|
||||
$toList = $testtask->owner;
|
||||
$ccList = str_replace(' ', '', trim($testtask->mailto, ','));
|
||||
$toList = zget($testtask, 'owner', '');
|
||||
$ccList = str_replace(' ', '', trim(zget($testtask, 'mailto', ''), ','));
|
||||
|
||||
if(empty($toList))
|
||||
{
|
||||
|
||||
@@ -7,36 +7,77 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 testtaskModel->create();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
新增一个正常的测试单 >> 11,新增测试报告,200,1,system
|
||||
新增一个名称为空的测试单 >> 『名称』不能为空。
|
||||
新增一个结束日期小于开始日期的测试单 >> 『结束日期』应当不小于『2022-10-05』。
|
||||
- 新增一个正常的测试单是否成功 @1
|
||||
|
||||
*/
|
||||
- 所属产品为空的时候插入是否成功 @0
|
||||
|
||||
$testtask = new testtaskTest();
|
||||
- 所属版本为空的时候插入是否成功 @0
|
||||
|
||||
$normalTask['product'] = 1;
|
||||
$normalTask['execution'] = 200;
|
||||
$normalTask['build'] = 11;
|
||||
$normalTask['type'] = 'system';
|
||||
$normalTask['owner'] = 'test10';
|
||||
$normalTask['pri'] = 3;
|
||||
$normalTask['begin'] = '2022-03-05';
|
||||
$normalTask['end'] = '2022-09-05';
|
||||
$normalTask['status'] = 'wait';
|
||||
$normalTask['name'] = '新增测试单';
|
||||
$normalTask['desc'] = '新增测试单的描述详情';
|
||||
- 开始时间为空的时候插入是否成功 @0
|
||||
|
||||
$emptyNameTask = $normalTask;
|
||||
$emptyNameTask['name'] = '';
|
||||
- 结束时间为空的时候插入是否成功 @0
|
||||
|
||||
$beginGtEndTask = $normalTask;
|
||||
$beginGtEndTask['begin'] = '2022-10-05';
|
||||
- 开始时间不符合日期规范的时候插入是否成功 @0
|
||||
|
||||
r($testtask->create(11, $normalTask)) && p('id,name,execution,product,type') && e('11,新增测试报告,200,1,system'); // 新增一个正常的测试单
|
||||
r($testtask->create(12, $emptyNameTask)) && p('name:0') && e('『名称』不能为空。'); // 新增一个名称为空的测试单
|
||||
r($testtask->create(13, $beginGtEndTask)) && p('end:0') && e('『结束日期』应当不小于『2022-10-05』。'); // 新增一个结束日期小于开始日期的测试单
|
||||
- 结束时间不符合日期规范的时候插入是否成功 @0
|
||||
|
||||
- 开始时间比结束时间大的时候插入是否成功 @0
|
||||
|
||||
- 状态为空的时候插入是否成功 @0
|
||||
|
||||
- 名称为空的时候插入是否成功 @0
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('testtask');
|
||||
|
||||
$formData = new stdclass();
|
||||
$formData->product = 1;
|
||||
$formData->build = 1;
|
||||
$formData->begin = date('Y-m-d');
|
||||
$formData->end = date('Y-m-d');
|
||||
$formData->status = 'wait';
|
||||
$formData->name = '测试单';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('1'); // 新增一个正常的测试单是否成功
|
||||
|
||||
$formData->product = 0;
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 所属产品为空的时候插入是否成功
|
||||
$formData->product = 1;
|
||||
|
||||
$formData->build = 0;
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 所属版本为空的时候插入是否成功
|
||||
$formData->build = 1;
|
||||
|
||||
$formData->begin = '';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 开始时间为空的时候插入是否成功
|
||||
$formData->begin = date('Y-m-d');
|
||||
|
||||
$formData->end = '';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 结束时间为空的时候插入是否成功
|
||||
$formData->end = date('Y-m-d');
|
||||
|
||||
$formData->begin = 'asdd';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 开始时间不符合日期规范的时候插入是否成功
|
||||
$formData->begin = date('Y-m-d');
|
||||
|
||||
$formData->end = 'asdd';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 结束时间不符合日期规范的时候插入是否成功
|
||||
$formData->end = date('Y-m-d');
|
||||
|
||||
$formData->begin = '2023-10-11';
|
||||
$formData->end = '2023-10-10';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 开始时间比结束时间大的时候插入是否成功
|
||||
$formData->begin = date('Y-m-d');
|
||||
$formData->end = date('Y-m-d');
|
||||
|
||||
$formData->status = '';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 状态为空的时候插入是否成功
|
||||
$formData->status = 'wait';
|
||||
|
||||
$formData->name = '';
|
||||
r((bool)$tester->testtask->create($formData)) && p() && e('0'); // 名称为空的时候插入是否成功
|
||||
$formData->name = '测试单';
|
||||
|
||||
@@ -87,10 +87,12 @@ formPanel
|
||||
(
|
||||
set::width('1/2'),
|
||||
set::label($lang->testtask->type),
|
||||
set::name('type[]'),
|
||||
set::control('picker'),
|
||||
set::items($lang->testtask->typeList),
|
||||
set::multiple(true),
|
||||
picker
|
||||
(
|
||||
set::multiple(true),
|
||||
set::name('type[]'),
|
||||
set::items($lang->testtask->typeList),
|
||||
)
|
||||
),
|
||||
formGroup
|
||||
(
|
||||
@@ -178,10 +180,12 @@ formPanel
|
||||
formGroup
|
||||
(
|
||||
set::label($lang->testtask->mailto),
|
||||
set::name('mailto[]'),
|
||||
set::control('picker'),
|
||||
set::items($users),
|
||||
set::multiple(true),
|
||||
picker
|
||||
(
|
||||
set::multiple(true),
|
||||
set::name('mailto[]'),
|
||||
set::items($users),
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user