From 44c7188932bf7fb0f20d9ff52c64f54b3d2142e9 Mon Sep 17 00:00:00 2001 From: wangxuepeng Date: Tue, 12 Dec 2023 10:57:29 +0800 Subject: [PATCH] * Code formatter for pivot's unit test. --- module/pivot/model.php | 2 +- module/pivot/test/model/gensheet.php | 19 +++++---- module/pivot/test/model/getbugassign.php | 27 ++++++------ .../pivot/test/model/processfieldsettings.php | 17 +++++--- module/pivot/test/model/processpivot.php | 9 ++-- module/pivot/test/model/replacetablenames.php | 2 +- module/pivot/test/model/setexecutionname.php | 41 +++++++++++++++++++ 7 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 module/pivot/test/model/setexecutionname.php diff --git a/module/pivot/model.php b/module/pivot/model.php index 02e5d3eee0..79fa2a3c68 100644 --- a/module/pivot/model.php +++ b/module/pivot/model.php @@ -607,7 +607,7 @@ class pivotModel extends model * @access public * @return void */ - public function setExecutionName(object &$execution, bool $canViewExecution): void + public function setExecutionName(object $execution, bool $canViewExecution): void { if($execution->multiple) { diff --git a/module/pivot/test/model/gensheet.php b/module/pivot/test/model/gensheet.php index 0187e5c10a..a752537b7a 100644 --- a/module/pivot/test/model/gensheet.php +++ b/module/pivot/test/model/gensheet.php @@ -1,14 +1,6 @@ #!/usr/bin/env php gen(20); -zdTable('product')->config('product')->gen(10); -zdTable('module')->gen(10); -zdTable('case')->gen(10); -zdTable('project')->config('project_gensheet')->gen(20); -zdTable('product')->gen(10); /** title=测试 pivotModel->getBugs(); cid=1 @@ -27,9 +19,18 @@ pid=1 查看id为1001的透视表生成的分组信息是否正确。 >> 一级项目集,项目名称 查看id为1001的透视表生成的标签是否正确。 >> 一级项目集,一级项目集;单位时间交付需求规模数;单位时间交付需求规模数 查看id为1001的透视表生成的列数据是否正确。 >> 项目11,3;项目20,10 - */ +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/pivot.class.php'; + +zdTable('bug')->gen(20); +zdTable('product')->config('product')->gen(10); +zdTable('module')->gen(10); +zdTable('case')->gen(10); +zdTable('project')->config('project_gensheet')->gen(20); +zdTable('product')->gen(10); + global $tester; $pivotTest = new pivotTest(); diff --git a/module/pivot/test/model/getbugassign.php b/module/pivot/test/model/getbugassign.php index e7c6b3835c..e0d11c7c72 100644 --- a/module/pivot/test/model/getbugassign.php +++ b/module/pivot/test/model/getbugassign.php @@ -1,7 +1,19 @@ #!/usr/bin/env php getBugAssign(); +cid=1 +pid=1 + +判断已分配的bug数据获取是否正确。 >> 1 +1.用户有此产品的权限并且此产品存在关联的项目。2。有访问项目的权限。--- 产品名称显示为链接,1.跳向项目页面,2.跳向产品页面。 >> 1 +用户没有访问权限的时候,产品名称显示为原本的名称,并且不可点击。 >> 1 + +*/ + include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/pivot.class.php'; +su('admin'); zdTable('bug')->config('bug_getbugassign')->gen(10); zdTable('product')->gen(10); @@ -10,21 +22,12 @@ zdTable('project')->config('project')->gen(10, false, false); zdTable('projectproduct')->gen(5); zdTable('user')->gen(2); -/** -title=测试 pivotModel->getWorkload(); -cid=1 -pid=1 - -1.用户有此产品的权限并且此产品存在关联的项目。2。有访问项目的权限。--- 产品名称显示为链接,1.跳向项目页面,2.跳向产品页面。 >> 1 -用户没有访问权限的时候,产品名称显示为原本的名称,并且不可点击。 >> 1 - -*/ - -su('admin'); $pivot = new pivotTest(); $result = $pivot->getBugAssign(); +r($result) && p('0:product,assignedTo,total;9:product,assignedTo,total') && e('1,admin,10;10,admin,10'); //判断已分配的bug数据获取是否正确。 + foreach($result as $row) { $productName = $row->productName; @@ -54,4 +57,4 @@ $row4 = $result[9]; $condition3 = $row3->product == 1 && !$row3->isProductNameHtml && strip_tags($row3->productName) == $row3->productName; $condition4 = $row4->product == 10 && !$row4->isProductNameHtml && strip_tags($row4->productName) == $row4->productName; -r($condition3 && $condition4) && p('') && e('1'); //用户没有访问权限的时候,产品名称显示为原本的名称,并且不可点击。 +r($condition3 && $condition4) && p('') && e('1'); //用户没有访问权限的时候,产品名称显示为原本的名称,并且不可点击。 diff --git a/module/pivot/test/model/processfieldsettings.php b/module/pivot/test/model/processfieldsettings.php index 6ac07d36db..3129d57fcc 100644 --- a/module/pivot/test/model/processfieldsettings.php +++ b/module/pivot/test/model/processfieldsettings.php @@ -8,10 +8,11 @@ title=测试 pivotModel->processFieldSettings(); cid=1 pid=1 -field和fieldSettings都为空,不做任何处理 >> 1 -判断是否生成了正确的sql,如果fieldSetting存在,则判定为正确。 >> 1 -sql错误的时候,不做任何处理。 >> 1 -id为1003的透视表,没有project字段,判断是否通过此方法生成了project字段。 >> 1 +field和fieldSettings都为空,不做任何处理。 >> 1 +判断是否生成了正确的sql,如果fieldSetting存在,则判定为正确。 >> 1 +sql错误的时候,不做任何处理。 >> 1 +id为1003的透视表,没有project字段,判断是否通过此方法生成了project配置以及project配置下是否生成了field字段,并且判断配置是否正确。 >> 1 +id为1003的透视表,存在BSA字段,判断更新的BSA配置是否正确。 >> 1 */ @@ -44,4 +45,10 @@ r($pivot3_1 == $pivot3_) && p('') && e(1); //sql错误的时候,不做任 $pivot2 = $pivotList[1]; $pivotTest->processFieldSettings($pivot2); -r(isset($pivot2->fieldSettings->project)) && p('') && e(1); //id为1003的透视表,没有project字段,判断是否通过此方法生成了project字段。 +$project = $pivot2->fieldSettings->project ?? null; +$condition = $project && $project->name == '所属项目' && $project->field == 'project'; +r($condition) && p('') && e(1); //id为1003的透视表,没有project字段,判断是否通过此方法生成了project配置以及project配置下是否生成了field字段,并且判断配置是否正确。 + +$bsa = $pivot2->fieldSettings->BSA ?? null; +$condition2 = $bsa && $bsa->name == 'BSA' && $bsa->field == 'BSA' && $bsa->object == 'project'; +r($condition2) && p('') && e(1); //id为1003的透视表,存在BSA字段,判断更新的BSA配置是否正确。 diff --git a/module/pivot/test/model/processpivot.php b/module/pivot/test/model/processpivot.php index 5b6c827707..a20bd8efe6 100644 --- a/module/pivot/test/model/processpivot.php +++ b/module/pivot/test/model/processpivot.php @@ -30,6 +30,9 @@ r(is_object($pivot->processPivot($pivotList[1], true))) && p('') && e(1); $add = ';;;;;;;;'; $pivotList[2]->sql .= $add; $pivot->processPivot($pivotList[2], true); -r(strpos($pivotList[2]->sql, $add) === false) && p('') && e(1); //测试函数执行以后sql是否被修改 -r(is_array($pivotList[2]->settings)) && p('') && e(1); //测试函数执行以后返回的setting是否是数组 -r($pivotList[2]->used) && p('') && e(1); //测试函数执行以后返回的used是否是true +r(strpos($pivotList[2]->sql, $add) === false) && p('') && e(1); //测试函数执行以后id为1002的透视表sql是否被修改 +r(is_array($pivotList[2]->settings)) && p('') && e(1); //测试函数执行以后id为1002的透视表返回的setting是否是数组 +r($pivotList[2]->used) && p('') && e(1); //测试函数执行以后id为1002的透视表返回的used是否是true + +$pivot->processPivot($pivotList[3], true); +r($pivotList[3]->used) && p('') && e(0); //测试函数执行以后id为1003的透视表返回的used是否是false diff --git a/module/pivot/test/model/replacetablenames.php b/module/pivot/test/model/replacetablenames.php index 0d4855bbb0..d290c35011 100644 --- a/module/pivot/test/model/replacetablenames.php +++ b/module/pivot/test/model/replacetablenames.php @@ -1,7 +1,7 @@ #!/usr/bin/env php getWorkload(); +title=测试 pivotModel->setExecutionName(); cid=1 pid=1 diff --git a/module/pivot/test/model/setexecutionname.php b/module/pivot/test/model/setexecutionname.php new file mode 100644 index 0000000000..5eea4789ac --- /dev/null +++ b/module/pivot/test/model/setexecutionname.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php +setExecutionName(); +cid=1 +pid=1 + +测试当execution的multiple为0时,生成的executionName为空 >> 空 +测试当execution的multiple为1时,生成的executionName为executionName值本身、 >> name1 +测试当execution的multiple为1时,生成的executionName为带了标签的值。 >> 1 +*/ +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/pivot.class.php'; + +$pivot = new pivotTest(); + +$execution1 = new stdclass(); +$execution1->multiple = 0; + +$execution2 = new stdclass(); +$execution2->executionID = 1; +$execution2->multiple = 1; +$execution2->executionName = 'name1'; + +$execution3 = new stdclass(); +$execution3->executionID = 2; +$execution3->multiple = 1; +$execution3->executionName = 'name2'; + +$execution3_ = clone($execution3); + +$executionList = array($execution1, $execution2, $execution3); +$canViewList = array(false, false, true); + +$pivot->setExecutionName($executionList[0], $canViewList[0]); +$pivot->setExecutionName($executionList[1], $canViewList[1]); +$pivot->setExecutionName($executionList[2], $canViewList[2]); + +r($execution1->executionName) && p('') && e('空'); //测试当execution的multiple为0时,生成的executionName为空 +r($execution2->executionName) && p('') && e('name1'); //测试当execution的multiple为1时,生成的executionName为executionName值本身、 +r($execution3->executionName && trim(strip_tags($execution3->executionName)) == trim($execution3_->executionName)) && p('') && e('1'); //测试当execution的multiple为1时,生成的executionName为带了标签的值。