From 4f90bfecb115ea8a1e32f137e32d03c0068bd816 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Thu, 17 Aug 2023 10:13:38 +0800 Subject: [PATCH] * Add comment of bugModel::updateRelatedBug, and modify its unit test. --- module/bug/model.php | 4 ++++ module/bug/test/bug.class.php | 5 +++-- module/bug/test/model/updaterelatedbug.php | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index dd0d81572f..9be29704f2 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1831,6 +1831,8 @@ class bugModel extends model */ public function updateRelatedBug(int $bugID, string $relatedBug, string $oldRelatedBug): bool { + /* 获取需要修改的相关 bug。 */ + /* Get related bugs that need to change. */ $relatedBugs = explode(',', $relatedBug); $oldRelatedBugs = explode(',', $oldRelatedBug); $addedRelatedBugs = array_diff($relatedBugs, $oldRelatedBugs); @@ -1838,6 +1840,8 @@ class bugModel extends model $changedRelatedBugs = array_merge($addedRelatedBugs, $removedRelatedBugs); $changedRelatedBugs = $this->dao->select('id, relatedBug')->from(TABLE_BUG)->where('id')->in(array_filter($changedRelatedBugs))->fetchPairs(); + /* 更新相关 bug。 */ + /* Update the related bug. */ foreach($changedRelatedBugs as $changedBugID => $relatedBugs) { if(in_array($changedBugID, $addedRelatedBugs)) diff --git a/module/bug/test/bug.class.php b/module/bug/test/bug.class.php index 1e8a1941a9..83ce9f11a0 100644 --- a/module/bug/test/bug.class.php +++ b/module/bug/test/bug.class.php @@ -1272,15 +1272,16 @@ class bugTest } /** + * 测试更新相关 bug。 * The test for updatelinkbug function. * - * @param string $bugID + * @param int $bugID * @param string $relatedBug * @param string $oldRelatedBug * @access public * @return array */ - public function updateRelatedBugTest($bugID, $relatedBug, $oldRelatedBug) + public function updateRelatedBugTest(int $bugID, string $relatedBug, string $oldRelatedBug): array|bool { $this->objectModel->updateRelatedBug($bugID, $relatedBug, $oldRelatedBug); diff --git a/module/bug/test/model/updaterelatedbug.php b/module/bug/test/model/updaterelatedbug.php index 43e334d558..2c6aeedf6c 100755 --- a/module/bug/test/model/updaterelatedbug.php +++ b/module/bug/test/model/updaterelatedbug.php @@ -42,10 +42,11 @@ cid=1 initData(); -$bugIDList = array(1, 2, 3); +$bugIDList = array(1, 2, 3, 10001); $bug = new bugTest(); r($bug->updateRelatedBugTest($bugIDList[0], '2', '')) && p('2', ';') && e('1'); //测试关联bug2的关联bug同步更新为1 r($bug->updateRelatedBugTest($bugIDList[0], '3', '2')) && p('2;3', ';') && e('~~;1'); //测试关联bug2的关联bug同步更新为空,bug3的关联bug为1 r($bug->updateRelatedBugTest($bugIDList[0], '2,3', '3')) && p('2') && e('1'); //测试关联bug2的关联bug同步更新为1 -r($bug->updateRelatedBugTest($bugIDList[1], '1,3', '1')) && p('3', ';') && e('1,2'); //测试关联bug3的关联bug同步更新为1,2 \ No newline at end of file +r($bug->updateRelatedBugTest($bugIDList[1], '1,3', '1')) && p('3', ';') && e('1,2'); //测试关联bug3的关联bug同步更新为1,2 +r($bug->updateRelatedBugTest($bugIDList[3], '1', '1')) && p() && e('0'); //测试不存在的关联bug的关联bug同步更新为1