Files
EasySoft-ZenTaoPMS/module/ai/test/model/testmodelconnection.php
T
2025-09-15 15:06:07 +08:00

50 lines
1.9 KiB
PHP
Executable File
Raw 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=测试 aiModel::testModelConnection();
timeout=0
cid=0
- 步骤1:有效模型ID,测试连接 @0
- 步骤2:不存在模型ID @0
- 步骤3:无效模型ID0 @0
- 步骤4:负数模型ID @0
- 步骤5:字符串模型ID @0
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/ai.unittest.class.php';
// 2. zendata数据准备(根据需要配置)
$table = zenData('ai_model');
$table->id->range('1-3');
$table->type->range('openai-gpt4, ernie, claude');
$table->vendor->range('openai, baidu, anthropic');
$table->credentials->range('{"key":"test-key","endpoint":"https://api.test.com"}');
$table->name->range('TestModel1, TestModel2, TestModel3');
$table->desc->range('Test Model Description');
$table->createdBy->range('admin');
$table->createdDate->range('`2024-01-01 00:00:00`');
$table->editedBy->range('admin');
$table->editedDate->range('`2024-01-01 00:00:00`');
$table->enabled->range('1');
$table->deleted->range('0');
$table->gen(3);
// 3. 用户登录(选择合适角色)
su('admin');
// 4. 创建测试实例(变量名与模块名一致)
$aiTest = new aiTest();
// 5. 强制要求:必须包含至少5个测试步骤
// 注意:由于testModelConnection会调用真实API,在测试环境中会失败,但这是正常的行为
r($aiTest->testModelConnectionTest(1)) && p('', '/0$/') && e('0'); // 步骤1:有效模型ID,测试连接
r($aiTest->testModelConnectionTest(999)) && p('', '/0$/') && e('0'); // 步骤2:不存在模型ID
r($aiTest->testModelConnectionTest(0)) && p('', '/0$/') && e('0'); // 步骤3:无效模型ID0
r($aiTest->testModelConnectionTest(-1)) && p('', '/0$/') && e('0'); // 步骤4:负数模型ID
r($aiTest->testModelConnectionTest('abc')) && p('', '/0$/') && e('0'); // 步骤5:字符串模型ID