diff --git a/module/task/model.php b/module/task/model.php index e931663615..3a1b543102 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -154,7 +154,7 @@ class taskModel extends model $this->loadModel('action'); /* Judge whether the current task is a parent. */ - $parentID = !empty($tasks->parent[1]) ? $tasks->parent[1] : 0; + $parentID = !empty($tasks[1]->parent) ? $tasks[1]->parent : 0; $oldParentTask = $this->dao->findById((int)$parentID)->from(TABLE_TASK)->fetch(); $taskIdList = array(); @@ -178,7 +178,7 @@ class taskModel extends model $this->action->create('task', $taskID, 'Opened', ''); if(!dao::isError()) $this->score->create('task', 'create', $taskID); - /* 将taskID和actionID存入数组中。 */ + /* 将taskID存入数组中。 */ $taskIdList[$taskID] = $taskID; } if(!dao::isError()) $this->score->create('ajax', 'batchCreate'); @@ -3860,7 +3860,7 @@ class taskModel extends model if($oldParentTask->parent == 0 and $oldParentTask->consumed > 0) { $taskID = $this->taskTao->splitConsumedTask($oldParentTask); - if(!$taskID) return false; + if(!$taskID) return false; $this->updateParentStatus($taskID); } diff --git a/module/task/tao.php b/module/task/tao.php index c7e8d460e7..1708553e3b 100644 --- a/module/task/tao.php +++ b/module/task/tao.php @@ -533,7 +533,7 @@ class taskTao extends taskModel } /** - * 批量创建前检查必填项 + * 批量创建前检查必填项。 * Check required fields before batch create tasks. * * @param object $execution diff --git a/module/task/test/model/batchcreate.php b/module/task/test/model/batchcreate.php index 345b0b263a..4994419e75 100755 --- a/module/task/test/model/batchcreate.php +++ b/module/task/test/model/batchcreate.php @@ -4,27 +4,171 @@ include dirname(__FILE__, 5) . "/test/lib/init.php"; include dirname(__FILE__, 2) . '/task.class.php'; su('admin'); +zdTable('project')->config('project')->gen('10'); + +$story = zdTable('story'); +$story->id->range('1'); +$story->product->range('1'); +$story->title->range('需求1'); +$story->type->range('story'); +$story->version->range('1'); +$story->status->range('active'); +$story->stage->range('projected'); +$story->reviewedDate->range('(-1M)-(+1w):60m')->type('timestamp')->format('YY/MM/DD'); +$story->lastEditedDate->range('(-1M)-(+1w):60m')->type('timestamp')->format('YY/MM/DD'); +$story->gen('1'); + +$storyspec = zdTable('storyspec'); +$storyspec->story->range('1'); +$storyspec->version->range('1'); +$storyspec->title->range('需求1'); +$storyspec->spec->range('storyspec1'); +$storyspec->gen('1'); + +$task = zdTable('task'); +$task->id->range('1'); +$task->name->range('任务1'); +$task->execution->range('2'); +$task->type->range('devel'); +$task->status->range('wait'); +$task->parent->range("`-1`"); +$task->gen('1'); + +$taskspec = zdTable('taskspec'); +$taskspec->task->range('1'); +$taskspec->version->range('1'); +$taskspec->name->range('任务一'); +$taskspec->gen('1'); + /** title=测试taskModel->batchCreate(); cid=1 pid=1 -测试正常的创建开发任务 >> 批量任务三 -测试正常的创建开发任务 >> 『任务类型』不能为空。 */ -$executionID = '101'; +$executionIdList = array(2); -$name = array('批量任务一','批量任务二','批量任务三'); -$type = array('devel','test','design'); -$normal_create = array('name' => $name, 'type' => $type); +$laneIdList = array(1, 2, 3); +$columnIdList = array(1, 2, 3); -$name = array('异常一','异常二','异常三'); -$Exception_create = array('name' => $name); +$parent = array(0, 0, 0, 0, 1); +$module = array(1, 2, 3, 4, 5); +$story = array(1, 0); +$storyEstimate = array(1, 2, 1, 2, 1); +$storyDesc = array('storyDesc1', 'storyDesc2', 'storyDesc3', '', ''); +$storyPri = array(3, 3, 1, 2, 4); +$name = array('task1', 'task2', 'task3', 'task4', ''); +$color = array('', 'red', 'green', '', 'gray'); +$type = array('devel', 'request', 'design', 'test', 'study', 'discuss', 'ui', 'affair', 'misc'); +$assignedTo = array('admin', 'admin', 'dev1', 'dev2', 'admin'); +$estimate = array('1', '2', '3', '1', '1'); +$estStarted = array('2022-07-01', '2023-05-08', '', '2023-09-09', ''); +$deadline = array('2023-02-01', '2022-06-02', '', '', ''); +$desc = array('', 'taskDesc', 'taskAAA', '', ''); +$pri = array('1', '2', '3', '3', '1'); + +$withoutNameTask = array(); +$withoutNameTask[1] = new stdclass(); +$withoutNameTask[1]->execution = $executionIdList[0]; +$withoutNameTask[1]->parent = $parent[0]; +$withoutNameTask[1]->module = $module[0]; +$withoutNameTask[1]->name = $name[4]; +$withoutNameTask[1]->deadline = $deadline[0]; +$withoutNameTask[1]->estimate = $estimate[0]; +$withoutNameTask[1]->estStarted = $estStarted[0]; + +$normalTaskList = array(); +$normalTaskList[1] = new stdclass(); +$normalTaskList[1]->execution = $executionIdList[0]; +$normalTaskList[1]->parent = $parent[0]; +$normalTaskList[1]->module = $module[0]; +$normalTaskList[1]->story = $story[0]; +$normalTaskList[1]->name = $name[0]; +$normalTaskList[1]->version = 1; +$normalTaskList[1]->type = $type[0]; +$normalTaskList[1]->deadline = $deadline[0]; +$normalTaskList[1]->estimate = $estimate[0]; +$normalTaskList[1]->estStarted = $estStarted[0]; +$normalTaskList[1]->mailto = ''; + +$normalTaskList[2] = new stdclass(); +$normalTaskList[2]->execution = $executionIdList[0]; +$normalTaskList[2]->parent = $parent[1]; +$normalTaskList[2]->module = $module[1]; +$normalTaskList[2]->story = $story[1]; +$normalTaskList[2]->name = $name[1]; +$normalTaskList[2]->color = $color[1]; +$normalTaskList[2]->type = $type[1]; +$normalTaskList[2]->version = 1; +$normalTaskList[2]->assignedTo = $assignedTo[1]; +$normalTaskList[2]->estimate = $estimate[1]; +$normalTaskList[2]->estStarted = $estStarted[1]; +$normalTaskList[2]->deadline = $deadline[2]; +$normalTaskList[2]->desc = $desc[1]; +$normalTaskList[2]->pri = $pri[1]; +$normalTaskList[2]->mailto = ''; + +$hasParentTask = array(); +$hasParentTask[1] = new stdclass(); +$hasParentTask[1]->execution = $executionIdList[0]; +$hasParentTask[1]->parent = $parent[4]; +$hasParentTask[1]->module = $module[1]; +$hasParentTask[1]->story = $story[1]; +$hasParentTask[1]->name = $name[1]; +$hasParentTask[1]->color = $color[1]; +$hasParentTask[1]->type = $type[1]; +$hasParentTask[1]->version = 1; +$hasParentTask[1]->assignedTo = $assignedTo[1]; +$hasParentTask[1]->estimate = $estimate[1]; +$hasParentTask[1]->estStarted = $estStarted[1]; +$hasParentTask[1]->deadline = $deadline[2]; +$hasParentTask[1]->desc = $desc[1]; +$hasParentTask[1]->pri = $pri[1]; +$hasParentTask[1]->mailto = ''; + +$hasStoryTask = array(); +$hasStoryTask[1] = new stdclass(); +$hasStoryTask[1]->execution = $executionIdList[0]; +$hasStoryTask[1]->parent = $parent[0]; +$hasStoryTask[1]->module = $module[1]; +$hasStoryTask[1]->story = $story[0]; +$hasStoryTask[1]->name = $name[1]; +$hasStoryTask[1]->color = $color[1]; +$hasStoryTask[1]->type = $type[1]; +$hasStoryTask[1]->version = 1; +$hasStoryTask[1]->assignedTo = $assignedTo[1]; +$hasStoryTask[1]->estimate = $estimate[1]; +$hasStoryTask[1]->estStarted = $estStarted[1]; +$hasStoryTask[1]->deadline = $deadline[2]; +$hasStoryTask[1]->desc = $desc[1]; +$hasStoryTask[1]->pri = $pri[1]; +$hasStoryTask[1]->mailto = ''; + +$verifyScoreTask = array(); +$verifyScoreTask[1] = new stdclass(); +$verifyScoreTask[1]->execution = $executionIdList[0]; +$verifyScoreTask[1]->parent = $parent[4]; +$verifyScoreTask[1]->module = $module[1]; +$verifyScoreTask[1]->story = $story[1]; +$verifyScoreTask[1]->name = $name[1]; +$verifyScoreTask[1]->color = $color[1]; +$verifyScoreTask[1]->type = $type[1]; +$verifyScoreTask[1]->version = 1; +$verifyScoreTask[1]->assignedTo = $assignedTo[1]; +$verifyScoreTask[1]->estimate = $estimate[1]; +$verifyScoreTask[1]->estStarted = $estStarted[1]; +$verifyScoreTask[1]->deadline = $deadline[2]; +$verifyScoreTask[1]->desc = $desc[1]; +$verifyScoreTask[1]->pri = $pri[1]; +$verifyScoreTask[1]->mailto = ''; $task = new taskTest(); -r($task->batchCreateObject($normal_create, $executionID)) && p('name') && e('批量任务三'); // 测试正常的创建开发任务 -r($task->batchCreateObject($Exception_create, $executionID)) && p('message:0') && e('『任务类型』不能为空。'); // 测试正常的创建开发任务 +r($task->batchCreateObject($withoutNameTask, $executionIdList[0])) && p('message:0') && e('『任务名称』不能为空。'); // 测试任务名称为空的情况 +r($task->batchCreateObject($normalTaskList, $executionIdList[0])) && p('') && e('2'); // 测试正常任务批量创建成功 +r($task->batchCreateObject($hasParentTask, $executionIdList[0], $parent[4])) && p('name') && e('任务1'); // 测试拆分任务 +r($task->batchCreateObject($hasStoryTask, $executionIdList[0], 0, $story[0])) && p('title') && e('需求1'); // 测试关联需求的情况 +r($task->batchCreateObject($verifyScoreTask, $executionIdList[0], 0, 0, true)) && p('') && e('1'); // 测试是否正常创建积分记录 diff --git a/module/task/test/model/yaml/batchcreate/project.yaml b/module/task/test/model/yaml/batchcreate/project.yaml new file mode 100644 index 0000000000..3b844b8d2a --- /dev/null +++ b/module/task/test/model/yaml/batchcreate/project.yaml @@ -0,0 +1,91 @@ +title: table zt_project +desc: "项目、执行" +author: Hu Fangzhou +version: "1.0" +fields: + - field: id + range: 1-10 + - field: project + range: 1 + - field: model + range: scrum,[]{9} + - field: name + note: "名称" + fields: + - field: name1 + range: 项目,执行{9} + - field: name2 + range: 1,[1-9] + - field: type + range: project,scrum{4},stage{3},kanban{2} + - field: status + range: wait{2},doing{4},suspended,closed + - field: lifetime + range: + - field: budget + range: 900000-1:100 + - field: budgetUnit + range: CNY,USD + - field: attribute + note: "Only stage has attribute" + range: + - field: percent + range: 1-100:R + - field: milestone + note: "Is it milestone" + range: 0 + - field: output + note: "Output document" + range: + - field: auth + note: "Only project has auth" + range: "extend" + - field: parent + range: 1-10 + - field: path + fields: + - field: path1 + prefix: "," + range: 1 + - field: path2 + prefix: "," + range: 2-10 + postfix: "," + - field: grade + range: "2" + - field: code + range: 1-10000 + prefix: "project" + - field: begin + range: "(-3M)-(+M):1D" + type: timestamp + format: "YY/MM/DD" + postfix: "\t" + - field: end + range: "(+5w)-(+2M):1D" + type: timestamp + format: "YY/MM/DD" + postfix: "\t" + - field: PO + range: + - field: PM + range: + - field: QD + range: + - field: RD + range: + - field: team + range: + - field: acl + range: open,private,program + - field: order + range: 5-10000:5 + - field: openedVersion + range: + - field: openedDate + range: "(-3M)-(+M):1D" + type: timestamp + format: "YY/MM/DD" + postfix: "\t" + - field: deleted + range: 0 diff --git a/module/task/test/task.class.php b/module/task/test/task.class.php index 4ac433df7f..b2c518b043 100644 --- a/module/task/test/task.class.php +++ b/module/task/test/task.class.php @@ -87,48 +87,52 @@ class taskTest /** * Test batch create tasks. * - * @param array $param + * @param array $data * @param int $executionID + * @param int $taskID + * @param int $storyID + * @param bool $verifyScore + * @param array $output * @access public - * @return object + * @return object|int */ - public function batchCreateObject($param = array(), $executionID = '') + public function batchCreateObject($data = array(), $executionID = 0, $taskID = 0, $storyID = 0, $verifyScore = false, $output = array()) { - $modul = array('','',''); - $parent = array('0','0','0'); - $name = array('','',''); - $type = array('','',''); - $assignedTo = array('','',''); - $story =array('','',''); - $pri = array('3','3','3'); - $color = array('','',''); - $desc = array('','',''); - $estimate = array('','',''); - $createFields = array('parent' => $parent, 'module' => $modul, 'name' => $name, 'type' => $type, 'assignedTo' => $assignedTo, - 'pri' => $pri, 'story' => $story, 'color' => $color, 'desc' => $desc ,'estimate' => $estimate); - foreach($createFields as $field => $defaultValue) $_POST[$field] = $defaultValue; + global $tester; - foreach($param as $key => $value) $_POST[$key] = $value; + $_SERVER['HTTP_HOST'] = $tester->config->db->host; - $object = $this->objectModel->batchCreate($executionID); - if (in_array('批量任务三', $_POST['name'], true)) - { - $objectID = $object[2]->taskID; - } - else - { - $objectID = $object[0]; - } - unset($_POST); + $execution = $tester->dao->findById($executionID)->from(TABLE_EXECUTION)->fetch(); + + $lastScore = $tester->dao->select('after')->from(TABLE_SCORE)->orderBy('id_desc')->limit(1)->fetch('after'); + + $objectIdList = $this->objectModel->batchCreate($execution, $data, $output); + + $childTask = array(); + if(!dao::isError()) $childTask = $this->objectModel->getById(current($objectIdList)); if(dao::isError()) { return dao::getError(); } + elseif(!empty($taskID)) + { + $parentTask = $this->objectModel->getById($childTask->parent); + return $parentTask; + } + elseif(!empty($storyID)) + { + $releatedStory = $tester->loadModel('story')->getById($childTask->story); + return $releatedStory; + } + elseif($verifyScore) + { + $score = $tester->dao->select('after')->from(TABLE_SCORE)->orderBy('id_desc')->limit(1)->fetch('after'); + return $score == $lastScore + 1; + } else { - $object = $this->objectModel->getByID($objectID); - return $object; + return count($objectIdList); } } @@ -1729,7 +1733,7 @@ class taskTest * @param int $columnID * @param string $vision * @access public - * @return void + * @return string */ public function updateKanban4BatchCreateTest($taskID, $executionID, $laneID, $columnID, $vision = 'rnd') {