From 78f64fdb322a893b4e13fc8fff65a839da409e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B9=BF=E6=98=8E?= Date: Tue, 15 Mar 2022 13:33:38 +0800 Subject: [PATCH] * Add batch create user unit test. --- test/class/user.class.php | 74 ++++++++++++++++++++++++ test/model/user/batchcreate.php | 37 ++++++++++++ test/model/user/create.php | 60 +++++++++++++++++++ test/model/user/getavatarpairs.php | 13 +---- test/model/user/getbyid.php | 16 ++--- test/model/user/getbyquery.php | 24 ++++++++ test/model/user/getcommiters.php | 13 +---- test/model/user/getlist.php | 5 +- test/model/user/getlistbyaccounts.php | 2 +- test/model/user/getpairs.php | 2 +- test/model/user/getrealnameandemails.php | 15 ++--- test/model/user/getuserdisplayinfos.php | 15 ++--- test/model/user/getuserroles.php | 13 +---- 13 files changed, 226 insertions(+), 63 deletions(-) create mode 100644 test/model/user/batchcreate.php create mode 100644 test/model/user/create.php create mode 100644 test/model/user/getbyquery.php diff --git a/test/class/user.class.php b/test/class/user.class.php index eb3de2d874..2b6b4248b6 100644 --- a/test/class/user.class.php +++ b/test/class/user.class.php @@ -201,4 +201,78 @@ class userTest return $objects; } } + + /** + * Test get user by query. + * + * @param string $browseType + * @param string $query + * @param string $orderBy + * @access public + * @return void + */ + public function getByQueryTest($browseType = 'inside', $query = '', $orderBy = 'id') + { + $objects = $this->objectModel->getByQuery($browseType, $query, null, $orderBy); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $objects; + } + } + + /** + * Test create a user. + * + * @param array $params + * @access public + * @return void + */ + public function createUserTest($params = array()) + { + $_POST = $params; + $_POST['verifyPassword'] = 'e79f8fb9726857b212401e42e5b7e18b'; + + $userID = $this->objectModel->create(); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $this->objectModel->getByID($userID, 'id'); + } + } + + /** + * Test batch create users. + * + * @access public + * @return void + */ + public function batchCreateUserTest($params = array()) + { + $_POST = $params; + $_POST['verifyPassword'] = 'e79f8fb9726857b212401e42e5b7e18b'; + + $userIDList = $this->objectModel->batchCreate(); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + a($userIDList);die; + $query = "id in $userIDList"; + return $this->objectModel->getByQuery('', $query); + } + } } diff --git a/test/model/user/batchcreate.php b/test/model/user/batchcreate.php new file mode 100644 index 0000000000..c9e471140c --- /dev/null +++ b/test/model/user/batchcreate.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +batchCreateTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['account'] = array('newtestuser1', 'newtestuser2', 'newtestuser3'); +$normalUser['realname'] = array('新测试用户1', '新测试用户2', '新测试用户3'); +$normalUser['visions'] = array('rnd', 'rnd,lite', 'lite'); +$normalUser['role'] = array('qa', 'dev', 'pm'); +$normalUser['email'] = array('testasd@163.com', '', '11773@qq.com'); +$normalUser['password'] = array('e10adc3949ba59abbe56e057f20f883e', 'e10adc3949ba59abbe56e057f20f883e', 'e10adc3949ba59abbe56e057f20f883e'); + +a($user->batchCreateUserTest($normalUser));die; + +r($user->batchCreateUserTest($normalUser)) && p('password1:0') && e('您的密码强度小于系统设定。'); //密码较弱的情况 + +system("./ztest init"); diff --git a/test/model/user/create.php b/test/model/user/create.php new file mode 100644 index 0000000000..6457995041 --- /dev/null +++ b/test/model/user/create.php @@ -0,0 +1,60 @@ +#!/usr/bin/env php +createTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['account'] = 'newtestuser'; +$normalUser['realname'] = '新的测试用户'; +$normalUser['password1'] = 'e10adc3949ba59abbe56e057f20f883e'; +$normalUser['password2'] = 'e10adc3949ba59abbe56e057f20f883e'; +$normalUser['type'] = 'inside'; +$normalUser['passwordStrength'] = 1; +$normalUser['visions'] = 'rnd'; + +$weakPassword = $normalUser; +$weakPassword['passwordStrength'] = 0; + +$emptyVisions = $normalUser; +unset($emptyVisions['visions']); + +$emptyAccount = $normalUser; +unset($emptyAccount['account']); + +$specialAccount = $normalUser; +$specialAccount['account'] = 'sa!@#asdf'; + +$differentPassword = $normalUser; +$differentPassword['password2'] = 'asfjhjkahf9012asd123'; + +$existUser = $normalUser; +$existUser['account'] = 'admin'; + +r($user->createUserTest($weakPassword)) && p('password1:0') && e('您的密码强度小于系统设定。'); //密码较弱的情况 +r($user->createUserTest($emptyVisions)) && p('visions:0') && e('『版本类型』不能为空。'); //Visions为空的情况 +r($user->createUserTest($emptyAccount)) && p('account:0') && e('『用户名』不能为空。'); //用户名为空的情况 +r($user->createUserTest($specialAccount)) && p('account:0') && e('『用户名』只能是字母、数字或下划线的组合三位以上。'); //用户名特殊的情况 +r($user->createUserTest($differentPassword)) && p('password:0') && e('两次密码应该相同。'); //两次密码不相同的情况 +r($user->createUserTest($existUser)) && p('account:0') && e('『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。'); //插入重复的用户名,返回报错信息 +r($user->createUserTest($normalUser)) && p('id,realname') && e('1001,新的测试用户'); //正常插入用户,返回新插入的ID、真实姓名 +r($user->createUserTest($normalUser)) && p('realname') && e('新的测试用户'); //正常插入用户,返回新插入的真实姓名 +system("./ztest init"); diff --git a/test/model/user/getavatarpairs.php b/test/model/user/getavatarpairs.php index 2ba8389fa0..37c6e80893 100644 --- a/test/model/user/getavatarpairs.php +++ b/test/model/user/getavatarpairs.php @@ -10,18 +10,11 @@ title=userModel->getPairs(); cid=1 pid=1 -查找带有Closed用户的外部用户键值对 >> Closed -查找带有首字母的外部用户键值对 >> O:用户1 -查找不带首字母的外部用户键值对 >> 用户1 -按照给定的用户名查找用户键值对,返回值中不带有Closed用户 >> 1 -按照给定的用户名查找用户键值对,返回值中带有Closed用户 >> 2 -使用limit参数来限制最多获取2个用户键值对 >> 2 -使用limit参数来限制最多获取50个用户键值对 >> 50 -使用pofirst参数来将系统中的产品经理用户放到返回值前列 >> P:测试主管58 -使用pmfirst参数来将系统中的项目经理用户放到返回值前列 >> O:其他100 +所有用户头像的数量 >> 999 +查找account为"user99"的用户的头像路径 >> /home/z/user/15.png */ $user = new userTest(); r(count($user->getAvatarPairsTest())) && p() && e('999'); //所有用户头像的数量 -r($user->getAvatarPairsTest()) && p('user99') && e('/home/z/user/15.png'); //查找account为"user99"的用户的头像路径 +r($user->getAvatarPairsTest()) && p('user99') && e('/home/z/user/15.png'); //查找account为"user99"的用户的头像路径 \ No newline at end of file diff --git a/test/model/user/getbyid.php b/test/model/user/getbyid.php index ffd1c89fe6..533b877ebe 100755 --- a/test/model/user/getbyid.php +++ b/test/model/user/getbyid.php @@ -1,7 +1,7 @@ #!/usr/bin/env php > admin */ -$user = $tester->loadModel('user'); +$user = new userTest(); -r($user->getById(1, 'id')) && p('account') && e('admin'); // 通过id获取存在的用户 -r($user->getByID('admin', 'account')) && p('account') && e('admin'); // 使用account字段获取存在的用户 -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->getByIDTest(1, 'id')) && p('account') && e('admin'); // 通过id获取存在的用户 +r($user->getByIDTest('admin', 'account')) && p('account') && e('admin'); // 使用account字段获取存在的用户 +r($user->getByIDTest('admin')) && p('account') && e('admin'); // 通过默认字段获取存在的用户 +r($user->getByIDTest(1)) && p('account') && e(''); // 通过默认字段获取不存在的用户 +r($user->getByIDTest(100000, 'id')) && p('account') && e(''); // 通过id字段获取不存在的用户 +r($user->getByIDTest('error', 'account')) && p('account') && e(''); // 通过默认字段获取不存在的用户 \ No newline at end of file diff --git a/test/model/user/getbyquery.php b/test/model/user/getbyquery.php new file mode 100644 index 0000000000..c3cd097b94 --- /dev/null +++ b/test/model/user/getbyquery.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +> 303 +按ID倒序查询内部用户,获取最后一个用户的account >> admin +获取第一个外部用户的真实姓名 >> 用户1 + +*/ +$user = new userTest(); +$insideQAUsers = $user->getByQueryTest('inside', "`role` = 'qa'", 'id desc'); +$outsideUsers = $user->getByQueryTest('outside'); + +r(count($insideQAUsers)) && p() && e('303'); //对比获取到的内部用户的数量 +r($insideQAUsers) && p('302:account') && e('admin'); //按ID倒序查询内部用户,获取最后一个用户的account +r($outsideUsers) && p('0:realname') && e('用户1'); //获取第一个外部用户的真实姓名 \ No newline at end of file diff --git a/test/model/user/getcommiters.php b/test/model/user/getcommiters.php index a12a9e426c..d6466aafbc 100644 --- a/test/model/user/getcommiters.php +++ b/test/model/user/getcommiters.php @@ -10,15 +10,8 @@ title=userModel->getPairs(); cid=1 pid=1 -查找带有Closed用户的外部用户键值对 >> Closed -查找带有首字母的外部用户键值对 >> O:用户1 -查找不带首字母的外部用户键值对 >> 用户1 -按照给定的用户名查找用户键值对,返回值中不带有Closed用户 >> 1 -按照给定的用户名查找用户键值对,返回值中带有Closed用户 >> 2 -使用limit参数来限制最多获取2个用户键值对 >> 2 -使用limit参数来限制最多获取50个用户键值对 >> 50 -使用pofirst参数来将系统中的产品经理用户放到返回值前列 >> P:测试主管58 -使用pmfirst参数来将系统中的项目经理用户放到返回值前列 >> O:其他100 +获取源代码账号为qd100的用户真实姓名 >> 高层管理100 +获取系统中源代码账号不为空的用户数量 >> 1000 */ @@ -26,4 +19,4 @@ $user = new userTest(); $commiters = $user->getCommitersTest(); r($commiters) && p('qd100') && e('高层管理100'); //获取源代码账号为qd100的用户真实姓名 -r(count($commiters)) && p() && e('1000'); //获取系统中源代码账号不为空的用户数量 +r(count($commiters)) && p() && e('1000'); //获取系统中源代码账号不为空的用户数量 \ No newline at end of file diff --git a/test/model/user/getlist.php b/test/model/user/getlist.php index 1580882cdd..4cc11069ae 100644 --- a/test/model/user/getlist.php +++ b/test/model/user/getlist.php @@ -11,14 +11,15 @@ cid=1 pid=1 查找系统中第二个未删除的、内部用户真实姓名,根据account正序排 >> 开发1 -查找系统中第三个未删除的、内部用户电话号,根据account正序排 >> 18556488236 +查找系统中未删除的、根据account正序排的最后一个用户的姓名 >> 测试99 查找系统中所有未删除的、内部用户的数量 >> 999 查找系统中不存在的用户,输出错误提示 >> Error: Cannot get index 1000 */ $user = new userTest(); +a($user->getListTest());die; r($user->getListTest()) && p('1:realname') && e('开发1'); //查找系统中第二个未删除的、内部用户真实姓名,根据account正序排 -r($user->getListTest()) && p('2:phone') && e('18556488236'); //查找系统中第三个未删除的、内部用户电话号,根据account正序排 +r($user->getListTest()) && p('998:realname') && e('测试99'); //查找系统中未删除的、根据account正序排的最后一个用户的姓名 r($user->getListTest(true)) && p() && e('999'); //查找系统中所有未删除的、内部用户的数量 r($user->getListTest()) && p('1000:realname') && e('Error: Cannot get index 1000'); //查找系统中不存在的用户,输出错误提示 \ No newline at end of file diff --git a/test/model/user/getlistbyaccounts.php b/test/model/user/getlistbyaccounts.php index 48c8f37d3f..3e25f2c71d 100644 --- a/test/model/user/getlistbyaccounts.php +++ b/test/model/user/getlistbyaccounts.php @@ -21,4 +21,4 @@ $count = array(0 => false, 1 => true); $user = new userTest(); r($user->getListByAccountsTest($accounts, $count[0])) && p('1:realname,role') && e('admin,qa'); //按照给定的用户名列表查询用户信息,获取用户ID为1的用户真实姓名和角色 r($user->getListByAccountsTest($accounts, $count[1])) && p() && e('3'); //按照给定的用户名列表查询用户信息,获取查询出的用户列表数量 -r($user->getListByAccountsTest($accounts, $count[0])) && p('0:realname') && e('Error: Cannot get index 0.'); //按照给定的用户名列表查询用户信息,获取用户ID为0的用户信息 +r($user->getListByAccountsTest($accounts, $count[0])) && p('0:realname') && e('Error: Cannot get index 0.'); //按照给定的用户名列表查询用户信息,获取用户ID为0的用户信息 \ No newline at end of file diff --git a/test/model/user/getpairs.php b/test/model/user/getpairs.php index b111b224c6..2d6e4fd5f4 100644 --- a/test/model/user/getpairs.php +++ b/test/model/user/getpairs.php @@ -44,4 +44,4 @@ r(count($usersInAccountsWithclosed)) && p() && e('2'); // r(count($limit2Users)) && p() && e('2'); //使用limit参数来限制最多获取2个用户键值对 r(count($limit50Users)) && p() && e('50'); //使用limit参数来限制最多获取50个用户键值对 r($firstPO) && p('pd58') && e('P:测试主管58'); //使用pofirst参数来将系统中的产品经理用户放到返回值前列 -r($firstPM) && p('outside100') && e('O:其他100'); //使用pmfirst参数来将系统中的项目经理用户放到返回值前列 +r($firstPM) && p('outside100') && e('O:其他100'); //使用pmfirst参数来将系统中的项目经理用户放到返回值前列 \ No newline at end of file diff --git a/test/model/user/getrealnameandemails.php b/test/model/user/getrealnameandemails.php index 966d8bc0ef..5dda0f0dc9 100644 --- a/test/model/user/getrealnameandemails.php +++ b/test/model/user/getrealnameandemails.php @@ -10,15 +10,8 @@ title=userModel->getPairs(); cid=1 pid=1 -查找带有Closed用户的外部用户键值对 >> Closed -查找带有首字母的外部用户键值对 >> O:用户1 -查找不带首字母的外部用户键值对 >> 用户1 -按照给定的用户名查找用户键值对,返回值中不带有Closed用户 >> 1 -按照给定的用户名查找用户键值对,返回值中带有Closed用户 >> 2 -使用limit参数来限制最多获取2个用户键值对 >> 2 -使用limit参数来限制最多获取50个用户键值对 >> 50 -使用pofirst参数来将系统中的产品经理用户放到返回值前列 >> P:测试主管58 -使用pmfirst参数来将系统中的项目经理用户放到返回值前列 >> O:其他100 +获取admin的邮箱 >> 833482@qq.com +从accounts中获取到的用户邮箱数量 >> 2 */ @@ -26,5 +19,5 @@ $accounts = array('tesrasd1asd#@!#$', 'ASD123中文', 'user10', 'ccsdqq@!', 'adm $user = new userTest(); $emails = $user->getRealNameAndEmailsTest($accounts); -r($emails['admin']) && p('email') && e('631479@qq.com'); //获取admin的邮箱 -r(count($emails)) && p() && e('2'); //从accounts中获取到的用户邮箱数量 +r($emails['admin']) && p('email') && e('833482@qq.com'); //获取admin的邮箱 +r(count($emails)) && p() && e('2'); //从accounts中获取到的用户邮箱数量 \ No newline at end of file diff --git a/test/model/user/getuserdisplayinfos.php b/test/model/user/getuserdisplayinfos.php index 69b9816426..8366fa54f2 100644 --- a/test/model/user/getuserdisplayinfos.php +++ b/test/model/user/getuserdisplayinfos.php @@ -10,15 +10,10 @@ title=userModel->getPairs(); cid=1 pid=1 -查找带有Closed用户的外部用户键值对 >> Closed -查找带有首字母的外部用户键值对 >> O:用户1 -查找不带首字母的外部用户键值对 >> 用户1 -按照给定的用户名查找用户键值对,返回值中不带有Closed用户 >> 1 -按照给定的用户名查找用户键值对,返回值中带有Closed用户 >> 2 -使用limit参数来限制最多获取2个用户键值对 >> 2 -使用limit参数来限制最多获取50个用户键值对 >> 50 -使用pofirst参数来将系统中的产品经理用户放到返回值前列 >> P:测试主管58 -使用pmfirst参数来将系统中的项目经理用户放到返回值前列 >> O:其他100 +查找获取到的用户名为dev33的真实姓名 >> 项目经理33 +查找获取到的用户名为user10的头像 >> /home/z/tmp/10.png +查找获取到的用户名为outside1的外部用户的头像信息 >> /home/z/tmp/18.png +查找获取到的用户名为cccfff的真实姓名 >> Error: Cannot get index cccfff. */ @@ -28,4 +23,4 @@ $user = new userTest(); 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的真实姓名 +r($user->getUserDisplayInfosTest($accounts)) && p('cccfff:realname') && e('Error: Cannot get index cccfff.'); //查找获取到的用户名为cccfff的真实姓名 \ No newline at end of file diff --git a/test/model/user/getuserroles.php b/test/model/user/getuserroles.php index 45d14e8325..8f2efdde53 100644 --- a/test/model/user/getuserroles.php +++ b/test/model/user/getuserroles.php @@ -10,15 +10,8 @@ title=userModel->getPairs(); cid=1 pid=1 -查找带有Closed用户的外部用户键值对 >> Closed -查找带有首字母的外部用户键值对 >> O:用户1 -查找不带首字母的外部用户键值对 >> 用户1 -按照给定的用户名查找用户键值对,返回值中不带有Closed用户 >> 1 -按照给定的用户名查找用户键值对,返回值中带有Closed用户 >> 2 -使用limit参数来限制最多获取2个用户键值对 >> 2 -使用limit参数来限制最多获取50个用户键值对 >> 50 -使用pofirst参数来将系统中的产品经理用户放到返回值前列 >> P:测试主管58 -使用pmfirst参数来将系统中的项目经理用户放到返回值前列 >> O:其他100 +获取用户名和职位Key的键值对 >> dev +获取用户名和职位Value的键值对 >> 研发 */ @@ -28,4 +21,4 @@ $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(count($user->getUserRolesTest($accounts, false))) && p() && e(2); //从指定accounts中获取到的键值对数量 \ No newline at end of file