From 0f01aceaf0d5433ef08da0f23fc39845ee57ed24 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 12 Sep 2023 10:41:04 +0800 Subject: [PATCH] * testtask: refactor script to test the block method. --- module/testtask/test/model/block.php | 28 ++++++++++++++++++++++--- module/testtask/test/testtask.class.php | 20 ++++++++++++++---- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/module/testtask/test/model/block.php b/module/testtask/test/model/block.php index 833f81db4d..471dc7150d 100755 --- a/module/testtask/test/model/block.php +++ b/module/testtask/test/model/block.php @@ -2,6 +2,9 @@ gen(5); + su('admin'); /** @@ -10,10 +13,29 @@ title=测试 testtaskModel->block(); cid=1 pid=1 - - */ +$uid = uniqid(); + +$task1 = array('id' => 0); +$task2 = array('id' => ''); +$task3 = array('id' => 'id'); +$task4 = array('id' => 3); +$task5 = array('id' => 4); +$task6 = array('id' => 6); +$task8 = array('id' => 1, 'status' => 'blocked', 'uid' => $uid, 'comment' => ''); +$task9 = array('id' => 5, 'status' => 'blocked', 'uid' => $uid, 'comment' => 'comment'); +$task10 = array('id' => 2, 'status' => 'blocked', 'uid' => $uid, 'comment' => 'comment'); + $testtask = new testtaskTest(); -r($testtask->blockTest()) && p() && e(); \ No newline at end of file +r($testtask->blockTest($task1)) && p() && e(0); // 测试单 ID 为 0 返回 false。 +r($testtask->blockTest($task2)) && p() && e(0); // 测试单 ID 为空字符串返回 false。 +r($testtask->blockTest($task3)) && p() && e(0); // 测试单 ID 为字符串返回 false。 +r($testtask->blockTest($task4)) && p() && e(0); // 测试单 ID 对应的测试单状态为 done 返回 false。 +r($testtask->blockTest($task5)) && p() && e(0); // 测试单 ID 对应的测试单状态为 blocked 返回 false。 +r($testtask->blockTest($task6)) && p() && e(0); // 测试单 ID 对应的测试单不存在返回 false。 + +r($testtask->blockTest($task8)) && p('task:id|status;action:objectType|action|comment;history[0]:field|old|new', '|') && e('1|blocked;testtask|blocked|~~;status|wait|blocked'); // 阻塞状态为 wait 的测试单,备注为空,成功后检测测试单信息和日志。 +r($testtask->blockTest($task9)) && p('task:id|status;action:objectType|action|comment;history[0]:field|old|new', '|') && e('5|blocked;testtask|blocked|comment;status|wait|blocked'); // 阻塞状态为 wait 的测试单,备注不为空,成功后检测测试单信息和日志。 +r($testtask->blockTest($task10)) && p('task:id|status;action:objectType|action|comment;history[0]:field|old|new', '|') && e('2|blocked;testtask|blocked|comment;status|doing|blocked'); // 阻塞状态为 doing 的测试单,备注不为空,成功后检测测试单信息和日志。 diff --git a/module/testtask/test/testtask.class.php b/module/testtask/test/testtask.class.php index c03ed44621..4ee5e08552 100644 --- a/module/testtask/test/testtask.class.php +++ b/module/testtask/test/testtask.class.php @@ -92,13 +92,25 @@ class testtaskTest return array('task' => $task, 'action' => $action, 'history' => $history); } - public function blockTest($taskID) + /** + * 测试阻塞一个测试单。 + * Test block a testtask. + * + * param array $task + * access public + * return bool|array + */ + public function blockTest(array $task): bool|array { - $objects = $this->objectModel->block($taskID); - + $result = $this->objectModel->block((object)$task); if(dao::isError()) return dao::getError(); + if(!$result) return $result; - return $objects; + $task = $this->objectModel->fetchByID($task['id']); + $action = $this->objectModel->dao->select('*')->from(TABLE_ACTION)->orderBy('id_desc')->limit(1)->fetch(); + $history = $this->objectModel->dao->select('*')->from(TABLE_HISTORY)->where('action')->eq($action->id)->fetchAll(); + + return array('task' => $task, 'action' => $action, 'history' => $history); } public function activateTest($taskID)