From 8045d80e5aabc33613cc9e01dcfde94736dac846 Mon Sep 17 00:00:00 2001 From: xushenjie Date: Fri, 12 May 2023 07:59:29 +0000 Subject: [PATCH] * Adjust unit test of programplanModel::updateSubStageAttr(). --- .../test/model/updatesubstageattr.php | 31 ++++++------------- module/programplan/test/programplan.class.php | 21 +++++++------ 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/module/programplan/test/model/updatesubstageattr.php b/module/programplan/test/model/updatesubstageattr.php index ce743613b4..d0f995d7ac 100755 --- a/module/programplan/test/model/updatesubstageattr.php +++ b/module/programplan/test/model/updatesubstageattr.php @@ -2,23 +2,12 @@ gen(5); su('admin'); -$execution = zdTable('project'); -$execution->id->range('1-5'); -$execution->name->range('瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b'); -$execution->type->range('project,stage{4}'); -$execution->project->range('0,1{4}'); -$execution->parent->range('0,1,2,3,1'); -$execution->path->range("`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`"); -$execution->status->range('doing,doing,doing,closed,suspended'); -$execution->attribute->range(" ,mix,request,request,review"); -$execution->openedBy->range('admin,user1'); -$execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD'); -$execution->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); -$execution->realBegan->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); -$execution->gen(5); +function initData() +{ + zdTable('project')->config('project')->gen(5); +} /** @@ -26,12 +15,12 @@ title=测试programplanModel->updateSubStageAttr(); cid=1 pid=1 -测试更改id为3的阶段为综合 >> request -测试更改id为2的阶段为设计 >> design - */ -$plan = new programplanTest(); +initData(); -r($plan->updateSubStageAttrTest(3, 'mix', 4)) && p('') && e('request'); // 测试更改id为3的阶段为综合 -r($plan->updateSubStageAttrTest(2, 'design', 3)) && p('') && e('design'); // 测试更改id为2的阶段为设计 +$plan = new programplanTest(); +r($plan->updateSubStageAttrTest(1, 'mix')) && p() && e('1'); // 测试更改 id 为 3 存在子阶段的阶段,attribute 更新值为 mix ,结果为 1 +r($plan->updateSubStageAttrTest(5, 'design')) && p() && e(1); // 测试更改 id 为 5 无子阶段的阶段,更新 attribute 值为 design ,结果为 1 +r($plan->updateSubStageAttrTest(2, 'design')) && p() && e('design'); // 测试更改 id 为 2 存在子阶段的阶段,更新 attribute 值为 design ,结果为 design +r($plan->updateSubStageAttrTest(3, 'design')) && p() && e('design'); // 测试更改 id 为 3 存在子阶段,子阶段下也存在子阶段,更新 attribute 值为 design ,结果为 design diff --git a/module/programplan/test/programplan.class.php b/module/programplan/test/programplan.class.php index ebaefb1ea0..f3363360f8 100644 --- a/module/programplan/test/programplan.class.php +++ b/module/programplan/test/programplan.class.php @@ -409,25 +409,26 @@ class programplanTest } /** + * 测试更新子阶段的属性。 * Test update sub-stage attribute. * * @param int $planID * @param string $attribute - * @param int $subStageID * @access public - * @return string + * @return bool|string */ - public function updateSubStageAttrTest($planID, $attribute, $subStageID) + public function updateSubStageAttrTest(int $planID, string $attribute): bool|string { + $this->objectModel->updateSubStageAttr($planID, $attribute); + if(dao::isError()) return false; + global $tester; + $subStage = $tester->dao->select('attribute')->from(TABLE_PROJECT)->where('parent')->eq($planID)->fetch(); + if(!$subStage) return true; - $objects = $this->objectModel->updateSubStageAttr($planID, $attribute); - - if(dao::isError()) return dao::getError(); - - $attribute = $tester->dao->select('attribute')->from(TABLE_EXECUTION)->where('id')->eq($subStageID)->fetch('attribute'); - - return $attribute; + /* Handles the result when the unit test assertion is an empty string. */ + $attribute = $subStage->attribute == '' ? 'empty string' : $subStage->attribute; + return $attribute == 'mix' ? true : $attribute; } /**