+ [misc] Add unit tests for apiModel::createDemoLib() 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:09 +08:00
co-authored by Claude
parent 05a9575a6f
commit ba1e89cbb8
2 changed files with 60 additions and 0 deletions
@@ -297,4 +297,32 @@ class apiTest
return $objects;
}
/**
* Test createDemoLib method.
*
* @param string $name
* @param string $baseUrl
* @param string $currentAccount
* @access public
* @return object|false
*/
public function createDemoLibTest($name, $baseUrl, $currentAccount)
{
global $tester;
$reflection = new ReflectionClass($this->objectModel);
$method = $reflection->getMethod('createDemoLib');
$method->setAccessible(true);
$libID = $method->invoke($this->objectModel, $name, $baseUrl, $currentAccount);
if(dao::isError()) return dao::getError();
$lib = $tester->dao->select('*')->from(TABLE_DOCLIB)->where('id')->eq($libID)->fetch();
$tester->dao->delete()->from(TABLE_DOCLIB)->where('id')->eq($libID)->exec();
return $lib;
}
}
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env php
<?php
/**
title=测试 apiModel::createDemoLib();
timeout=0
cid=0
- 执行apiTest模块的createDemoLibTest方法,参数是'API Demo Library', 'https://api.demo.com', 'admin' 属性name @API Demo Library
- 执行apiTest模块的createDemoLibTest方法,参数是'API Demo Library', 'https://api.demo.com', 'admin' 属性type @api
- 执行apiTest模块的createDemoLibTest方法,参数是'API Demo Library', 'https://api.demo.com', 'admin' 属性baseUrl @https://api.demo.com
- 执行apiTest模块的createDemoLibTest方法,参数是'API Demo Library', 'https://api.demo.com', 'admin' 属性acl @open
- 执行apiTest模块的createDemoLibTest方法,参数是'Test Library', '', 'admin' 属性baseUrl @~~
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/api.unittest.class.php';
zenData('doclib');
zenData('user');
su('admin');
$apiTest = new apiTest();
r($apiTest->createDemoLibTest('API Demo Library', 'https://api.demo.com', 'admin')) && p('name') && e('API Demo Library');
r($apiTest->createDemoLibTest('API Demo Library', 'https://api.demo.com', 'admin')) && p('type') && e('api');
r($apiTest->createDemoLibTest('API Demo Library', 'https://api.demo.com', 'admin')) && p('baseUrl') && e('https://api.demo.com');
r($apiTest->createDemoLibTest('API Demo Library', 'https://api.demo.com', 'admin')) && p('acl') && e('open');
r($apiTest->createDemoLibTest('Test Library', '', 'admin')) && p('baseUrl') && e('~~');