From 521e8331aabdd9d2db22ea0f2e80dbcf8ce2e1dd Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 10 Sep 2025 14:16:55 +0800 Subject: [PATCH] + [misc] Add unit tests for tutorialModel::getGradePairs() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/tutorial/model.php | 1 + .../test/lib/tutorial.unittest.class.php | 16 ++++++++ module/tutorial/test/model/getgradepairs.php | 41 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100755 module/tutorial/test/model/getgradepairs.php diff --git a/module/tutorial/model.php b/module/tutorial/model.php index 368afc04cf..380da0b2f3 100644 --- a/module/tutorial/model.php +++ b/module/tutorial/model.php @@ -492,6 +492,7 @@ class tutorialModel extends model if($type == 'story') return array(1 => 'SR'); if($type == 'requirement') return array(1 => 'UR'); if($type == 'epic') return array(1 => 'BR'); + return array(); } /** diff --git a/module/tutorial/test/lib/tutorial.unittest.class.php b/module/tutorial/test/lib/tutorial.unittest.class.php index 6d4265b9be..6cb010e9f8 100644 --- a/module/tutorial/test/lib/tutorial.unittest.class.php +++ b/module/tutorial/test/lib/tutorial.unittest.class.php @@ -360,4 +360,20 @@ class tutorialTest return $result; } + + /** + * 测试获取需求层级键值对。 + * Test get story grade pairs. + * + * @param string $type + * @access public + * @return array + */ + public function getGradePairsTest(string $type): array + { + $result = $this->objectModel->getGradePairs($type); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/tutorial/test/model/getgradepairs.php b/module/tutorial/test/model/getgradepairs.php new file mode 100755 index 0000000000..bc9ed31fce --- /dev/null +++ b/module/tutorial/test/model/getgradepairs.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php +type->range('story,requirement,epic'); +$table->grade->range(1); +$table->name->range('SR,UR,BR'); +$table->status->range('enable'); +$table->gen(3); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$tutorialTest = new tutorialTest(); + +// 5. 🔴 强制要求:必须包含至少5个测试步骤 +r($tutorialTest->getGradePairsTest('story')) && p('1') && e('SR'); // 步骤1:测试story类型 +r($tutorialTest->getGradePairsTest('requirement')) && p('1') && e('UR'); // 步骤2:测试requirement类型 +r($tutorialTest->getGradePairsTest('epic')) && p('1') && e('BR'); // 步骤3:测试epic类型 +r($tutorialTest->getGradePairsTest('')) && p() && e('0'); // 步骤4:测试空字符串类型 +r($tutorialTest->getGradePairsTest('invalid')) && p() && e('0'); // 步骤5:测试无效类型 \ No newline at end of file