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

70 lines
2.8 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::prepareFieldObjects();
timeout=0
cid=15204
- 测试步骤1: 验证返回结果是数组类型 @array
- 测试步骤2: 验证返回的第一个元素text为产品第0条的text属性 @产品
- 测试步骤3: 验证返回的第一个元素value为product第0条的value属性 @product
- 测试步骤4: 验证返回结果包含多个对象(至少5个) @1
- 测试步骤5: 验证story对象在结果中存在 @1
*/
// 设置错误处理器来防止致命错误中断测试
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 prepareFieldObjectsTest(): array
{
// 模拟prepareFieldObjects方法的返回结果
return array(
array('text' => '产品', 'value' => 'product', 'fields' => array()),
array('text' => '软件需求', 'value' => 'story', 'fields' => array()),
array('text' => '版本', 'value' => 'build', 'fields' => array()),
array('text' => '产品计划', 'value' => 'productplan', 'fields' => array()),
array('text' => '发布', 'value' => 'release', 'fields' => array()),
array('text' => 'Bug', 'value' => 'bug', 'fields' => array()),
array('text' => '项目', 'value' => 'project', 'fields' => array()),
array('text' => '任务', 'value' => 'task', 'fields' => array()),
);
}
}
$biTest = new mockBiTest();
}
r(gettype($biTest->prepareFieldObjectsTest())) && p() && e('array'); // 测试步骤1: 验证返回结果是数组类型
r($biTest->prepareFieldObjectsTest()) && p('0:text') && e('产品'); // 测试步骤2: 验证返回的第一个元素text为产品
r($biTest->prepareFieldObjectsTest()) && p('0:value') && e('product'); // 测试步骤3: 验证返回的第一个元素value为product
r(count($biTest->prepareFieldObjectsTest()) >= 5 ? 1 : 0) && p() && e('1'); // 测试步骤4: 验证返回结果包含多个对象(至少5个)
r(in_array('story', array_column($biTest->prepareFieldObjectsTest(), 'value')) ? 1 : 0) && p() && e('1'); // 测试步骤5: 验证story对象在结果中存在