From 85b822d1bf4e2bcc51c250221ffa12f5425bb1bd Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 8 Sep 2025 17:58:55 +0800 Subject: [PATCH] + [misc] Add unit tests for instanceModel::getBackupSettings() 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 --- .../test/lib/instance.unittest.class.php | 15 +++++ .../instance/test/model/getbackupsettings.php | 55 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 module/instance/test/model/getbackupsettings.php diff --git a/module/instance/test/lib/instance.unittest.class.php b/module/instance/test/lib/instance.unittest.class.php index 8cb32e5024..78bbd1618d 100644 --- a/module/instance/test/lib/instance.unittest.class.php +++ b/module/instance/test/lib/instance.unittest.class.php @@ -450,4 +450,19 @@ class instanceTest return $result; } + + /** + * Test getBackupSettings method. + * + * @param int $instanceID + * @access public + * @return mixed + */ + public function getBackupSettingsTest(int $instanceID) + { + $result = $this->objectModel->getBackupSettings($instanceID); + if(dao::isError()) return dao::getError(); + + return $result; + } } \ No newline at end of file diff --git a/module/instance/test/model/getbackupsettings.php b/module/instance/test/model/getbackupsettings.php new file mode 100755 index 0000000000..9534e292b7 --- /dev/null +++ b/module/instance/test/model/getbackupsettings.php @@ -0,0 +1,55 @@ +#!/usr/bin/env php +id->range('1-5'); +$instanceTable->name->range('test-instance{5}'); +$instanceTable->autoBackup->range('0{2},1{3}'); +$instanceTable->backupKeepDays->range('1{2},7{2},30'); +$instanceTable->space->range('1{5}'); +$instanceTable->deleted->range('0{5}'); +$instanceTable->gen(5); + +$cronTable = zenData('cron'); +$cronTable->id->range('1-3'); +$cronTable->command->range('moduleName=instance&methodName=cronBackup&instanceID=3,moduleName=instance&methodName=cronBackup&instanceID=4,moduleName=instance&methodName=cronBackup&instanceID=5'); +$cronTable->h->range('1,8,23'); +$cronTable->m->range('0,30,45'); +$cronTable->dom->range('*{3}'); +$cronTable->mon->range('*{3}'); +$cronTable->dow->range('*{3}'); +$cronTable->type->range('zentao{3}'); +$cronTable->status->range('normal{3}'); +$cronTable->gen(3); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$instanceTest = new instanceTest(); + +// 5. 强制要求:必须包含至少5个测试步骤 +r($instanceTest->getBackupSettingsTest(1)) && p('backupTime') && e('01:00'); // 步骤1:正常情况获取备份时间 +r($instanceTest->getBackupSettingsTest(3)) && p('backupTime') && e('01:00'); // 步骤2:有定时任务的实例获取备份时间 +r($instanceTest->getBackupSettingsTest(4)) && p('backupTime') && e('08:30'); // 步骤3:不同时间的定时任务 +r($instanceTest->getBackupSettingsTest(2)) && p('cycleDays') && e('1'); // 步骤4:验证cycleDays固定为1 +r($instanceTest->getBackupSettingsTest(5)) && p('backupTime') && e('23:45'); // 步骤5:另一个时间的定时任务 \ No newline at end of file