* Unit test of the read method of action module.

This commit is contained in:
wangxuepeng
2023-09-14 07:50:50 +00:00
parent 71cf9bff29
commit 854504f10d
3 changed files with 84 additions and 41 deletions
+4 -41
View File
@@ -89,14 +89,15 @@ class actionModel extends model
}
/**
* 访问任务或者bug时,更新action的read字段。
* Update read field of action when view a task/bug.
*
* @param string $objectType
* @param int $objectID
* @access public
* @return void
* @return bool
*/
public function read($objectType, $objectID)
public function read(string $objectType, int $objectID): bool
{
$this->dao->update(TABLE_ACTION)
->set('`read`')->eq(1)
@@ -104,46 +105,8 @@ class actionModel extends model
->andWhere('objectID')->eq($objectID)
->andWhere('`read`')->eq(0)
->exec();
}
/**
* Get the unread actions.
*
* @param int $actionID
* @access public
* @return string
*/
public function getUnreadActions($actionID = 0)
{
if(!is_numeric($actionID)) $actionID = 0;
$actions = array();
$objectList = array('task' => TABLE_TASK, 'bug' => TABLE_BUG);
foreach($objectList as $object => $table)
{
$idList = $this->dao->select('id')->from($table)->where('assignedTo')->eq($this->app->user->account)->fetchPairs('id');
$tmpActions = $this->dao->select('*')->from(TABLE_ACTION)
->where('objectType')->eq($object)
->andWhere('objectID')->in($idList)
->andWhere('`read`')->eq(0)
->andWhere('id')->gt($actionID)
->fetchAll('id');
if(empty($tmpActions)) continue;
$tmpActions = $this->transformActions($tmpActions);
foreach($tmpActions as $action)
{
$actions[$action->objectType][] = array(
'actionID' => $action->id,
'objectType' => $action->objectType,
'objectID' => $action->objectID,
'action' => $action->actor . ' ' . $action->actionLabel . ' ' . $action->objectType . " #$action->objectID" . $action->objectName
);
}
}
return json_encode($actions);
return !dao::isError();
}
/**
+2
View File
@@ -4,6 +4,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/action.class.php';
su('admin');
zdTable('action')->config('action')->gen(5);
/**
title=测试 actionModel->read();
@@ -0,0 +1,78 @@
title: table zt_action
desc: "系统日志"
author: automated export
version: "1.0"
fields:
- field: objectType
note: "对象类型"
range: product,story,productplan,release,project,task,build,bug,testcase,case,testtask,user,doc,doclib,todo,branch,module,testsuite,caselib,testreport,entry,webhook,review
prefix: ""
postfix: ""
loop: 0
format: ""
- field: objectID
note: "对象ID"
range: "1-100000"
prefix: ""
postfix: ""
loop: 0
format: ""
- field: product
note: "产品"
range: "1-100000"
prefix: ","
postfix: ","
loop: 0
format: ""
- field: project
note: "项目"
range: "1-100000"
prefix: ""
postfix: ""
loop: 0
format: ""
- field: actor
note: "操作者"
fields:
- field: actor1
range: admin,dev,test
- field: actor2
range: "[],17-18"
prefix: ""
postfix: ""
loop: 0
format: ""
- field: action
note: "动作"
range: common,extra,opened,created,changed,edited,assigned,closed,deleted,deletedfile,editfile,erased,undeleted,hidden,commented,activated,blocked,moved,confirmed,caseconfirmed,bugconfirmed,frombug,started,restarted,delayed,suspended,recordestimate,editestimate,deleteestimate,canceled,svncommited,gitcommited,finished,paused,verified,diff1,diff2,diff3,linked2bug
postfix: ""
loop: 0
format: ""
- field: date
note: "日期"
range: "(-1M)-(w):1D"
type: timestamp
prefix: ""
postfix: ""
loop: 0
format: "YYYY-MM-DD hh:mm:ss"
- field: comment
note: "备注"
range: 1-100000
prefix: "这是一个系统日志测试备注"
postfix: ""
loop: 0
format: ""
- field: extra
note: "附加参数"
range: 1{4},11,1{3}, 2 ,1{18},33,1{22},101,1{22},131,1{22},161,1{3}
prefix: ""
postfix: ""
loop: 0
- field: read
note: ""
range: "0"
prefix: ""
postfix: ""
loop: 0
format: ""