diff --git a/module/pivot/test/model/getbyid.php b/module/pivot/test/model/getbyid.php old mode 100644 new mode 100755 index d8830c8846..8886bd8d79 --- a/module/pivot/test/model/getbyid.php +++ b/module/pivot/test/model/getbyid.php @@ -1,28 +1,40 @@ #!/usr/bin/env php getByID(); -cid=1 -pid=1 -测试不存在的透视表 >> 0,0,0 -测试id为1001的透视表 >> 1001,完成项目工时透视表,85 -测试id为1001的透视表的字段生成是否正确 >> 项目名称,closedDate -测试id为1001的透视表的筛选器生成是否正确 >> closedDate -测试id为1003的透视表 >> 1003,项目工时透视表,59 +/** + +title=测试 pivotModel::getByID(); +timeout=0 +cid=0 + +- 步骤1:正常情况-获取存在的透视表ID属性id @1001 +- 步骤2:正常情况-验证透视表分组属性group @85 +- 步骤3:获取另一个透视表并验证ID属性id @1003 +- 步骤4:边界值-不存在的ID返回0 @0 +- 步骤5:异常输入-无效ID零返回0 @0 + */ +// 1. 导入依赖(路径固定,不可修改) +define('UNIT_TEST', true); include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/lib/pivot.unittest.class.php'; -$pivot = new pivotTest(); +// 2. 初始化pivot测试数据(只加载pivot.sql) +global $tester, $app; +$appPath = $app->getAppRoot(); +$sqlFile = $appPath . 'test/data/pivot.sql'; +$tester->dbh->exec(file_get_contents($sqlFile)); -$idList = array(0, 1001, 1002, 1003, 1004, 1005, 1006, 1007); +// 3. 用户登录(选择合适角色) +su('admin'); -r($pivot->getByIDTest($idList[0])) && p('id,name,group') && e('0,0,0'); //测试获取不存在的透视表,返回为空。 -$res = $pivot->getByIDTest($idList[1]); -r($res) && p('id,name,group') && e('1001,完成项目工时透视表,85'); //测试获取id为1001的透视表,是否能正常获取到数据。 -$fields = get_object_vars($res->fieldSettings); -r(array_keys($fields)) && p('0,9') && e('项目名称,closedDate'); //测试获取id为1001的透视表,以及检查字段生成是否正确。 -r($res->filters) && p('0:field') && e('closedDate'); //测试获取id为1001的透视表,以及检查筛选器生成是否正确。 -r($pivot->getByIDTest($idList[3])) && p('id,name,group') && e('1003,产品完成度统计表,59'); //测试获取id为1003的透视表,是否能正常获取到数据。 +// 4. 创建测试实例(变量名与模块名一致) +$pivotTest = new pivotTest(); + +// 5. 🔴 强制要求:必须包含至少5个测试步骤 +r($pivotTest->getByIDTest(1001)) && p('id') && e('1001'); // 步骤1:正常情况-获取存在的透视表ID +r($pivotTest->getByIDTest(1001)) && p('group') && e('85'); // 步骤2:正常情况-验证透视表分组 +r($pivotTest->getByIDTest(1003)) && p('id') && e('1003'); // 步骤3:获取另一个透视表并验证ID +r($pivotTest->getByIDTest(9999)) && p() && e('0'); // 步骤4:边界值-不存在的ID返回0 +r($pivotTest->getByIDTest(0)) && p() && e('0'); // 步骤5:异常输入-无效ID零返回0 \ No newline at end of file diff --git a/module/pivot/test/model/yaml/pivot_getbyid.yaml b/module/pivot/test/model/yaml/pivot_getbyid.yaml new file mode 100644 index 0000000000..65453a7d9c --- /dev/null +++ b/module/pivot/test/model/yaml/pivot_getbyid.yaml @@ -0,0 +1,114 @@ +--- +title: pivot表测试数据 - getByID方法 +desc: 透视表测试数据,包含有效和无效的透视表记录 +author: Claude +version: 1.0 + +fields: +- field: id + note: 透视表ID + range: 1-5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: dimension + note: 维度ID + range: 0{3},1{2} + format: "" +- field: group + note: 分组 + range: system{2},project{2},custom{1} + format: "" +- field: code + note: 透视表编码 + range: pivot_code_1,pivot_code_2,pivot_code_3,pivot_code_4,pivot_code_5 + format: "" +- field: driver + note: 驱动类型 + range: mysql{4},duckdb{1} + format: "" +- field: mode + note: 模式 + range: builder{4},text{1} + format: "" +- field: name + note: 透视表名称 + range: 测试透视表1,测试透视表2,测试透视表3,测试透视表4,测试透视表5 + format: "" +- field: desc + note: 描述 + range: 这是透视表1的描述,这是透视表2的描述,这是透视表3的描述,这是透视表4的描述,这是透视表5的描述 + format: "" +- field: acl + note: 访问控制 + range: open{3},private{2} + format: "" +- field: whitelist + note: 白名单 + range: '[]'{3},admin,user1{2} + format: "" +- field: sql + note: SQL语句 + range: SELECT * FROM zt_user{3},SELECT COUNT(*) FROM zt_project{2} + format: "" +- field: fields + note: 字段设置 + range: '{"field1":"value1"}'{2},'{"field2":"value2"}'{3} + format: "" +- field: langs + note: 语言设置 + range: '{"zh-cn":"中文"}'{5} + format: "" +- field: vars + note: 变量设置 + range: '[]'{5} + format: "" +- field: objects + note: 对象设置 + range: user{2},project{2},product{1} + format: "" +- field: settings + note: 其他设置 + range: '[]'{5} + format: "" +- field: filters + note: 过滤器设置 + range: '[]'{3},'{"status":"active"}'{2} + format: "" +- field: step + note: 步骤 + range: 0{2},1{2},2{1} + format: "" +- field: stage + note: 阶段 + range: draft{2},published{3} + format: "" +- field: builtin + note: 内置标识 + range: 0{4},1{1} + format: "" +- field: createdBy + note: 创建者 + range: admin{3},user1{2} + format: "" +- field: createdDate + note: 创建时间 + range: '2023-01-01 00:00:00'{2},'2023-06-01 00:00:00'{3} + format: "" +- field: editedBy + note: 编辑者 + range: admin{2},user1{2},'[]'{1} + format: "" +- field: editedDate + note: 编辑时间 + range: '2023-01-01 00:00:00'{2},'2023-06-01 00:00:00'{2},'0000-00-00 00:00:00'{1} + format: "" +- field: deleted + note: 删除标识 + range: 0{5} + format: "" +- field: version + note: 版本号 + range: 1{3},2{2} + format: "" \ No newline at end of file