From de2e4be17454d8f4f7e53265116e567d927d6e40 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Fri, 17 Dec 2021 10:23:57 +0800 Subject: [PATCH] * Fix test. --- .gitignore | 1 + framework/api/entry.class.php | 1 + lib/base/front/front.class.php | 2 - module/api/js/common.js | 2 - module/product/control.php | 4 +- test/api/bugs/browse.php | 17 +++- test/api/products/create.php | 11 ++- test/api/products/delete.php | 6 +- test/api/products/getbyid.php | 6 +- test/api/products/getlist.php | 16 +++- test/api/products/update.php | 4 +- test/api/project/get.php | 2 +- test/api/projects/get.php | 2 +- test/api/projects/post.php | 3 +- test/api/testcases/delete.php | 2 +- test/api/testcases/getbyid.php | 2 +- test/api/testcases/getlist.php | 5 +- test/api/tokens/post.php | 2 +- test/api/users/delete.php | 4 +- test/data/{zt_action.yaml => action.yaml} | 0 test/data/company.yaml | 12 +-- test/data/dept.yaml | 14 ++- test/data/{zentao => }/program.yaml | 9 +- test/data/project.yaml | 13 ++- test/data/user.yaml | 13 +-- test/data/zentao/commonproject.yaml | 37 -------- test/data/zentao/config.php | 11 +-- test/data/zentao/deptgrade1.yaml | 24 ----- test/data/zentao/deptgrade2.yaml | 33 ------- test/data/zentao/deptgrade3.yaml | 36 -------- test/data/zentao/execution.yaml | 60 ------------- test/data/zentao/programgrade1.yaml | 17 ---- test/data/zentao/programgrade2.yaml | 24 ----- test/data/zentao/programgrade3.yaml | 25 ------ test/data/zentao/projectgrade1.yaml | 21 ----- test/data/zentao/projectgrade2.yaml | 24 ----- test/data/zentao/projectgrade3.yaml | 27 ------ test/data/zentao/projectgrade4.yaml | 30 ------- test/lib/utils.php | 103 +++++++++++++--------- 39 files changed, 173 insertions(+), 452 deletions(-) rename test/data/{zt_action.yaml => action.yaml} (100%) rename test/data/{zentao => }/program.yaml (82%) delete mode 100644 test/data/zentao/commonproject.yaml delete mode 100644 test/data/zentao/deptgrade1.yaml delete mode 100644 test/data/zentao/deptgrade2.yaml delete mode 100644 test/data/zentao/deptgrade3.yaml delete mode 100644 test/data/zentao/execution.yaml delete mode 100644 test/data/zentao/programgrade1.yaml delete mode 100644 test/data/zentao/programgrade2.yaml delete mode 100644 test/data/zentao/programgrade3.yaml delete mode 100644 test/data/zentao/projectgrade1.yaml delete mode 100644 test/data/zentao/projectgrade2.yaml delete mode 100644 test/data/zentao/projectgrade3.yaml delete mode 100644 test/data/zentao/projectgrade4.yaml diff --git a/.gitignore b/.gitignore index dd804eae67..93a4a42186 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ config/my.php www/data/ www/install.php www/upgrade.php +www/checklist.php www/ok.txt tools/* release/* diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index c722c5b2b5..a2c6496563 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -275,6 +275,7 @@ class baseEntry global $app; $app->setModuleName($moduleName); $app->setMethodName($methodName); + $app->viewType = 'json'; /* Check user permission. */ $this->checkPriv(); diff --git a/lib/base/front/front.class.php b/lib/base/front/front.class.php index 0c2d4ad8ef..d6993697fa 100644 --- a/lib/base/front/front.class.php +++ b/lib/base/front/front.class.php @@ -108,8 +108,6 @@ class baseHTML */ static public function a($href = '', $title = '', $misc = '', $newline = true) { - global $config; - if(strlen(trim($title)) == 0) $title = $href; $newline = $newline ? "\n" : ''; diff --git a/module/api/js/common.js b/module/api/js/common.js index 42576d9c0c..ff2ec1e452 100644 --- a/module/api/js/common.js +++ b/module/api/js/common.js @@ -164,10 +164,8 @@ $(document).ready(function() { $('.split-row').splitRow(); }); - }); - /** * Redirect the parent window. * diff --git a/module/product/control.php b/module/product/control.php index 569a8ec0fa..7f786e0f95 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -30,8 +30,8 @@ class product extends control $this->loadModel('user'); /* Get all products, if no, goto the create page. */ - $this->products = $this->product->getPairs('nocode|all'); - if(empty($this->products) and strpos(',create,index,showerrornone,ajaxgetdropmenu,kanban', $this->methodName) === false and $this->app->getViewType() != 'mhtml') $this->locate($this->createLink('product', 'create')); + $this->products = $this->product->getPairs('nocode'); + if($this->app->viewType !== 'json' and empty($this->products) and strpos(',create,index,showerrornone,ajaxgetdropmenu,kanban', $this->methodName) === false and $this->app->getViewType() != 'mhtml') $this->locate($this->createLink('product', 'create')); $this->view->products = $this->products; } diff --git a/test/api/bugs/browse.php b/test/api/bugs/browse.php index 1e22b7207b..51c4b57967 100644 --- a/test/api/bugs/browse.php +++ b/test/api/bugs/browse.php @@ -8,10 +8,19 @@ title=测试API 获取bug列表 cid=1 pid=1 -通过正确的productID获取bug列表的状态码 >> 200 -通过错误的productID获取bug列表的状态码 >> 200 -通过正确的productID获取bug列表的数量 >> 10 -通过错误的productID获取bug列表的数量 >> 0 + >> /bugs/ +创建最少字段的Bug >> product required. +创建最少字段的Bug >> title required. +创建最少字段的Bug >> Bug1 +创建最多字段的Bug >> Bug2 +创建不存在产品的Bug >> product does not exist. + >> Bug2 + >> Bug1 + >> Bug1 + >> Bug1 + >> Bug3 + >> Bug3 + >> true */ diff --git a/test/api/products/create.php b/test/api/products/create.php index bcae1dfa39..fdb12ed2c1 100644 --- a/test/api/products/create.php +++ b/test/api/products/create.php @@ -8,6 +8,15 @@ title=测试创建产品; cid=1 pid=1 +测试创建所属项目集为1的产品 >> CESHI1,CESHI1 +测试创建独立产品 >> 0 +测试产品名称为空的情况 >> 『产品名称』不能为空。 +测试产品代号为空的情况 >> 『产品代号』不能为空。 +测试状态码 >> 400 +测试产品名称已存在 >> 『产品名称』已经有『CESHI1』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 +测试状态码 >> 400 +测试产品代号已存在 >> 『产品代号』已经有『CESHI1』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。 + */ global $token; $header = array('Token' => $token->token); @@ -30,4 +39,4 @@ r($existedName->body->error) && p('name:0') && e('『产品名称』已经有『 $existedCode = $rest->post('/products', array('name' => 'CESHI4','code' => 'CESHI1'), $header); r($existedCode->status_code) && p() && e('400'); //测试状态码 -r($existedCode->body->error) && p('code:0') && e('『产品代号』已经有『CESHI1』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。'); //测试产品代号已存在 +r($existedCode->body->error) && p('code:0') && e('『产品代号』已经有『CESHI1』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。'); //测试产品代号已存在 \ No newline at end of file diff --git a/test/api/products/delete.php b/test/api/products/delete.php index 9a803a85ab..4d6b17b505 100644 --- a/test/api/products/delete.php +++ b/test/api/products/delete.php @@ -8,6 +8,10 @@ title=测试删除产品; cid=1 pid=1 +调用成功,返回200 >> 200 +调用查找接口,成功返回200 >> 200 +已删除的产品的deleted字段为1 >> 1 + */ global $token; $header = array('Token' => $token->token); @@ -17,4 +21,4 @@ r($pass->status_code) && p('') && e('200'); //调用成功,返回200 $findProduct = $rest->get('/products/190', $header); r($findProduct->status_code) && p() && e('200'); //调用查找接口,成功返回200 -r($findProduct->body) && p('deleted') && e('1'); //已删除的产品的deleted字段为1 +r($findProduct->body) && p('deleted') && e('1'); //已删除的产品的deleted字段为1 \ No newline at end of file diff --git a/test/api/products/getbyid.php b/test/api/products/getbyid.php index 3ad072d6fa..06fa0603bd 100644 --- a/test/api/products/getbyid.php +++ b/test/api/products/getbyid.php @@ -8,6 +8,10 @@ title=测试获取产品详情; cid=1 pid=1 +调用成功,返回200 >> 200 +期望code为code1 >> code1 +ID为1000的产品不存在,返回401 >> 404 + */ global $token; $header = array('Token' => $token->token); @@ -17,4 +21,4 @@ r($pass->status_code) && p() && e('200'); //调用成功,返回200 r($pass->body) && p('code') && e('code1'); //期望code为code1 $fail = $rest->get('/products/1000', $header); -r($fail->status_code) && p() && e('404'); //ID为1000的产品不存在,返回401 +r($fail->status_code) && p() && e('404'); //ID为1000的产品不存在,返回401 \ No newline at end of file diff --git a/test/api/products/getlist.php b/test/api/products/getlist.php index 5ddf85268d..ff94abce34 100644 --- a/test/api/products/getlist.php +++ b/test/api/products/getlist.php @@ -8,6 +8,18 @@ title=测试获取产品列表; cid=1 pid=1 +调用成功,返回200 >> 200 +测试所有产品的数量 >> 191 +查看所有产品中第一个产品的ID和code >> 1,code1 +调用成功,返回200 >> 200 +测试已关闭的产品的数量 >> 90 +查看已关闭的第一个产品的ID和code >> 21,code21 +调用成功,返回200 >> 200 +测试正常状态的产品的数量 >> 101 +查看正常状态的第一个产品的ID和code >> 1,code1 +调用成功,返回200 >> 200 +测试使用错误的状态参数查询时结果为空 >> 0 + */ global $token; $header = array('Token' => $token->token); @@ -32,6 +44,4 @@ r($productList) && p('0:id,code') && e('1,code1'); //查看正 $statusError = $rest->get('/products?status=doing', $header); r($statusError->status_code) && p() && e('200'); //调用成功,返回200 -r(count($statusError->body->products)) && p() && e('0'); //测试使用错误的状态参数查询时结果为空 - - +r(count($statusError->body->products)) && p() && e('0'); //测试使用错误的状态参数查询时结果为空 \ No newline at end of file diff --git a/test/api/products/update.php b/test/api/products/update.php index 262c24cb40..f592c7fa8e 100644 --- a/test/api/products/update.php +++ b/test/api/products/update.php @@ -8,9 +8,11 @@ title=测试修改产品信息; cid=1 pid=1 +调用成功,返回200 >> 200 + */ global $token; $header = array('Token' => $token->token); $pass = $rest->put('/products/1', array('name' => '测试正常产品1'), $header); -r($pass->status_code) && p() && e('200'); //调用成功,返回200 +r($pass->status_code) && p() && e('200'); //调用成功,返回200 \ No newline at end of file diff --git a/test/api/project/get.php b/test/api/project/get.php index 677e970957..c499d5833c 100644 --- a/test/api/project/get.php +++ b/test/api/project/get.php @@ -20,4 +20,4 @@ $stringIdError = $rest->get('/projects/test', array("Token" => $token->body->tok r($project) && c('200') && p('project,type', ',') && e('0,project'); // 获取条目的project和type字段 r($zeroIdError) && c('404') && p('error') && e('404 Not found'); // 获取不存在的项目 -r($stringIdError) && c('404') && p('error') && e('404 Not found'); // 获取错误ID的项目 +r($stringIdError) && c('404') && p('error') && e('404 Not found'); // 获取错误ID的项目 \ No newline at end of file diff --git a/test/api/projects/get.php b/test/api/projects/get.php index 70367f0912..d4d54404d7 100644 --- a/test/api/projects/get.php +++ b/test/api/projects/get.php @@ -15,4 +15,4 @@ global $token; $projects = $rest->get('/projects', array("Token" => $token)); $project = array(reset($projects->body->projects)); -r($project) && p('project,type', ',') && e('0,project'); // 获取条目的project和type字段 +r($project) && p('project,type', ',') && e('0,project'); // 获取条目的project和type字段 \ No newline at end of file diff --git a/test/api/projects/post.php b/test/api/projects/post.php index 3c8222de44..f91e62bdb7 100644 --- a/test/api/projects/post.php +++ b/test/api/projects/post.php @@ -8,6 +8,7 @@ title=创建项目; cid=1 pid=1 + >> Y-m-d 创建失败,没有name字段 >> `『项目名称』` 创建失败,没有code字段 >> `『项目代号』` 创建失败,没有end字段 >> `『计划完成』` @@ -58,4 +59,4 @@ r($noNameError) && p('error') && e('`『项目名称』`'); // r($noCodeError) && p('error') && e('`『项目代号』`'); // 创建失败,没有code字段 r($noEndError) && p('error') && e('`『计划完成』`'); // 创建失败,没有end字段 r($project) && c('201') && p('name,code', ',') && e('test111,test222'); // 创建成功,获取创建的name和code字段 -r($error) && p('error') && e('`『test111』`'); // 创建失败,获取错误信息 +r($error) && p('error') && e('`『test111』`'); // 创建失败,获取错误信息 \ No newline at end of file diff --git a/test/api/testcases/delete.php b/test/api/testcases/delete.php index 6603df589a..6da5e0ecc6 100644 --- a/test/api/testcases/delete.php +++ b/test/api/testcases/delete.php @@ -25,4 +25,4 @@ r($deleteNotExist) && c(200) && p() && e('{"message":"success"}'); // 使用不 $existCase = $rest->get('/testcases/1', $header); $existCase->body = array($existCase->body); -r($existCase) && c(200) && p('title,deleted') && e('这个是测试用例1,1'); // 查询已删除的用例信息 +r($existCase) && c(200) && p('title,deleted') && e('这个是测试用例1,1'); // 查询已删除的用例信息 \ No newline at end of file diff --git a/test/api/testcases/getbyid.php b/test/api/testcases/getbyid.php index d8c3bf81bc..bf0f4cce2c 100644 --- a/test/api/testcases/getbyid.php +++ b/test/api/testcases/getbyid.php @@ -22,4 +22,4 @@ $existCase->body = array($existCase->body); $noCase->body = array($noCase->body); r($existCase) && c(200) && p('title') && e('这个是测试用例100'); // 使用正确用例id查询用例详情 -r($noCase) && c(404) && p('error') && e('404 Not found'); // 使用不存在的用例id查询用例详情 +r($noCase) && c(404) && p('error') && e('404 Not found'); // 使用不存在的用例id查询用例详情 \ No newline at end of file diff --git a/test/api/testcases/getlist.php b/test/api/testcases/getlist.php index 798d71d6dc..29f796ef1a 100644 --- a/test/api/testcases/getlist.php +++ b/test/api/testcases/getlist.php @@ -10,9 +10,10 @@ pid=1 使用正确产品id查询用例列表的状态码 >> 200 使用不存在的产品id查询用例列表的状态码 >> 200 +使用产品id为0查询用例列表的状态码 >> "Need product or project or execution id. 使用正确产品id获取用例列表的数量 >> 50 使用不存在的产品id获取用例列表的数量 >> 0 -使用正确产品id获取用例列表 >> 这个是测试用例51,这个是测试用例52 +使用正确产品id获取用例列表 >> 这个是测试用例51,这个是测试用例52,这个是测试用例53,这个是测试用例54,这个是测试用例55,这个是测试用例56,这个是测试用例57,这个是测试用例58,这个是测试用例59,这个是测试用例60,这个是测试用例61,这个是测试用例62,这个是测试用例63,这个是测试用例64,这个是测试用例65,这个是测试用例66,这个是测试用例67,这个是测试用例68,这个是测试用例69,这个是测试用例70,这个是测试用例71,这个是测试用例72,这个是测试用例73,这个是测试用例74,这个是测试用例75,这个是测试用例76,这个是测试用例77,这个是测试用例78,这个是测试用例79,这个是测试用例80,这个是测试用例81,这个是测试用例82,这个是测试用例83,这个是测试用例84,这个是测试用例85,这个是测试用例86,这个是测试用例87,这个是测试用例88,这个是测试用例89,这个是测试用例90,这个是测试用例91,这个是测试用例92,这个是测试用例93,这个是测试用例94,这个是测试用例95,这个是测试用例96,这个是测试用例97,这个是测试用例98,这个是测试用例99,这个是测试用例100 */ global $token; @@ -33,4 +34,4 @@ $emptyCases = $notExistProductCases->body->testcases; r(count($existCases)) && p() && e('50'); // 使用正确产品id获取用例列表的数量 r(count($emptyCases)) && p() && e('0'); // 使用不存在的产品id获取用例列表的数量 -r($existCases) && p('title') && e('这个是测试用例51,这个是测试用例52,这个是测试用例53,这个是测试用例54,这个是测试用例55,这个是测试用例56,这个是测试用例57,这个是测试用例58,这个是测试用例59,这个是测试用例60,这个是测试用例61,这个是测试用例62,这个是测试用例63,这个是测试用例64,这个是测试用例65,这个是测试用例66,这个是测试用例67,这个是测试用例68,这个是测试用例69,这个是测试用例70,这个是测试用例71,这个是测试用例72,这个是测试用例73,这个是测试用例74,这个是测试用例75,这个是测试用例76,这个是测试用例77,这个是测试用例78,这个是测试用例79,这个是测试用例80,这个是测试用例81,这个是测试用例82,这个是测试用例83,这个是测试用例84,这个是测试用例85,这个是测试用例86,这个是测试用例87,这个是测试用例88,这个是测试用例89,这个是测试用例90,这个是测试用例91,这个是测试用例92,这个是测试用例93,这个是测试用例94,这个是测试用例95,这个是测试用例96,这个是测试用例97,这个是测试用例98,这个是测试用例99,这个是测试用例100'); // 使用正确产品id获取用例列表 +r($existCases) && p('title') && e('这个是测试用例51,这个是测试用例52,这个是测试用例53,这个是测试用例54,这个是测试用例55,这个是测试用例56,这个是测试用例57,这个是测试用例58,这个是测试用例59,这个是测试用例60,这个是测试用例61,这个是测试用例62,这个是测试用例63,这个是测试用例64,这个是测试用例65,这个是测试用例66,这个是测试用例67,这个是测试用例68,这个是测试用例69,这个是测试用例70,这个是测试用例71,这个是测试用例72,这个是测试用例73,这个是测试用例74,这个是测试用例75,这个是测试用例76,这个是测试用例77,这个是测试用例78,这个是测试用例79,这个是测试用例80,这个是测试用例81,这个是测试用例82,这个是测试用例83,这个是测试用例84,这个是测试用例85,这个是测试用例86,这个是测试用例87,这个是测试用例88,这个是测试用例89,这个是测试用例90,这个是测试用例91,这个是测试用例92,这个是测试用例93,这个是测试用例94,这个是测试用例95,这个是测试用例96,这个是测试用例97,这个是测试用例98,这个是测试用例99,这个是测试用例100'); // 使用正确产品id获取用例列表 \ No newline at end of file diff --git a/test/api/tokens/post.php b/test/api/tokens/post.php index 35ca41143a..04f05a0875 100755 --- a/test/api/tokens/post.php +++ b/test/api/tokens/post.php @@ -17,4 +17,4 @@ $pass = $rest->post('/tokens', array('account' => 'admin', 'password' => '123qwe $fail = $rest->post('/tokens', array('account' => 'admin', 'password' => '123')); r($pass) && c(201) && p('token') && e('`[A-Za-z0-9]+`'); // 使用正确用户名和密码获取token -r($fail) && c(400) && p('error') && e('登录失败,请检查您的用户名或密码是否填写正确。'); // 使用正确用户名和密码获取token +r($fail) && c(400) && p('error') && e('登录失败,请检查您的用户名或密码是否填写正确。'); // 使用正确用户名和密码获取token \ No newline at end of file diff --git a/test/api/users/delete.php b/test/api/users/delete.php index 34aa2671ff..3d9e36c39d 100644 --- a/test/api/users/delete.php +++ b/test/api/users/delete.php @@ -8,11 +8,11 @@ title=删除用户; cid=1 pid=1 -删除用户 >> message:success +删除ID为10的用户,判断返回信息 >> message:success */ global $token; $result = $rest->delete('/users/10', array('token' => $token->token)); -r($result) && c(200) && p() && e("message:success") ; //删除ID为10的用户,判断返回信息 +r($result) && c(200) && p() && e("message:success") ; //删除ID为10的用户,判断返回信息 \ No newline at end of file diff --git a/test/data/zt_action.yaml b/test/data/action.yaml similarity index 100% rename from test/data/zt_action.yaml rename to test/data/action.yaml diff --git a/test/data/company.yaml b/test/data/company.yaml index 970634b829..60629603f5 100644 --- a/test/data/company.yaml +++ b/test/data/company.yaml @@ -6,14 +6,14 @@ fields: - field: id note: "id" range: 1 - - field: name + - field: name note: "公司名" range: 易软天创网络科技有限公司 - - field: admins + - field: admins note: "管理员" - prefix: "," + prefix: "," range: admin - postfix: "," + postfix: "," - field: phone note: "电话" range: 15666933065 @@ -23,9 +23,9 @@ fields: - field: website note: "网站" range: www.zentao.net - - field: guest + - field: guest note: "匿名登录" range: 0 - - field: deleted + - field: deleted note: "是否删除" range: 0 diff --git a/test/data/dept.yaml b/test/data/dept.yaml index 501a47d96b..87e7e0264f 100644 --- a/test/data/dept.yaml +++ b/test/data/dept.yaml @@ -8,12 +8,20 @@ fields: - field: name fields: - field: name1 - range: [@#$%%&&*((adfdfss,测试名称长度能有多长并且包含特殊字符的一个长长的字符串!@#¥%……&×()哈哈哈哈,一级部门]{5} + range: 产品部,开发部,测试部,运营部,开发部1,开发部2,测试名称长度能有多长并且包含特殊字符的一个长长的字符串!@#¥%……&×()哈哈哈哈,[一级部门,二级部门,三级部门]{10},其他部门{10000} - field: name2 - range: A-E + range: []{7},1-10,1-10,1-10,1-10000 - field: order note: "排序" - range: 10-150:10,10-100:10{2!} + range: 1-10000 + - field: path + note: "路径" + range: 1-10000 + prefix: "," + postfix: "," + - field: grade + note: "层级" + range: 1 - field: position range: "" - field: function diff --git a/test/data/zentao/program.yaml b/test/data/program.yaml similarity index 82% rename from test/data/zentao/program.yaml rename to test/data/program.yaml index db1038a271..5b5378a0a3 100644 --- a/test/data/zentao/program.yaml +++ b/test/data/program.yaml @@ -5,7 +5,14 @@ fields: - field: project range: 0 - field: model - range: + range: "" + - field: name + note: "名称" + fields: + - field: name1 + range: "项目集" + - field: name2 + range: 1-10000 - field: type range: program - field: status diff --git a/test/data/project.yaml b/test/data/project.yaml index cbe6402a19..da6d534838 100644 --- a/test/data/project.yaml +++ b/test/data/project.yaml @@ -2,12 +2,17 @@ title: table zt_project author: Zhu Jinyong version: "1.0" fields: - - field: id - range: 1-10000 - field: project - range: 1-10000 + range: 0 - field: model - range: + range: "" + - field: name + note: "名称" + fields: + - field: name1 + range: '项目' + - field: name2 + range: []{100000} - field: type range: project - field: lifetime diff --git a/test/data/user.yaml b/test/data/user.yaml index ea4e555b5b..e1b4df56c1 100644 --- a/test/data/user.yaml +++ b/test/data/user.yaml @@ -12,7 +12,7 @@ fields: format: "" - field: type note: "内外部人员" - range: inside{344},outside,inside + range: inside{900},outside,inside{10000} prefix: "" postfix: "" loop: 0 @@ -25,9 +25,9 @@ fields: note: "用户名" fields: - field: account1 - range: admin,program1User,noprogram1user,product1user,noproduct1user,project1user,noproject1user,test{100},dev{200},pm{10},po{10},td{2},pd{2},qd{2},top{5},others{10},a,bb,ccc,qwuiadsd?!2as@#%$aasd~aj1!@#1 + 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: account2 - range: [],1-100,1-200,1-10,1-10,1-2,1-2,1-2,1-5,1-10 + 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: password note: "密码" range: 123qwe!@#{346} @@ -43,9 +43,9 @@ fields: note: "真实姓名" fields: - field: realname1 - range: admin,测试{100},开发{200},项目经理{10},产品经理{10},研发主管{2},产品主管{2},测试主管{2},高层管理{5},其他{10},短用户名,BB,CCC,非常长非常长的用户名怎么这么长? + range: admin,用户,测试{100},开发{100},项目经理{100},产品经理{100},研发主管{100},产品主管{100},测试主管{100},高层管理{100},用户{100},其他{100},A,BB,CCC,非常长非常长的用户名怎么这么长? - field: realname2 - range: [],1-100,1-200,1-10,1-10,1-2,1-2,1-2,1-5,1-10 + 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: nickname note: "昵称" - field: commiter @@ -148,6 +148,9 @@ fields: - field: locked note: "锁定时间" range: 0 + - field: company + note: "公司" + range: 1 - field: ranzhi note: "ZDOO账号" - field: score diff --git a/test/data/zentao/commonproject.yaml b/test/data/zentao/commonproject.yaml deleted file mode 100644 index 7c7da39c17..0000000000 --- a/test/data/zentao/commonproject.yaml +++ /dev/null @@ -1,37 +0,0 @@ -title: project -author: Zhu Jinyong -version: "1.0" -fields: - - field: project - range: 0 - - field: model - range: scrum - - field: type - range: project - - field: status - range: wait - - field: percent - range: 0 - - field: auth - range: extend,reset - - field: desc - range: 1-10000 - prefix: "项目描述" - - field: acl - range: open{4},private{4} - - field: whitelist - froms: - - from: common.user.v1.yaml - use: empty{8} - - from: common.user.v1.yaml - use: empty{8} - prefix: "," - - from: common.user.v1.yaml - use: one{8} - prefix: "," - - from: common.user.v1.yaml - use: two{8} - prefix: "," - - from: common.user.v1.yaml - use: three{8} - prefix: "," diff --git a/test/data/zentao/config.php b/test/data/zentao/config.php index d2af5e1731..9352cfc25a 100644 --- a/test/data/zentao/config.php +++ b/test/data/zentao/config.php @@ -1,8 +1,9 @@ user = array('rows' => 1000, 'extends' => array('user')); -$builder->dept = array('rows' => 100, 'extends' => array('dept')); +$builder->company = array('rows' => 1, 'extends' => array('company')); +$builder->user = array('rows' => 1000, 'extends' => array('user')); +$builder->dept = array('rows' => 100, 'extends' => array('dept')); $builder->program = array('rows' => 100, 'extends' => array('project', 'program')); $builder->project = array('rows' => 100, 'extends' => array('project', 'project')); @@ -15,6 +16,6 @@ $builder->branch = array('rows' => 240, 'extends' => array('branch')); $builder->build = array('rows' => 8, 'extends' => array('build')); $builder->release = array('rows' => 8, 'extends' => array('release')); -$builder->pipeline = array('rows' => 1, 'data' => array('pipeline')); -$builder->repo = array('rows' => 1, 'data' => array('repo')); -$builder->mr = array('rows' => 1, 'data' => array('mr')); +$builder->pipeline = array('rows' => 1, 'extends' => array('pipeline')); +$builder->repo = array('rows' => 1, 'extends' => array('repo')); +$builder->mr = array('rows' => 1, 'extends' => array('mr')); diff --git a/test/data/zentao/deptgrade1.yaml b/test/data/zentao/deptgrade1.yaml deleted file mode 100644 index 26fa77a081..0000000000 --- a/test/data/zentao/deptgrade1.yaml +++ /dev/null @@ -1,24 +0,0 @@ -title: dept -author: Li yuhcun -version: "1.0" -fields: - - field: id - note: "ID" - range: 1-10000 - - field: grade - note: "部门级别" - range: 1 - - field: parent - note: "上级部门ID" - range: 0 - - field: path - range: 1-15 - prefix: "," - postfix: "," - - field: manager - note: "负责人" - fields: - - field: manager1 - range: test{5},[]{5} - - field: manager2 - range: 1-50:10,[]{5},51-100:10 diff --git a/test/data/zentao/deptgrade2.yaml b/test/data/zentao/deptgrade2.yaml deleted file mode 100644 index ad5f5798c2..0000000000 --- a/test/data/zentao/deptgrade2.yaml +++ /dev/null @@ -1,33 +0,0 @@ -title: dept -author: Li yuhcun -version: "1.0" -fields: - - field: id - note: "ID" - range: 16-10000 - - field: name - note: "部门名称" - fields: - - field: name1 - range: 二级部门{10} - - field: name2 - range: A-J - - field: grade - note: "部门级别" - range: 2 - - field: parent - note: "上级部门ID" - range: 11 - - field: path - fields: - - field: grade1 - range: 11 - prefix: "," - postfix: "," - - field: grade2 - range: 16-25 - postfix: "," - - field: manager - note: "负责人" - range: 1-200:10 - prefix: "dev" diff --git a/test/data/zentao/deptgrade3.yaml b/test/data/zentao/deptgrade3.yaml deleted file mode 100644 index 191d90beaa..0000000000 --- a/test/data/zentao/deptgrade3.yaml +++ /dev/null @@ -1,36 +0,0 @@ -title: dept -author: Li yuhcun -version: "1.0" -fields: - - field: id - note: "ID" - range: 26-10000 - - field: name - note: "部门名称" - fields: - - field: name1 - range: 三级部门{10} - - field: name2 - range: A-J - - field: path - fields: - - field: grade1 - range: 11 - prefix: "," - postfix: "," - - field: grade2 - range: 16 - postfix: "," - - field: grade3 - range: 26-25 - postfix: "," - - field: grade - note: "部门级别" - range: 3 - - field: parent - note: "上级部门ID" - range: 16 - - field: manager - note: "负责人" - range: 101-200:10 - prefix: "dev" diff --git a/test/data/zentao/execution.yaml b/test/data/zentao/execution.yaml deleted file mode 100644 index 48712f5a86..0000000000 --- a/test/data/zentao/execution.yaml +++ /dev/null @@ -1,60 +0,0 @@ -title: project -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 241-10000 - - field: name - fields: - - field: grade1 - prefix: "测试项目" - range: 1-120 - - field: grade2 - prefix: "下的迭代" - range: 1-10000 - - field: project - range: 121-130{15},131-240{5} - - field: model - range: - - field: type - range: sprint - - field: status - range: wait,doing - - field: percent - range: 0 - - field: auth - range: - - field: desc - range: 1-10000 - prefix: "迭代描述" - - field: grade - range: 1 - - field: parent - range: 121-130{15},131-240{5} - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 121-130{15},131-240{5} - - field: self - postfix: "," - range: 241-10000 - - field: acl - range: open{4},private{4} - - field: whitelist - froms: - - from: common.user.v1.yaml - use: empty{8} - - from: common.user.v1.yaml - use: empty{8} - prefix: "," - - from: common.user.v1.yaml - use: one{8} - prefix: "," - - from: common.user.v1.yaml - use: two{8} - prefix: "," - - from: common.user.v1.yaml - use: three{8} - prefix: "," diff --git a/test/data/zentao/programgrade1.yaml b/test/data/zentao/programgrade1.yaml deleted file mode 100644 index fcbec24e67..0000000000 --- a/test/data/zentao/programgrade1.yaml +++ /dev/null @@ -1,17 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 1-10000 - - field: name - range: 1-10000 - prefix: "一级测试项目集" - - field: grade - range: 1 - - field: parent - range: 0 - - field: path - prefix: "," - postfix: "," - range: 1-10000 diff --git a/test/data/zentao/programgrade2.yaml b/test/data/zentao/programgrade2.yaml deleted file mode 100644 index 3871c82683..0000000000 --- a/test/data/zentao/programgrade2.yaml +++ /dev/null @@ -1,24 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 41-10000 - - field: name - range: 41-10000 - prefix: "二级测试项目集" - - field: type - range: program - - field: grade - range: 2 - - field: parent - range: 1-40{2} - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 1-40{2} - - field: self - postfix: "," - range: 41-10000 diff --git a/test/data/zentao/programgrade3.yaml b/test/data/zentao/programgrade3.yaml deleted file mode 100644 index 735b0479ee..0000000000 --- a/test/data/zentao/programgrade3.yaml +++ /dev/null @@ -1,25 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 81-10000 - - field: name - range: 81-10000 - prefix: "三级测试项目集" - - field: grade - range: 3 - - field: parent - range: 41-80{2} - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 1-40{2} - - field: grade2 - postfix: "," - range: 41-80{2} - - field: self - postfix: "," - range: 81-10000 diff --git a/test/data/zentao/projectgrade1.yaml b/test/data/zentao/projectgrade1.yaml deleted file mode 100644 index 41858be409..0000000000 --- a/test/data/zentao/projectgrade1.yaml +++ /dev/null @@ -1,21 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 121-10000 - - field: name - range: 1-10000 - prefix: "独立测试项目" - - field: status - range: wait - - field: grade - range: 1 - - field: parent - range: 0 - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 121-10000 diff --git a/test/data/zentao/projectgrade2.yaml b/test/data/zentao/projectgrade2.yaml deleted file mode 100644 index 6fa4dcff37..0000000000 --- a/test/data/zentao/projectgrade2.yaml +++ /dev/null @@ -1,24 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 131-10000 - - field: name - range: 11-10000 - prefix: "测试项目" - - field: status - range: wait - - field: grade - range: 2 - - field: parent - range: 1-40{2} - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 1-40{2} - - field: grade2 - postfix: "," - range: 131-10000 diff --git a/test/data/zentao/projectgrade3.yaml b/test/data/zentao/projectgrade3.yaml deleted file mode 100644 index 17585a3df6..0000000000 --- a/test/data/zentao/projectgrade3.yaml +++ /dev/null @@ -1,27 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 161-10000 - - field: name - range: 41-10000 - prefix: "测试项目" - - field: status - range: wait - - field: grade - range: 3 - - field: parent - range: 41-80{2} - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 1-40{2} - - field: grade2 - postfix: "," - range: 41-80{2} - - field: self - postfix: "," - range: 161-10000 diff --git a/test/data/zentao/projectgrade4.yaml b/test/data/zentao/projectgrade4.yaml deleted file mode 100644 index a872421445..0000000000 --- a/test/data/zentao/projectgrade4.yaml +++ /dev/null @@ -1,30 +0,0 @@ -title: program -author: Zhu Jinyong -version: "1.0" -fields: - - field: id - range: 201-10000 - - field: name - range: 81-10000 - prefix: "测试项目" - - field: status - range: wait - - field: grade - range: 4 - - field: parent - range: 81-120{2} - - field: path - fields: - - field: grade1 - prefix: "," - postfix: "," - range: 1-40{2} - - field: grade2 - postfix: "," - range: 41-80{2} - - field: grade3 - postfix: "," - range: 81-120{2} - - field: self - postfix: "," - range: 201-10000 diff --git a/test/lib/utils.php b/test/lib/utils.php index 8a30f90c81..584f2c0894 100644 --- a/test/lib/utils.php +++ b/test/lib/utils.php @@ -13,6 +13,8 @@ define('RUNTIME_ROOT', dirname(dirname(__FILE__)) . '/runtime/'); define('LIB_ROOT', dirname(dirname(__FILE__)) . '/lib/'); +include LIB_ROOT . 'init.php'; + /** * Get version type of ZenTaoPMS. * @@ -71,34 +73,27 @@ function ztfExtract($dir) */ function zdRun() { + global $config, $dao; + $frameworkRoot = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR; - include $frameworkRoot . 'helper.class.php'; include LIB_ROOT . 'spyc.php'; - $zdRoot = dirname(dirname(__FILE__)) . '/data/'; - $zdPath = RUNTIME_ROOT . 'zd'; + $zdRoot = dirname(dirname(__FILE__)) . '/data/'; + $zdPath = RUNTIME_ROOT . 'zd'; set_time_limit(0); try { - $config = new stdclass(); - $config->db = new stdclass(); - - include dirname(dirname(dirname(__FILE__))) . '/config/config.php'; - $versionType = getVersionType($config->version); $configRoot = $zdRoot . $versionType . '/'; include $configRoot . 'config.php'; + include $configRoot . 'processor.php'; /* Connect to MySQL. */ - $dsn = "mysql:host={$config->db->host}:{$config->db->port};dbname={$config->db->name}"; - $dbh = new PDO($dsn, $config->db->user, $config->db->password); + $dao = new dao(); echo 'MySQL connect success' . PHP_EOL; - $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // 设置报错处理方式。 - $dbh->exec("SET GLOBAL sql_mode = '';"); - $dbh->exec("set names 'utf8'"); - $dbh->beginTransaction(); + $dao->begin(); /* Copy common to tmp. */ $tmpCommonPath = RUNTIME_ROOT . 'tmp/common'; @@ -107,19 +102,38 @@ function zdRun() system("rm {$zdRoot}sql/*"); /* Generate SQL files. */ - $command = "$zdPath -c %s -d $zdRoot%s -n %s -o {$zdRoot}sql/%s.sql -table %s"; - $tables = array(); + $tables = array(); foreach($builder as $key => $info) { - /* Build zendata. */ - $configData = array('fields' => array()); + /* Build ZenData. */ + $tableName = ''; + $files = array(); + if(!empty($info['extends'])) + { + foreach($info['extends'] as $fileKey => $fileName) + { + if(!$tableName) $tableName = $fileName; + $files[] = $zdRoot . $fileName . '.yaml'; + } + } if(!empty($info['data'])) { - foreach($info['data'] as $fileKey => $fileName) - { - if($fileKey == 0) continue; // Skip default file. + if(!$tableName) $tableName = $info['data']; + $files[] = $configRoot . $info['data'] . '.yaml'; + } + $defaultFile = array_shift($files); - $data = Spyc::YAMLLoad($configRoot . $fileName . '.yaml'); + /* Parse files, Generate $configYaml. */ + if(count($files) == 1) // If only one file need to parse, use is direactly. + { + $configYaml = $files[0]; + } + else + { + $configData = array('fields' => array()); + foreach($files as $file) + { + $data = Spyc::YAMLLoad($file); foreach($data['fields'] as $field) { $fieldName = $field['field']; @@ -137,26 +151,25 @@ function zdRun() if(!$fieldExist) $configData['fields'][] = $field; } } + + /* Refresh runtime/tmp/config.yaml. */ + $spyc = new Spyc(); + $spyc->setting_dump_force_quotes = true; + + $content = $spyc->dump($configData); + $yaml = fopen(RUNTIME_ROOT . 'tmp/config.yaml', 'w'); + fwrite($yaml, $content); + fclose($yaml); + + $configYaml = RUNTIME_ROOT . 'tmp/config.yaml'; } - /* Refresh runtime/tmp/config.yaml. */ - $spyc = new Spyc(); - $spyc->setting_dump_force_quotes = true; - - $content = $spyc->dump($configData); - $yaml = fopen(RUNTIME_ROOT . 'tmp/config.yaml', 'w'); - fwrite($yaml, $content); - fclose($yaml); - - /* Create sql files. */ - $defaultName = $info['data'][0]; - $tableName = $config->db->prefix . $defaultName; - - $execYaml = sprintf($command, RUNTIME_ROOT . 'tmp/config.yaml', $defaultName . '.yaml', $info['rows'], $fileName, $tableName); + /* Create SQL files. */ + $tableName = $config->db->prefix . $tableName; + $command = "$zdPath -c %s -d %s -n %s -o {$zdRoot}sql/%s.sql -table %s"; + $execYaml = sprintf($command, $configYaml, $defaultFile, $info['rows'], $fileName, $tableName); system($execYaml); - - echo $execYaml . "\n"; - echo 'Execute: ' . $fileName . PHP_EOL; + // echo $execYaml . "\n"; $tables[$tableName] = $tableName; } @@ -164,7 +177,7 @@ function zdRun() /* Truncate tables. */ foreach($tables as $table) { - $dbh->exec('truncate table ' . $table); + $dao->exec('truncate table ' . $table); } /* Export SQL files to MySQL. */ @@ -178,12 +191,14 @@ function zdRun() $tableName = basename($file, '.sql'); $sql = file_get_contents($sqlDir . $file); - $count = $dbh->exec($sql); + $count = $dao->exec($sql); echo $tableName . ' insert rows ' . $count . PHP_EOL; } - $dbh->commit(); - $dbh = null; + $dao->commit(); + + $processor = new Processor(); + $processor->init(); } catch (PDOException $e) { @@ -209,6 +224,8 @@ Usage: The commands are: init only init data and files + extract extract comment of testcase + api run unit test for api control run unit test for controllers model run unit test for models ui ui testing