+ Add unit test for pivotModel::getWorkload.
This commit is contained in:
+23
-6
@@ -478,9 +478,7 @@ class pivotModel extends model
|
||||
$execution->totalTasks = 0;
|
||||
$execution->totalHours = 0;
|
||||
$execution->workload = '0%';
|
||||
$execution->executionName = $this->lang->null;
|
||||
|
||||
if($execution->multiple) $execution->executionName = $canViewExecution ? html::a(helper::createLink('execution', 'view', "executionID={$execution->executionID}"), $execution->executionName) : $execution->executionName;
|
||||
$this->setExecutionName($execution, $canViewExecution);
|
||||
|
||||
if($userFirstRow) $execution->userRowspan = $totalExecutions;
|
||||
if($projectFirstRow) $execution->projectRowspan = count($executions);
|
||||
@@ -544,9 +542,7 @@ class pivotModel extends model
|
||||
$execution->totalTasks = $totalTasks;
|
||||
$execution->totalHours = $totalHours;
|
||||
$execution->workload = $userWorkload;
|
||||
$execution->executionName = $this->lang->null;
|
||||
|
||||
if($execution->multiple) $execution->executionName = $canViewExecution ? html::a(helper::createLink('execution', 'view', "executionID={$execution->executionID}"), $execution->executionName) : $execution->executionName;
|
||||
$this->setExecutionName($execution, $canViewExecution);
|
||||
|
||||
if($userFirstRow) $execution->userRowspan = $totalExecutions;
|
||||
if($projectFirstRow) $execution->projectRowspan = count($executions);
|
||||
@@ -561,6 +557,27 @@ class pivotModel extends model
|
||||
return $workload;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置执行名称。
|
||||
* Set execution name.
|
||||
*
|
||||
* @param object $execution
|
||||
* @param bool $canViewExecution
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setExecutionName(object &$execution, bool $canViewExecution): void
|
||||
{
|
||||
if($execution->multiple)
|
||||
{
|
||||
$execution->executionName = $canViewExecution ? html::a(helper::createLink('execution', 'view', "executionID={$execution->executionID}"), $execution->executionName) : $execution->executionName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$execution->executionName = $this->lang->null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的工作负载。
|
||||
* Get user's workload.
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/pivot.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
zdTable('user')->gen(20);
|
||||
zdTable('dept')->gen(4);
|
||||
zdTable('task')->config('task')->gen(10);
|
||||
zdTable('project')->gen(10);
|
||||
zdTable('project')->config('execution_workload')->gen(10, false, false);
|
||||
zdTable('team')->config('team')->gen(5);
|
||||
|
||||
/**
|
||||
title=测试 pivotModel->getWorkload();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
测试部门id为0,执行状态未分配,工时为7的透视表数据是否正常生成,此返回值包含四条数据。 >> user1,空,项目集2;user4,空,项目集5
|
||||
测试部门id为1,执行状态未分配,工时为7的透视表数据是否正常生成, 此返回值只包含一条数据。 >> user1,空,项目集2
|
||||
测试部门id为10000,执行状态未分配,工时为7的透视表数据是否正常生成, 部门id存在但是部门不存在的情况下不会返回数据。 >> 0
|
||||
测试部门id为0,执行状态已分配,工时为7的透视表数据是否正常生成,此返回值包含四条数据。 >> 2,0,1,2,28.57;10,1,1,5,71.43
|
||||
|
||||
*/
|
||||
|
||||
$pivot = new pivotTest();
|
||||
|
||||
global $tester;
|
||||
$users = $tester->loadModel('user')->getPairs('noletter|noclosed');
|
||||
|
||||
$deptList = array(0, 1, 3);
|
||||
$assignList = array('noassign', 'assign');
|
||||
$allHourList = array(7, 7.5, 8);
|
||||
$usersList = array($users, array());
|
||||
|
||||
r($pivot->getWorkload($deptList[0], $assignList[0], $usersList[0], $allHourList[0])) && p('0:user,executionName,projectName;3:user,executionName,projectName') && e('user1,空,项目集2;user4,空,项目集5'); //测试部门id为0,执行状态未分配,工时为7的透视表数据是否正常生成,此返回值包含四条数据。
|
||||
r($pivot->getWorkload($deptList[1], $assignList[0], $usersList[0], $allHourList[0])) && p('0:user,executionName,projectName') && e('user1,空,项目集2'); //测试部门id为1,执行状态未分配,工时为7的透视表数据是否正常生成, 此返回值只包含一条数据。
|
||||
r($pivot->getWorkload($deptList[2], $assignList[0], $usersList[0], $allHourList[0])) && p('') && e('0'); //测试部门id为10000,执行状态未分配,工时为7的透视表数据是否正常生成, 部门id存在但是部门不存在的情况下不会返回数据。
|
||||
|
||||
$result = $pivot->getWorkload($deptList[0], $assignList[1], $usersList[0], $allHourList[0]);
|
||||
foreach($result as $row)
|
||||
{
|
||||
if($row->workload) $row->workload = str_replace('%', '', $row->workload);
|
||||
$name = $row->executionName;
|
||||
$row->isExecutionNameHtml = 0;
|
||||
if(strip_tags($name) != $row->executionName) $row->isExecutionNameHtml = 1;
|
||||
}
|
||||
r($result) && p('0:id,isExecutionNameHtml,totalTasks,totalHours,workload;3:id,isExecutionNameHtml,totalTasks,totalHours,workload') && e("2,0,1,2,28.57;10,1,1,5,71.43"); //测试部门id为0,执行状态已分配,工时为7的透视表数据是否正常生成,此返回值包含四条数据。
|
||||
@@ -0,0 +1,12 @@
|
||||
title: table zt_project
|
||||
author: Wang XuePeng
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
range: 101-700
|
||||
- field: project
|
||||
range: 1-10
|
||||
- field: status
|
||||
range: waiting,doing
|
||||
- field: multiple
|
||||
range: 0{5},1{5}
|
||||
@@ -0,0 +1,18 @@
|
||||
title: table zt_task
|
||||
desc: "任务"
|
||||
author: automated export
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: assignedTo
|
||||
fields:
|
||||
- field: account1
|
||||
range: admin,user{100}
|
||||
- field: account2
|
||||
range: "[],11-100"
|
||||
note: "指派给"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: left
|
||||
range: 1-5
|
||||
@@ -0,0 +1,30 @@
|
||||
title: table zt_team
|
||||
desc: "团队"
|
||||
author: Wang XuePeng
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: root
|
||||
note: "项目/执行ID"
|
||||
range: 101-110
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: type
|
||||
note: "项目类型"
|
||||
range: execution{5}
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: account
|
||||
note: "用户账号"
|
||||
fields:
|
||||
- field: account1
|
||||
range: admin,user{100}
|
||||
- field: account2
|
||||
range: "[],1-100"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
Reference in New Issue
Block a user