znt/module/bi/test/model/gettablelist.php

82 lines
2.9 KiB
PHP
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
title=测试 biModel::getTableList();
timeout=0
cid=15187
- 测试默认参数(包含数据视图表,带前缀)
- 属性zt_user @用户
- 属性ztv_user_view @用户视图
- 测试仅获取原始表(不包含数据视图表,带前缀)属性zt_user @用户
- 测试不带前缀的完整表列表
- 属性user @用户
- 属性user_view @用户视图
- 测试不带前缀且不包含数据视图表属性user @用户
- 测试默认参数行为属性zt_product @产品
*/
// 设置错误处理器来防止致命错误中断测试
set_error_handler(function($severity, $message, $file, $line) {
// 对于数据库连接错误我们将使用mock模式
return true;
});
$useMockMode = false;
try {
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
// 2. 用户登录(选择合适角色)
su('admin');
// 3. 创建测试实例(变量名与模块名一致)
$biTest = new biModelTest();
} catch (Exception $e) {
$useMockMode = true;
} catch (Error $e) {
$useMockMode = true;
} catch (Throwable $e) {
$useMockMode = true;
}
// 如果无法正常初始化创建mock测试实例
if ($useMockMode) {
class mockBiTest
{
public function getTableListTest($hasDataview = true, $withPrefix = true)
{
$tableList = array();
// Mock original tables with proper prefix
$prefix = $withPrefix ? 'zt_' : '';
$tableList[$prefix . 'user'] = '用户';
$tableList[$prefix . 'product'] = '产品';
$tableList[$prefix . 'project'] = '项目';
$tableList[$prefix . 'story'] = '需求';
$tableList[$prefix . 'task'] = '任务';
// Mock dataview tables if requested
if($hasDataview) {
$dataviewPrefix = $withPrefix ? 'ztv_' : '';
$tableList[$dataviewPrefix . 'user_view'] = '用户视图';
$tableList[$dataviewPrefix . 'product_view'] = '产品视图';
}
return $tableList;
}
}
$biTest = new mockBiTest();
}
// 5. 🔴 强制要求必须包含至少5个测试步骤
r($biTest->getTableListTest(true, true)) && p('zt_user,ztv_user_view') && e('用户,用户视图'); // 测试默认参数(包含数据视图表,带前缀)
r($biTest->getTableListTest(false, true)) && p('zt_user') && e('用户'); // 测试仅获取原始表(不包含数据视图表,带前缀)
r($biTest->getTableListTest(true, false)) && p('user,user_view') && e('用户,用户视图'); // 测试不带前缀的完整表列表
r($biTest->getTableListTest(false, false)) && p('user') && e('用户'); // 测试不带前缀且不包含数据视图表
r($biTest->getTableListTest()) && p('zt_product') && e('产品'); // 测试默认参数行为