znt/module/api/test/model/getapistructspecbydata.php

83 lines
3 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=测试 apiModel::getApiStructSpecByData();
timeout=0
cid=15105
- 执行apiTest模块的getApiStructSpecByDataTest方法参数是$fullData
- 属性name @TestStruct
- 属性type @object
- 属性desc @Test description
- 属性version @2
- 属性attribute @{"field1": "string"}
- 属性addedBy @testuser
- 属性addedDate @2024-01-01 12:00:00
- 执行apiTest模块的getApiStructSpecByDataTest方法参数是$minData 属性name @MinimalStruct
- 执行apiTest模块的getApiStructSpecByDataTest方法参数是$emptyFieldsData 属性name @EmptyFieldsStruct
- 执行apiTest模块的getApiStructSpecByDataTest方法参数是$missingOptionalData
- 属性name @MissingOptionalStruct
- 属性type @array
- 属性desc @Missing optional fields
- 执行apiTest模块的getApiStructSpecByDataTest方法参数是$zeroVersionData
- 属性name @ZeroVersionStruct
- 属性type @string
- 属性desc @Version zero test
- 属性version @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
su('admin');
$apiTest = new apiModelTest();
// 测试步骤1正常完整数据输入
$fullData = new stdclass();
$fullData->name = 'TestStruct';
$fullData->type = 'object';
$fullData->desc = 'Test description';
$fullData->version = 2;
$fullData->attribute = '{"field1": "string"}';
$fullData->addedBy = 'testuser';
$fullData->addedDate = '2024-01-01 12:00:00';
r($apiTest->getApiStructSpecByDataTest($fullData)) && p('name,type,desc,version,attribute,addedBy,addedDate') && e('TestStruct,object,Test description,2,{"field1": "string"},testuser,2024-01-01 12:00:00');
// 测试步骤2最小必需字段数据输入
$minData = new stdclass();
$minData->name = 'MinimalStruct';
r($apiTest->getApiStructSpecByDataTest($minData)) && p('name') && e('MinimalStruct');
// 测试步骤3部分字段为空值的数据输入
$emptyFieldsData = new stdclass();
$emptyFieldsData->name = 'EmptyFieldsStruct';
$emptyFieldsData->type = '';
$emptyFieldsData->desc = '';
$emptyFieldsData->version = '';
$emptyFieldsData->attribute = '';
r($apiTest->getApiStructSpecByDataTest($emptyFieldsData)) && p('name') && e('EmptyFieldsStruct');
// 测试步骤4缺失可选字段的数据输入
$missingOptionalData = new stdclass();
$missingOptionalData->name = 'MissingOptionalStruct';
$missingOptionalData->type = 'array';
$missingOptionalData->desc = 'Missing optional fields';
r($apiTest->getApiStructSpecByDataTest($missingOptionalData)) && p('name,type,desc') && e('MissingOptionalStruct,array,Missing optional fields');
// 测试步骤5version为0的边界值测试
$zeroVersionData = new stdclass();
$zeroVersionData->name = 'ZeroVersionStruct';
$zeroVersionData->type = 'string';
$zeroVersionData->desc = 'Version zero test';
$zeroVersionData->version = 0;
$zeroVersionData->attribute = '{"test": "value"}';
r($apiTest->getApiStructSpecByDataTest($zeroVersionData)) && p('name,type,desc,version') && e('ZeroVersionStruct,string,Version zero test,1');