From 854504f10d07dbc0a9383678860cd9d30b779758 Mon Sep 17 00:00:00 2001 From: wangxuepeng Date: Thu, 14 Sep 2023 07:50:46 +0000 Subject: [PATCH] * Unit test of the read method of action module. --- module/action/model.php | 45 +---------- module/action/test/model/read.php | 2 + .../action/test/model/yaml/read/action.yaml | 78 +++++++++++++++++++ 3 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 module/action/test/model/yaml/read/action.yaml diff --git a/module/action/model.php b/module/action/model.php index 2a58a2424a..1f1ae54b8b 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -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(); } /** diff --git a/module/action/test/model/read.php b/module/action/test/model/read.php index b9a010cd95..e78c9552da 100755 --- a/module/action/test/model/read.php +++ b/module/action/test/model/read.php @@ -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(); diff --git a/module/action/test/model/yaml/read/action.yaml b/module/action/test/model/yaml/read/action.yaml new file mode 100644 index 0000000000..852db3f8dc --- /dev/null +++ b/module/action/test/model/yaml/read/action.yaml @@ -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: ""