+ [misc] Add unit tests for backupZen::backupSQL() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -71,4 +71,36 @@ class backupZenTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test backupSQL method.
|
||||
*
|
||||
* @param string $fileName 文件名
|
||||
* @param string $reload 重载参数
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function backupSQLTest(string $fileName = '', string $reload = 'no')
|
||||
{
|
||||
$result = $this->invokeArgs('backupSQL', [$fileName, $reload]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test backupSQL method with nosafe setting.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function backupSQLTestWithNosafe()
|
||||
{
|
||||
global $config;
|
||||
$oldSetting = $config->backup->setting;
|
||||
$config->backup->setting = 'nosafe';
|
||||
$result = $this->invokeArgs('backupSQL', ['test_nosafe_' . time()]);
|
||||
$config->backup->setting = $oldSetting;
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 backupZen::backupSQL();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:正常备份SQL文件属性result @success
|
||||
- 步骤2:reload=yes参数测试属性result @success
|
||||
- 步骤3:reload=no参数测试属性result @success
|
||||
- 步骤4:nosafe配置测试属性result @success
|
||||
- 步骤5:日期格式文件名测试属性result @success
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zen.class.php';
|
||||
|
||||
// 2. 用户登录
|
||||
su('admin');
|
||||
|
||||
// 3. 创建测试实例
|
||||
$backupTest = new backupZenTest();
|
||||
|
||||
// 4. 测试步骤
|
||||
r($backupTest->backupSQLTest('test_sql_' . time())) && p('result') && e('success'); // 步骤1:正常备份SQL文件
|
||||
r($backupTest->backupSQLTest('test_sql_yes_' . time(), 'yes')) && p('result') && e('success'); // 步骤2:reload=yes参数测试
|
||||
r($backupTest->backupSQLTest('test_sql_no_' . time(), 'no')) && p('result') && e('success'); // 步骤3:reload=no参数测试
|
||||
r($backupTest->backupSQLTestWithNosafe()) && p('result') && e('success'); // 步骤4:nosafe配置测试
|
||||
r($backupTest->backupSQLTest('backup_sql_' . date('YmdHis'))) && p('result') && e('success'); // 步骤5:日期格式文件名测试
|
||||
Reference in New Issue
Block a user