* Refactor messageModel::saveNotice, and modify its unit test.
This commit is contained in:
@@ -122,16 +122,18 @@ class messageModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储提示消息。
|
||||
* Save notice.
|
||||
*
|
||||
* @param string $objectType
|
||||
* @param int $objectID
|
||||
* @param string $actionType
|
||||
* @param int $actionID
|
||||
* @param string $actor
|
||||
* @access public
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function saveNotice($objectType, $objectID, $actionType, $actionID, $actor = '')
|
||||
public function saveNotice(string $objectType, int $objectID, string $actionType, int $actionID, string $actor = ''): bool
|
||||
{
|
||||
if(empty($actor)) $actor = $this->app->user->account;
|
||||
if(empty($actor)) return false;
|
||||
@@ -142,8 +144,7 @@ class messageModel extends model
|
||||
$field = $this->config->action->objectNameFields[$objectType];
|
||||
$object = $this->dao->select('*')->from($table)->where('id')->eq($objectID)->fetch();
|
||||
$toList = $this->getToList($object, $objectType, $actionID);
|
||||
if(empty($toList)) return false;
|
||||
if($toList == $actor) return false;
|
||||
if(empty($toList) || $toList == $actor) return false;
|
||||
|
||||
$this->app->loadConfig('mail');
|
||||
$sysURL = zget($this->config->mail, 'domain', common::getSysURL());
|
||||
@@ -152,11 +153,11 @@ class messageModel extends model
|
||||
if($isonlybody) unset($_GET['onlybody']);
|
||||
|
||||
$moduleName = $objectType == 'case' ? 'testcase' : $objectType;
|
||||
$moduleName = $objectType == 'kanbancard' ? 'kanban' : $objectType;
|
||||
if($objectType == 'kanbancard') $moduleName = 'kanban';
|
||||
$space = common::checkNotCN() ? ' ' : '';
|
||||
$data = $user->realname . $space . $this->lang->action->label->$actionType . $space . $this->lang->action->objectTypes[$objectType];
|
||||
$data = $user->realname . $space . $this->lang->action->label->{$actionType} . $space . $this->lang->action->objectTypes[$objectType];
|
||||
$dataID = $objectType == 'kanbancard' ? $object->kanban : $objectID;
|
||||
$url = helper::createLink($moduleName, 'view', "id=$dataID");
|
||||
$url = helper::createLink($moduleName, 'view', "id={$dataID}");
|
||||
$data .= ' ' . html::a((strpos($url, $sysURL) === 0 ? '' : $sysURL) . $url, "[#{$objectID}::{$object->$field}]");
|
||||
|
||||
if($isonlybody) $_GET['onlybody'] = 'yes';
|
||||
@@ -171,6 +172,7 @@ class messageModel extends model
|
||||
$notify->createdDate = helper::now();
|
||||
|
||||
$this->dao->insert(TABLE_NOTIFY)->data($notify)->exec();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,23 +86,32 @@ class messageTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Save notice.
|
||||
* 测试存储提示消息。
|
||||
* Test save notice.
|
||||
*
|
||||
* @param int $objectType
|
||||
* @param int $objectID
|
||||
* @param int $actionType
|
||||
* @param int $actionID
|
||||
* @param string $actor
|
||||
* @param string $objectType
|
||||
* @param int $objectID
|
||||
* @param string $actionType
|
||||
* @param int $actionID
|
||||
* @param string $actor
|
||||
* @access public
|
||||
* @return void
|
||||
* @return object|array
|
||||
*/
|
||||
public function saveNoticeTest($objectType, $objectID, $actionType, $actionID, $actor = '')
|
||||
public function saveNoticeTest(string $objectType, int $objectID, string $actionType, int $actionID, string $actor = ''): object|array
|
||||
{
|
||||
$objects = $this->objectModel->saveNotice($objectType, $objectID, $actionType, $actionID, $actor = '');
|
||||
global $tester;
|
||||
if($actor == 'empty')
|
||||
{
|
||||
$actor = '';
|
||||
$tester->app->user->account = '';
|
||||
}
|
||||
$result = $this->objectModel->saveNotice($objectType, $objectID, $actionType, $actionID, $actor);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
|
||||
if($result) $notify = $tester->dao->select('*')->from(TABLE_NOTIFY)->orderBy('id_desc')->fetch();
|
||||
return !empty($notify) ? $notify : array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/message.class.php';
|
||||
|
||||
zdTable('story')->gen(2);
|
||||
zdTable('task')->config('task')->gen(7);
|
||||
zdTable('notify')->gen(0);
|
||||
zdTable('action')->gen(20);
|
||||
zdTable('user')->gen(2);
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
@@ -10,16 +17,27 @@ title=测试 messageModel->saveNotice();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过拿取todo表的第一条数据并且将actor赋值admin获取返回值 >> 0
|
||||
通过拿取task表的第一条数据并且将actor赋值admin获取返回值 >> 0
|
||||
通过拿取todo表的第一条数据并且不给actor赋值获取返回值 >> 0
|
||||
通过拿取todo表的第一条数据并且给actor赋值user1获取返回值 >> 0
|
||||
|
||||
*/
|
||||
|
||||
$message = new messageTest();
|
||||
$objectType = array('story', 'task', 'user');
|
||||
$objectID = array(2, 6, 0);
|
||||
$actionType = array('opened', 'edited', 'nothing');
|
||||
$actionID = array(2, 6, 0);
|
||||
$actor = array('admin', 'user1', '', 'empty');
|
||||
|
||||
r($message->saveNoticeTest('todo', '1', 'product', '1', 'admin')) && p() && e('0'); //通过拿取todo表的第一条数据并且将actor赋值admin获取返回值
|
||||
r($message->saveNoticeTest('task', '1', 'product', '1', 'admin')) && p() && e('0'); //通过拿取task表的第一条数据并且将actor赋值admin获取返回值
|
||||
r($message->saveNoticeTest('todo', '1', 'product', '1', '')) && p() && e('0'); //通过拿取todo表的第一条数据并且不给actor赋值获取返回值
|
||||
r($message->saveNoticeTest('todo', '1', 'product', '1', 'user1')) && p() && e('0'); //通过拿取todo表的第一条数据并且给actor赋值user1获取返回值
|
||||
$message = new messageTest();
|
||||
r($message->saveNoticeTest($objectType[0], $objectID[0], $actionType[0], $actionID[0], $actor[0])) && p('id,objectType,action,createdBy') && e('1,message,2,admin'); // 发送 需求 2 动态 2 用户 admin 的消息
|
||||
r($message->saveNoticeTest($objectType[1], $objectID[1], $actionType[1], $actionID[1], $actor[0])) && p('id,objectType,action,createdBy') && e('2,message,6,admin'); // 发送 任务 6 动态 6 用户 admin 的消息
|
||||
r($message->saveNoticeTest($objectType[2], $objectID[2], $actionType[2], $actionID[2], $actor[0])) && p('id,objectType,action,createdBy') && e('0,0,0,0'); // 发送 反馈 0 动态 0 用户 admin 的消息
|
||||
|
||||
r($message->saveNoticeTest($objectType[0], $objectID[0], $actionType[0], $actionID[0], $actor[1])) && p('id,objectType,action,createdBy') && e('3,message,2,user1'); // 发送 需求 2 动态 2 用户 user1 的消息
|
||||
r($message->saveNoticeTest($objectType[1], $objectID[1], $actionType[1], $actionID[1], $actor[1])) && p('id,objectType,action,createdBy') && e('4,message,6,user1'); // 发送 任务 6 动态 6 用户 user1 的消息
|
||||
r($message->saveNoticeTest($objectType[2], $objectID[2], $actionType[2], $actionID[2], $actor[1])) && p('id,objectType,action,createdBy') && e('0,0,0,0'); // 发送 反馈 0 动态 0 用户 user1 的消息
|
||||
|
||||
r($message->saveNoticeTest($objectType[0], $objectID[0], $actionType[0], $actionID[0], $actor[2])) && p('id,objectType,action,createdBy') && e('5,message,2,admin'); // 发送 需求 2 动态 2 不传 actor 的消息
|
||||
r($message->saveNoticeTest($objectType[1], $objectID[1], $actionType[1], $actionID[1], $actor[2])) && p('id,objectType,action,createdBy') && e('6,message,6,admin'); // 发送 任务 6 动态 6 不传 actor 的消息
|
||||
r($message->saveNoticeTest($objectType[2], $objectID[2], $actionType[2], $actionID[2], $actor[2])) && p('id,objectType,action,createdBy') && e('0,0,0,0'); // 发送 反馈 0 动态 0 不传 actor 的消息
|
||||
|
||||
r($message->saveNoticeTest($objectType[0], $objectID[0], $actionType[0], $actionID[0], $actor[3])) && p('id') && e('0'); // 发送 需求 2 动态 2 未登录 的消息
|
||||
r($message->saveNoticeTest($objectType[1], $objectID[1], $actionType[1], $actionID[1], $actor[3])) && p('id') && e('0'); // 发送 任务 6 动态 6 未登录 的消息
|
||||
r($message->saveNoticeTest($objectType[2], $objectID[2], $actionType[2], $actionID[2], $actor[3])) && p('id') && e('0'); // 发送 反馈 0 动态 0 未登录 的消息
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
title: table_task
|
||||
desc: "任务"
|
||||
author: Mengyi Liu
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: assignedTo
|
||||
range: user1,user2,dev1,dev2
|
||||
Reference in New Issue
Block a user