Merge branch 'sgm_unittest' into 'master'
Sgm unittest See merge request easycorp/zentaopms!2310
This commit is contained in:
@@ -427,4 +427,221 @@ class userTest
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test authorize user.
|
||||
*
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function authorizeTest($account)
|
||||
{
|
||||
$user = $this->objectModel->authorize($account);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test login user.
|
||||
*
|
||||
* @param object $user
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function loginTest($user)
|
||||
{
|
||||
$user = $this->objectModel->login($user);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get groups by user.
|
||||
*
|
||||
* @param string $account
|
||||
* @param string $password
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getGroupsTest($account)
|
||||
{
|
||||
$groups = $this->objectModel->getGroups($account);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $groups;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get groups by visions.
|
||||
*
|
||||
* @param string $visions
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getGroupsByVisionsTest($visions)
|
||||
{
|
||||
$groups = $this->objectModel->getGroupsByVisions($visions);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $groups;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get my objects.
|
||||
*
|
||||
* @param string $account
|
||||
* @param string $type
|
||||
* @param string $status
|
||||
* @param string $orderBy
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getObjectsTest($account, $type, $status, $orderBy)
|
||||
{
|
||||
$myObjects = $this->objectModel->getObjects($account, $type, $status, $orderBy);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $myObjects;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get contact list.
|
||||
*
|
||||
* @param string $account
|
||||
* @param string $params
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getContactListsTest($account = '', $params = '')
|
||||
{
|
||||
$contacts = $this->objectModel->getContactLists($account, $params);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $contacts;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list by account method.
|
||||
*
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getListByAccountTest($account)
|
||||
{
|
||||
return $this->objectModel->getListByAccount($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get parent stage authed users.
|
||||
*
|
||||
* @param int $stageID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getParentStageAuthedUsersTest($stageID)
|
||||
{
|
||||
return $this->objectModel->getParentStageAuthedUsers($stageID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get contact list by id.
|
||||
*
|
||||
* @param int $listID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getContactListByIDTest($listID)
|
||||
{
|
||||
return $this->objectModel->getContactListByID($listID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get contact user pairs.
|
||||
*
|
||||
* @param array $accountList
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getContactUserPairsTest($accountList)
|
||||
{
|
||||
return $this->objectModel->getContactListByID($listID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create contact list.
|
||||
*
|
||||
* @param string $listName
|
||||
* @param array $userList
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function createContactListTest($listName = '', $userList = array())
|
||||
{
|
||||
$listID = $this->objectModel->createContactList($listName, $userList);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $listID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update contact list.
|
||||
*
|
||||
* @param int $listID
|
||||
* @param string $listName
|
||||
* @param array $userList
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateContactListTest($listID = 0, $listName = '', $userList = array())
|
||||
{
|
||||
$this->objectModel->updateContactList($listID, $listName, $userList);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->objectModel->getContactListByID($listID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=userModel->authorizeTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$user = new userTest();
|
||||
$rights = $user->authorizeTest('test2');
|
||||
|
||||
r($rights['rights']) && p('action:comment') && e('1'); //获取用户的权限,返回权限列表
|
||||
r($rights['rights']) && p('testtask:activate') && e('1'); //获取用户的权限,返回权限列表
|
||||
r($user->authorizeTest('sadf!!@#a')) && p('projects') && e(''); //获取不存在的用户的权限,返回空
|
||||
r($user->authorizeTest('')) && p('') && e('0'); //获取空用户名的权限,返回空
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getContactListByIDTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$user = new userTest();
|
||||
|
||||
r($user->getContactListByIDTest(1)) && p() && e('0'); //
|
||||
r($user->getContactListByIDTest(2)) && p() && e('0'); //
|
||||
r($user->getContactListByIDTest(1000)) && p() && e('0'); //
|
||||
r($user->getContactListByIDTest(false)) && p() && e('0'); //
|
||||
r($user->getContactListByIDTest(null)) && p() && e('0'); //
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getContactListsTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
$adminContactList1 = $user->getContactListsTest('admin', 'withempty|withnote');
|
||||
$adminContactList2 = $user->getContactListsTest('admin', '');
|
||||
$test2ContactList = $user->getContactListsTest('test2');
|
||||
$emptyContactList = $user->getContactListsTest('', '');
|
||||
|
||||
r($adminContactList) && p() && e('0'); // 获取admin的联系人列表
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=userModel->getContactUserPairsTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
$accountList = array('admin', 'test2');
|
||||
|
||||
r($user->getContactUserPairsTest($accountList)) && p('') && e(''); //
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getGroupsTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
|
||||
r($user->getGroupsTest('admin')) && p() && e('0'); // 获取admin所在的分组,为空
|
||||
r(count($user->getGroupsTest('test2'))) && p() && e('1'); // 通过test2所在的分组数量,1个
|
||||
r($user->getGroupsTest('')) && p() && e('0'); // 传空用户名,返回空
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getGroupsByVisionsTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
|
||||
r(count($user->getGroupsByVisionsTest(array('rnd')))) && p() && e('14'); // 获取系统中所有研发界面分组的数量
|
||||
r(count($user->getGroupsByVisionsTest(array('lite')))) && p() && e('3'); // 获取系统中所有迅捷界面分组的数量
|
||||
r($user->getGroupsByVisionsTest(array())) && p() && e('0'); // 传空Visions,返回空数组
|
||||
r(count($user->getGroupsByVisionsTest(array('rnd','lite')))) && p() && e('17'); // 获取系统中所有用户分组的数量
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getListByAccount();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
$adminContactList = $user->getListByAccountTest('admin');
|
||||
$test2ContactList = $user->getListByAccountTest('test2');
|
||||
$emptyContactList = $user->getListByAccountTest('');
|
||||
|
||||
r($adminContactList) && p() && e('0'); // 获取admin的联系人列表
|
||||
r($test2ContactList) && p() && e('0'); // 获取admin的联系人列表
|
||||
r($emptyContactList) && p() && e('0'); // 获取admin的联系人列表
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getObjectsTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
$adminProjects = $user->getObjectsTest('admin', 'project', 'all', 'id_desc');
|
||||
$adminDoneProjects = $user->getObjectsTest('admin', 'project', 'done', 'id_desc');
|
||||
$adminExecutions = $user->getObjectsTest('admin', 'execution', 'all', 'id_desc');
|
||||
$test2Projects = $user->getObjectsTest('test2', 'project', 'all', 'id_desc');
|
||||
$emptyUser = $user->getObjectsTest('', 'execution', 'all', 'id_desc');
|
||||
|
||||
r($adminProjects) && p('11:name') && e('项目1'); //获取admin的所属项目列表,取ID为11的项目名字
|
||||
r($adminProjects) && p('11:type') && e('project'); //获取admin的所属项目列表,取ID为11的项目类型
|
||||
r($adminExecutions) && p('120:name') && e('迭代20'); //获取admin的所属执行列表,取ID为120的项目名字
|
||||
r($adminDoneProjects) && p('') && e('0'); //获取admin的已完成的所属项目列表,返回空
|
||||
r($test2Projects) && p('') && e('0'); //获取test2用户的所属项目列表,返回空
|
||||
r($emptyUser) && p('') && e('0'); //传入一个空用户名字段,返回空
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 userModel::getParentStageAuthedUsersTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$user = new userTest();
|
||||
|
||||
r($user->getParentStageAuthedUsersTest(0)) && p() && e('0'); //传入ID为0的情况获取有权限的用户
|
||||
r($user->getParentStageAuthedUsersTest(131)) && p('wwccss') && e('wwccss'); //传入一个阶段ID获取有权限的用户
|
||||
r($user->getParentStageAuthedUsersTest(1)) && p() && e('0'); //传入一个项目集ID获取有权限的用户
|
||||
r($user->getParentStageAuthedUsersTest(161)) && p('wwccss') && e('wwccss'); //传入一个看板类型的项目ID获取有权限的用户
|
||||
@@ -13,6 +13,7 @@ pid=1
|
||||
*/
|
||||
|
||||
$user = new userTest();
|
||||
$user->identifyTest('admin', '78302615c8b79cac8df6d2607f8a83ee');
|
||||
|
||||
system("./ztest init");
|
||||
r($user->identifyTest('admin', '78302615c8b79cac8df6d2607f8a83ee')) && p('realname') && e('admin'); //用户名密码皆正确,返回验证登录的用户
|
||||
r($user->identifyTest('asdjaf12', '78302615c8b79cac8df6d2607f8a83ee')) && p() && e('0'); //验证一个不存在的用户,返回空
|
||||
r($user->identifyTest('', '')) && p() && e('0'); //验证一个不传用户名和密码的用户,返回空
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/user.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=userModel->loginTest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$userClass = new userTest();
|
||||
|
||||
$admin = new stdclass();
|
||||
$admin->id = 1;
|
||||
$admin->account = 'admin';
|
||||
$admin = $userClass->loginTest($admin);
|
||||
|
||||
$emptyAccount = new stdclass();
|
||||
$emptyAccount->id = 0;
|
||||
$emptyAccount->account = '';
|
||||
$emptyAccount = $userClass->loginTest($emptyAccount);
|
||||
|
||||
r($admin) && p('admin') && e('1'); //使用admin登录,返回此用户为超级管理员
|
||||
r(count($admin->rights)) && p() && e('3'); //使用Admin登录,返回权限列表的数量
|
||||
r(count($emptyAccount->group)) && p() && e('0'); //使用空账号登录,返回权限列表数量为0
|
||||
Reference in New Issue
Block a user