* Add auto test.

This commit is contained in:
孙广明
2022-03-14 15:40:17 +08:00
parent 88c870f3e1
commit 66db8b0249
3 changed files with 28 additions and 6 deletions
+22
View File
@@ -179,4 +179,26 @@ class userTest
return $objects;
}
}
/**
* Test get user by id.
*
* @param int|string $userID
* @param string $field
* @access public
* @return void
*/
public function getByIdTest($userID, $field = 'account')
{
$objects = $this->objectModel->getById($userID, $field);
if(dao::isError())
{
$error = dao::getError();
return $error[0];
}
else
{
return $objects;
}
}
}
+1 -1
View File
@@ -22,4 +22,4 @@ r($user->getByID('admin', 'account')) && p('account') && e('admin'); // 使
r($user->getByID('admin')) && p('account') && e('admin'); // 通过默认字段获取存在的用户
r($user->getByID(1)) && p('account') && e(''); // 通过默认字段获取不存在的用户
r($user->getByID(100000, 'id')) && p('account') && e(''); // 通过id字段获取不存在的用户
r($user->getByID('error', 'account')) && p('account') && e(''); // 通过默认字段获取不存在的用户
r($user->getByID('error', 'account')) && p('account') && e(''); // 通过默认字段获取不存在的用户
+5 -5
View File
@@ -22,10 +22,10 @@ pid=1
*/
$accounts = array('!asd12d', '中文用户名', 'user10', 'dev33', 'cccfff');
$accounts = array('!asd12d', '中文用户名', 'user10', 'dev33', 'cccfff', 'outside1');
$user = new userTest();
r($user->getUserRolesTest($accounts, true)) && p('dev33') && e('dev'); //获取用户名和职位Key的键值对
r($user->getUserRolesTest($accounts, false)) && p('dev33') && e('研发'); //获取用户名和职位Value的键值对
r(count($user->getUserRolesTest($accounts, true))) && p() && e(2); //从指定accounts中获取到的键值对数量
r(count($user->getUserRolesTest($accounts, false))) && p() && e(2); //从指定accounts中获取到的键值对数量
r($user->getUserDisplayInfosTest($accounts)) && p('dev33:realname') && e('项目经理33'); //查找获取到的用户名为dev33的真实姓名
r($user->getUserDisplayInfosTest($accounts)) && p('user10:avatar') && e('/home/z/tmp/10.png'); //查找获取到的用户名为user10的头像
r($user->getUserDisplayInfosTest($accounts, 0, 'outside')) && p('outside1:avatar') && e('/home/z/tmp/18.png'); //查找获取到的用户名为outside1的外部用户的头像信息
r($user->getUserDisplayInfosTest($accounts)) && p('cccfff:realname') && e('Error: Cannot get index cccfff.'); //查找获取到的用户名为cccfff的真实姓名