+ [misc] Add unit tests for aiModel::getPrompts() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:08 +08:00
co-authored by Claude
parent 365b45b42b
commit 10d4a762b1
3 changed files with 163 additions and 0 deletions
+18
View File
@@ -915,4 +915,22 @@ class aiTest
return $result;
}
/**
* Test getPrompts method.
*
* @param string $module
* @param string $status
* @param string $order
* @param object $pager
* @access public
* @return mixed
*/
public function getPromptsTest($module = '', $status = '', $order = 'id_desc', $pager = null)
{
$result = $this->objectModel->getPrompts($module, $status, $order, $pager);
if(dao::isError()) return dao::getError();
return $result;
}
}
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env php
<?php
/**
title=测试 aiModel::getPrompts();
timeout=0
cid=0
- 步骤1:获取所有提示词,应返回10条记录 @10
- 步骤2:按story模块过滤,应返回3条记录 @3
- 步骤3:按active状态过滤,应返回6条记录 @6
- 步骤4:组合过滤,应返回符合条件的记录 @3
- 步骤5:按名称排序,检查第一条记录的名称属性name @Bug润色
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/ai.unittest.class.php';
$table = zenData('ai_prompt');
$table->id->range('1-10');
$table->name->range('需求润色,一键拆用例,任务润色,需求转任务,Bug润色,文档润色,Bug转需求,拆分一个子计划,测试提示词1,测试提示词2');
$table->desc->range('测试描述内容{10}');
$table->model->range('0,1,2,3');
$table->module->range('story{3},task{2},bug{2},doc{1},productplan{2}');
$table->source->range(',story.title,story.spec,,task.name,task.desc,,bug.title,bug.steps,');
$table->targetForm->range('story.change,task.edit,bug.edit,doc.edit,story.create');
$table->purpose->range('测试目的内容{10}');
$table->elaboration->range('测试详细说明内容{10}');
$table->role->range('测试角色描述{10}');
$table->characterization->range('测试角色特征{10}');
$table->createdBy->range('admin,system,user1,user2');
$table->createdDate->range('`2023-08-10 10:00:00`,`2023-08-11 11:00:00`,`2023-08-12 12:00:00`');
$table->status->range('active{6},draft{4}');
$table->deleted->range('0');
$table->gen(10);
su('admin');
$aiTest = new aiTest();
r(count($aiTest->getPromptsTest())) && p() && e('10'); // 步骤1:获取所有提示词,应返回10条记录
r(count($aiTest->getPromptsTest('story'))) && p() && e('3'); // 步骤2:按story模块过滤,应返回3条记录
r(count($aiTest->getPromptsTest('', 'active'))) && p() && e('6'); // 步骤3:按active状态过滤,应返回6条记录
r(count($aiTest->getPromptsTest('story', 'active'))) && p() && e('3'); // 步骤4:组合过滤,应返回符合条件的记录
r(current($aiTest->getPromptsTest('', '', 'name_asc'))) && p('name') && e('Bug润色'); // 步骤5:按名称排序,检查第一条记录的名称
@@ -0,0 +1,98 @@
---
title: AI提示词数据定义
desc: 用于测试getPrompts方法的测试数据
author: Claude Code
version: 1.0
fields:
- field: id
note: 提示词ID
range: 1-10
prefix: ""
postfix: ""
loop: 0
format: ""
- field: name
note: 提示词名称
range: 需求润色,一键拆用例,任务润色,需求转任务,Bug润色{2},文档润色,Bug转需求,拆分一个子计划{2}
prefix: ""
postfix: ""
- field: desc
note: 提示词描述
range: [测试描述内容]{8}
prefix: ""
postfix: ""
- field: model
note: 模型ID
range: 0,1,2,3
prefix: ""
postfix: ""
- field: module
note: 所属模块
range: story{3},task{2},bug{2},doc{1},productplan{2}
prefix: ""
postfix: ""
- field: source
note: 数据源
range: ',story.title,story.spec,story.verify,',',task.name,task.desc,task.pri,',',bug.title,bug.steps,'
prefix: ""
postfix: ""
- field: targetForm
note: 目标表单
range: story.change,task.edit,bug.edit,doc.edit,story.create
prefix: ""
postfix: ""
- field: purpose
note: 目的
range: [测试目的内容]{10}
prefix: ""
postfix: ""
- field: elaboration
note: 详细说明
range: [测试详细说明内容]{10}
prefix: ""
postfix: ""
- field: role
note: 角色描述
range: [测试角色描述]{10}
prefix: ""
postfix: ""
- field: characterization
note: 角色特征
range: [测试角色特征]{10}
prefix: ""
postfix: ""
- field: createdBy
note: 创建者
range: admin,system,user1,user2
prefix: ""
postfix: ""
- field: createdDate
note: 创建时间
range: 2023-08-10 10:00:00,2023-08-11 11:00:00,2023-08-12 12:00:00
prefix: ""
postfix: ""
- field: status
note: 状态
range: active{6},inactive{4}
prefix: ""
postfix: ""
- field: deleted
note: 是否删除
range: 0
prefix: ""
postfix: ""