diff --git a/test/class/user.class.php b/test/class/user.class.php new file mode 100644 index 0000000000..854110c622 --- /dev/null +++ b/test/class/user.class.php @@ -0,0 +1,430 @@ +objectModel = $tester->loadModel('user'); + } + + /** + * Test get user list. + * + * @param bool $count + * @access public + * @return void + */ + public function getListTest($count = false) + { + $objects = $this->objectModel->getList(); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $count ? count($objects) : $objects; + } + } + + /** + * Test get user information by accounts. + * + * @param array $accounts + * @param bool $count + * @access public + * @return void + */ + public function getListByAccountsTest($accounts = array(), $count = false) + { + $objects = $this->objectModel->getListByAccounts($accounts); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $count ? count($objects) : $objects; + } + } + + /** + * Test user get pairs. + * + * @param string $params + * @param string $usersToAppended + * @param int $maxCount + * @param array $accounts + * @access public + * @return void + */ + public function getPairsTest($params = '', $usersToAppended = '', $maxCount = 0, $accounts = array()) + { + $objects = $this->objectModel->getPairs($params, $usersToAppended, $maxCount, $accounts); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $objects; + } + } + + /** + * Test get avatar pairs. + * + * @access public + * @return void + */ + public function getAvatarPairsTest() + { + $objects = $this->objectModel->getAvatarPairs(); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $objects; + } + } + + /** + * Test get user commiters. + * + * @access public + * @return void + */ + public function getCommitersTest() + { + $objects = $this->objectModel->getCommiters(); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $objects; + } + } + + /** + * Test get user realname and emails. + * + * @param array $accounts + * @access public + * @return void + */ + public function getRealNameAndEmailsTest($accounts) + { + $objects = $this->objectModel->getRealNameAndEmails($accounts); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $objects; + } + } + + /** + * Test get user roles. + * + * @param array $accounts + * @param bool $needRole + * @access public + * @return void + */ + public function getUserRolesTest($accounts, $needRole = false) + { + $objects = $this->objectModel->getUserRoles($accounts, $needRole); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + return $objects; + } + } + + /** + * Test get user display infos. + * + * @param int $accounts + * @param int $deptID + * @param string $type + * @access public + * @return void + */ + public function getUserDisplayInfosTest($accounts, $deptID = 0, $type = 'inside') + { + $objects = $this->objectModel->getUserDisplayInfos($accounts, $deptID, $type); + if(dao::isError()) + { + $error = dao::getError(); + return $error[0]; + } + else + { + 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; + } + } + + /** + * 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 + { + $users = array(); + foreach($userIDList as $userID) $users[] = $this->objectModel->getByID($userID, 'id'); + + return $users; + } + } + + /** + * Test edit a user. + * + * @param int $userID + * @param array $params + * @access public + * @return void + */ + public function updateUserTest($userID, $params = array()) + { + $_POST = $params; + $_POST['verifyPassword'] = 'e79f8fb9726857b212401e42e5b7e18b'; + + $this->objectModel->update($userID); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $this->objectModel->getByID($userID, 'id'); + } + } + + /** + * Test batch edit users. + * + * @param array $params + * @access public + * @return void + */ + public function batchEditUserTest($params = array()) + { + $_POST = $params; + $_POST['verifyPassword'] = 'e79f8fb9726857b212401e42e5b7e18b'; + + $this->objectModel->batchEdit($params); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + $users = array(); + $userIDList = array_keys($params['account']); + foreach($userIDList as $userID) + { + $user = $this->objectModel->getByID($userID, 'id'); + $users[$user->id] = $user; + } + + return $users; + } + } + + /** + * Test edit a user password. + * + * @param int $userID + * @param array $params + * @access public + * @return void + */ + public function updatePasswordTest($userID, $params = array()) + { + $_POST = $params; + + $this->objectModel->updatePassword($userID); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $this->objectModel->getByID($userID, 'id'); + } + } + + /** + * Reset user password. + * + * @param array $params + * @access public + * @return void + */ + public function resetPasswordTest($params = array()) + { + $_POST = $params; + + $this->objectModel->resetPassword(); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + $account = $params['account']; + return $this->objectModel->getByID($account, 'account'); + } + } + + /** + * Check user password. + * + * @param array $params + * @access public + * @return void + */ + public function checkPasswordTest($params = array()) + { + $_POST = $params; + + $this->objectModel->checkPassword(); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return '无报错'; + } + } + + /** + * Identify user. + * + * @param string $account + * @param string $password + * @access public + * @return void + */ + public function identifyTest($account, $password) + { + $_POST = $params; + + $user = $this->objectModel->identify($account, $password); + unset($_POST); + + return $user; + } +} diff --git a/test/data/user.yaml b/test/data/user.yaml index 7fbf1a8ca9..670bc1aeff 100644 --- a/test/data/user.yaml +++ b/test/data/user.yaml @@ -49,12 +49,20 @@ fields: note: "昵称" - field: commiter note: "源代码帐号" + fields: + - field: commiter1 + range: admin,user{99},test{100},dev{100},pm{100},po{100},td{100},pd{100},qd{100},top{100},outside{100},others{100},a,bb,ccc,qwuiadsd?!2as@#%$aasd~aj1!@#1 + - field: commiter2 + range: [],1-99,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,[]{4} - field: avatar note: "" - range: 0 + fields: + - field: avatar1 + range: /home/z/tmp/,/home/z/user/ + - field: avatar2 + range: 1-10,10-20 prefix: "" - postfix: "" - loop: 0 + postfix: ".png" format: "" - field: birthday note: "生日" diff --git a/test/model/user/batchcreate.php b/test/model/user/batchcreate.php new file mode 100644 index 0000000000..6a11f8e31d --- /dev/null +++ b/test/model/user/batchcreate.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +batchCreateTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['account'] = array(1 => 'newtestuser1', 2 => 'newtestuser2', 3 => 'newtestuser3'); +$normalUser['realname'] = array(1 => '新测试用户1', 2 => '新测试用户2', 3 => '新测试用户3'); +$normalUser['visions'] = array(1 => 'rnd', 2 => 'rnd,lite', 3 => 'lite'); +$normalUser['role'] = array(1 => 'qa', 2 => 'dev', 3 => 'pm'); +$normalUser['email'] = array(1 => 'testasd@163.com', 2 => '', 3 => '11773@qq.com'); +$normalUser['password'] = array(1 => 'e10adc3949ba59abbe56e057f20f883e', 2 => 'e10adc3949ba59abbe56e057f20f883e', 3 => 'e10adc3949ba59abbe56e057f20f883e'); + +r($user->batchCreateUserTest($normalUser)) && p('0:account') && e('newtestuser1'); //获取插入的第一个用户的account +r($user->batchCreateUserTest($normalUser)) && p('2:realname') && e('新测试用户3'); //获取插入的最后一个用户的realname + +system("./ztest init"); diff --git a/test/model/user/batchedit.php b/test/model/user/batchedit.php new file mode 100644 index 0000000000..dc509eaf48 --- /dev/null +++ b/test/model/user/batchedit.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +batchEditTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['account'] = array(998 => 'newtestuser1', 999 => 'newtestuser2', 1000 => 'newtestuser3'); +$normalUser['realname'] = array(998 => '新测试用户1', 999 => '新测试用户2', 1000 => '新测试用户3'); +$normalUser['visions'] = array(998 => 'rnd', 999 => 'rnd,lite', 1000 => 'lite'); +$normalUser['role'] = array(998 => 'qa', 999 => 'dev', 1000 => 'pm'); +$normalUser['email'] = array(998 => 'testasd@163.com', 999 => '', 1000 => '11773@qq.com'); +$normalUser['password'] = array(998 => 'e10adc3949ba59abbe56e057f20f883e', 999 => 'e10adc3949ba59abbe56e057f20f883e', 1000 => 'e10adc3949ba59abbe56e057f20f883e'); + +r($user->batchEditUserTest($normalUser)) && p('998:account') && e('newtestuser1'); //获取编辑后的第一个用户的account +r($user->batchEditUserTest($normalUser)) && p('1000:realname') && e('新测试用户3'); //获取编辑的最后一个用户的真实姓名 + +system("./ztest init"); diff --git a/test/model/user/checkpassword.php b/test/model/user/checkpassword.php new file mode 100644 index 0000000000..63ae484b00 --- /dev/null +++ b/test/model/user/checkpassword.php @@ -0,0 +1,44 @@ +#!/usr/bin/env php +checkPasswordTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['password1'] = 'Adsd@#!%qaz'; +$normalUser['password2'] = 'Adsd@#!%qaz'; +$normalUser['passwordStrength'] = 1; + +$weakPassword = $normalUser; +$weakPassword['passwordStrength'] = '0'; + +$differentPassword = $normalUser; +$differentPassword['password2'] = '!@#!@#asfasf'; + +$simplePassword = $normalUser; +$simplePassword['password1'] = '123456'; +$simplePassword['password2'] = '123456'; + +r($user->checkPasswordTest($normalUser)) && p('password') && e('无报错'); //正常的用户密码 +r($user->checkPasswordTest($differentPassword)) && p('password:0') && e('两次密码应该相同。'); //两次密码不相同的情况 +r($user->checkPasswordTest($weakPassword)) && p('password1:0') && e('您的密码强度小于系统设定。'); //密码强度小于系统设定 +r($user->checkPasswordTest($simplePassword)) && p('password1:0') && e('密码不能使用【123456,password,12345,12345678,qwerty,123456789,1234,1234567,abc123,111111,123123】这些常用弱口令。'); //使用常见简单密码,给出错误提示 +system("./ztest init"); diff --git a/test/model/user/create.php b/test/model/user/create.php new file mode 100644 index 0000000000..1a8c0d5779 --- /dev/null +++ b/test/model/user/create.php @@ -0,0 +1,60 @@ +#!/usr/bin/env php +createUserTest(); +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 new file mode 100644 index 0000000000..37c6e80893 --- /dev/null +++ b/test/model/user/getavatarpairs.php @@ -0,0 +1,20 @@ +#!/usr/bin/env php +getPairs(); +cid=1 +pid=1 + +所有用户头像的数量 >> 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"的用户的头像路径 \ No newline at end of file diff --git a/test/model/user/getbyid.php b/test/model/user/getbyid.php index 17f22ba69b..533b877ebe 100755 --- a/test/model/user/getbyid.php +++ b/test/model/user/getbyid.php @@ -1,7 +1,7 @@ #!/usr/bin/env php > account1 -使用account字段获取存在的用户 >> account1 -通过默认字段获取存在的用户 >> account1 +通过id获取存在的用户 >> admin +使用account字段获取存在的用户 >> admin +通过默认字段获取存在的用户 >> 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 new file mode 100644 index 0000000000..d6466aafbc --- /dev/null +++ b/test/model/user/getcommiters.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +getPairs(); +cid=1 +pid=1 + +获取源代码账号为qd100的用户真实姓名 >> 高层管理100 +获取系统中源代码账号不为空的用户数量 >> 1000 + +*/ + +$user = new userTest(); +$commiters = $user->getCommitersTest(); + +r($commiters) && p('qd100') && e('高层管理100'); //获取源代码账号为qd100的用户真实姓名 +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 new file mode 100644 index 0000000000..4cc11069ae --- /dev/null +++ b/test/model/user/getlist.php @@ -0,0 +1,25 @@ +#!/usr/bin/env php +getList(); +cid=1 +pid=1 + +查找系统中第二个未删除的、内部用户真实姓名,根据account正序排 >> 开发1 +查找系统中未删除的、根据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('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 new file mode 100644 index 0000000000..3e25f2c71d --- /dev/null +++ b/test/model/user/getlistbyaccounts.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +getListByAccountsTest(); +cid=1 +pid=1 + +按照给定的用户名列表查询用户信息,获取用户ID为1的用户真实姓名和角色 >> admin,qa +按照给定的用户名列表查询用户信息,获取查询出的用户列表数量 >> 3 +按照给定的用户名列表查询用户信息,获取用户ID为0的用户信息 >> Error: Cannot get index 0. + +*/ +$accounts = array('admin', 'program1whitelist', 'user10', 'ccsdqq@!'); +$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的用户信息 \ No newline at end of file diff --git a/test/model/user/getpairs.php b/test/model/user/getpairs.php new file mode 100644 index 0000000000..2d6e4fd5f4 --- /dev/null +++ b/test/model/user/getpairs.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php +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 + +*/ + +$user = new userTest(); +$accounts = array('tesrasd1asd#@!#$', 'ASD123中文', 'user10', 'ccsdqq@!'); +$outsideUsersWithClosed = $user->getPairsTest('outside'); +$outsideUsersWithLetter = $user->getPairsTest('outside|noclosed'); +$outsideUsersNoLetter = $user->getPairsTest('outside|noclosed|noletter'); +$usersInAccountsNoclosed = $user->getPairsTest('noempty|noclosed', '', 0, $accounts); +$usersInAccountsWithclosed = $user->getPairsTest('noempty', '', 0, $accounts); +$limit2Users = $user->getPairsTest('noempty|noclosed', '', 2); +$limit50Users = $user->getPairsTest('noempty|noclosed', '', 50); +$POFirstUsers = $user->getPairsTest('noempty|noclosed|pofirst'); +$PMFirstUsers = $user->getPairsTest('noempty|noclosed|pmfirst'); +$firstPO = array_slice($POFirstUsers, 0, 1); +$firstPM = array_slice($PMFirstUsers, 0, 1); + +r($outsideUsersWithClosed) && p('closed') && e('Closed'); //查找带有Closed用户的外部用户键值对 +r($outsideUsersWithLetter) && p('outside1') && e('O:用户1'); //查找带有首字母的外部用户键值对 +r($outsideUsersNoLetter) && p('outside1') && e('用户1'); //查找不带首字母的外部用户键值对 +r(count($usersInAccountsNoclosed)) && p() && e('1'); //按照给定的用户名查找用户键值对,返回值中不带有Closed用户 +r(count($usersInAccountsWithclosed)) && p() && e('2'); //按照给定的用户名查找用户键值对,返回值中带有Closed用户 +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参数来将系统中的项目经理用户放到返回值前列 \ No newline at end of file diff --git a/test/model/user/getrealnameandemails.php b/test/model/user/getrealnameandemails.php new file mode 100644 index 0000000000..5dda0f0dc9 --- /dev/null +++ b/test/model/user/getrealnameandemails.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +getPairs(); +cid=1 +pid=1 + +获取admin的邮箱 >> 833482@qq.com +从accounts中获取到的用户邮箱数量 >> 2 + +*/ + +$accounts = array('tesrasd1asd#@!#$', 'ASD123中文', 'user10', 'ccsdqq@!', 'admin'); +$user = new userTest(); +$emails = $user->getRealNameAndEmailsTest($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 new file mode 100644 index 0000000000..8366fa54f2 --- /dev/null +++ b/test/model/user/getuserdisplayinfos.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +getPairs(); +cid=1 +pid=1 + +查找获取到的用户名为dev33的真实姓名 >> 项目经理33 +查找获取到的用户名为user10的头像 >> /home/z/tmp/10.png +查找获取到的用户名为outside1的外部用户的头像信息 >> /home/z/tmp/18.png +查找获取到的用户名为cccfff的真实姓名 >> Error: Cannot get index cccfff. + +*/ + +$accounts = array('!asd12d', '中文用户名', 'user10', 'dev33', 'cccfff', 'outside1'); +$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的真实姓名 \ No newline at end of file diff --git a/test/model/user/getuserroles.php b/test/model/user/getuserroles.php new file mode 100644 index 0000000000..8f2efdde53 --- /dev/null +++ b/test/model/user/getuserroles.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +getPairs(); +cid=1 +pid=1 + +获取用户名和职位Key的键值对 >> dev +获取用户名和职位Value的键值对 >> 研发 + +*/ + +$accounts = array('!asd12d', '中文用户名', 'user10', 'dev33', 'cccfff'); +$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中获取到的键值对数量 \ No newline at end of file diff --git a/test/model/user/identify.php b/test/model/user/identify.php new file mode 100644 index 0000000000..22a47519e2 --- /dev/null +++ b/test/model/user/identify.php @@ -0,0 +1,18 @@ +#!/usr/bin/env php +identifyTest(); +cid=1 +pid=1 + +*/ + +$user = new userTest(); +$user->identifyTest('admin', '78302615c8b79cac8df6d2607f8a83ee'); + +system("./ztest init"); diff --git a/test/model/user/resetpassword.php b/test/model/user/resetpassword.php new file mode 100644 index 0000000000..ab0ec41dd5 --- /dev/null +++ b/test/model/user/resetpassword.php @@ -0,0 +1,45 @@ +#!/usr/bin/env php +resetPasswordTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['account'] = 'admin'; +$normalUser['password1'] = 'Adsd@#!%qaz'; +$normalUser['password2'] = 'Adsd@#!%qaz'; +$normalUser['passwordStrength'] = 1; + +$weakPassword = $normalUser; +$weakPassword['passwordStrength'] = 0; + +$differentPassword = $normalUser; +$differentPassword['password2'] = '!@#!@#asfasf'; + +$simplePassword = $normalUser; +$simplePassword['password1'] = '123456'; +$simplePassword['password2'] = '123456'; + +r($user->resetPasswordTest($normalUser)) && p('password') && e('367ef140036b0feb2f90d70d33255eea'); //重设用户密码,返回重设后的加密后的密码 +r($user->resetPasswordTest($differentPassword)) && p('password:0') && e('两次密码应该相同。'); //两次密码不相同的情况 +r($user->resetPasswordTest($weakPassword)) && p('password1:0') && e('您的密码强度小于系统设定。'); //密码强度小于系统设定 +r($user->resetPasswordTest($simplePassword)) && p('password1:0') && e('密码不能使用【123456,password,12345,12345678,qwerty,123456789,1234,1234567,abc123,111111,123123】这些常用弱口令。'); //使用常见简单密码,给出错误提示 +system("./ztest init"); diff --git a/test/model/user/update.php b/test/model/user/update.php new file mode 100644 index 0000000000..204a6d2718 --- /dev/null +++ b/test/model/user/update.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php +updateUserTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['account'] = 'newtestuser4'; +$normalUser['realname'] = '新的测试用户'; +$normalUser['password1'] = 'e10adc3949ba59abbe56e057f20f883e'; +$normalUser['password2'] = 'e10adc3949ba59abbe56e057f20f883e'; +$normalUser['type'] = 'inside'; +$normalUser['passwordStrength'] = 1; +$normalUser['visions'] = 'rnd'; + +$existUser = $normalUser; +$existUser['account'] = 'adminasdasd'; + +$differentPassword = $normalUser; +$differentPassword['password2'] = 'asfjsdklj1234jkljsdklfj19'; + +$specialUser = $normalUser; +$specialUser['account'] = '!@#Asdsd中文'; + +r($user->updateUserTest(1000, $normalUser)) && p('account') && e('newtestuser4'); //编辑用户,返回新的用户名 +r($user->updateUserTest(1000, $existUser)) && p('account:0') && e('『用户名』已经有『newtestuser4』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。');//编辑用户,有重名用户的情况 +r($user->updateUserTest(1000, $differentPassword)) && p('password:0') && e('两次密码应该相同。'); //两次密码不相同的情况 +r($user->updateUserTest(1000, $specialUser)) && p('account:0') && e('『用户名』只能是字母、数字或下划线的组合三位以上。'); //用户名包含特殊字符的情况 +system("./ztest init"); diff --git a/test/model/user/updatepassword.php b/test/model/user/updatepassword.php new file mode 100644 index 0000000000..9e60a05a12 --- /dev/null +++ b/test/model/user/updatepassword.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php +updatePasswordTest(); +cid=1 +pid=1 + +密码较弱的情况 >> 您的密码强度小于系统设定。 +Visions为空的情况 >> 『版本类型』不能为空。 +用户名为空的情况 >> 『用户名』不能为空。 +用户名特殊的情况 >> 『用户名』只能是字母、数字或下划线的组合三位以上。 +两次密码不相同的情况 >> 两次密码应该相同。 +插入重复的用户名,返回报错信息 >> 『用户名』已经有『admin』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +正常插入用户,返回新插入的ID、真实姓名 >> 1001,新的测试用户 +正常插入用户,返回新插入的真实姓名 >> 新的测试用户 + +*/ + +$user = new userTest(); +$normalUser = array(); +$normalUser['originalPassword'] = 'e79f8fb9726857b212401e42e5b7e18b'; +$normalUser['password1'] = 'dcf859ce8dd8f998bdfe4ae6c22c329e'; +$normalUser['password2'] = 'dcf859ce8dd8f998bdfe4ae6c22c329e'; +$normalUser['passwordStrength'] = 1; + +$weakPassword = $normalUser; +$weakPassword['passwordStrength'] = 0; + +$differentPassword = $normalUser; +$differentPassword['password2'] = 'asdasfasf!@#!@#asfasf'; + +r($user->updatePasswordTest(1000, $normalUser)) && p('password') && e('dcf859ce8dd8f998bdfe4ae6c22c329e'); //编辑用户密码,返回编辑后的密码 +r($user->updatePasswordTest(1000, $differentPassword)) && p('password:0') && e('两次密码应该相同。'); //两次密码不相同的情况 +r($user->updatePasswordTest(1000, $weakPassword)) && p('password1:0') && e('您的密码强度小于系统设定。'); //密码小于设定强度的情况 + +system("./ztest init"); diff --git a/test/ztest b/test/ztest index d6f9f9680d..e3474d2821 100755 --- a/test/ztest +++ b/test/ztest @@ -34,6 +34,9 @@ switch($argv[1]) case 'execution': ztfRun('model/execution'); break; + case 'user': + ztfRun('model/user'); + break; case 'model': ztfRun('model'); break;