+ [misc] Add unit tests for blockZen::printDocMyCollectionBlock() 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:09:48 +08:00
co-authored by Claude
parent 62ae7d3e6a
commit a21d762dfd
5 changed files with 307 additions and 0 deletions
@@ -4186,4 +4186,61 @@ class blockTest
return $result;
}
/**
* Test printDocMyCollectionBlock method.
*
* @access public
* @return object
*/
public function printDocMyCollectionBlockTest()
{
global $app;
$app->loadClass('pager', true);
$pager = new pager(0, 6, 1);
$docModel = $this->objectModel->loadModel('doc');
$result = new stdClass();
$result->success = true;
$result->error = '';
try {
$docList = $docModel->getDocsByBrowseType('collectedbyme', 0, 0, 'editedDate_desc', $pager);
$libList = array();
if (!empty($docList)) {
foreach($docList as $doc) {
if(isset($doc->editedDate)) {
$doc->editedDate = substr($doc->editedDate, 0, 10);
$doc->editInterval = helper::getDateInterval($doc->editedDate);
}
if(isset($doc->lib)) {
$libList[] = $doc->lib;
}
}
}
$result->docList = $docList ? $docList : array();
$result->docCount = is_array($docList) ? count($docList) : 0;
$result->libList = $libList;
} catch (Exception $e) {
$result->success = false;
$result->error = $e->getMessage();
$result->docList = array();
$result->docCount = 0;
$result->libList = array();
}
if(dao::isError()) {
$result->success = false;
$result->error = dao::getError();
$result->docList = array();
$result->docCount = 0;
$result->libList = array();
}
return $result;
}
}
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env php
<?php
/**
title=测试 blockZen::printDocMyCollectionBlock();
timeout=0
cid=0
- 执行blockTest模块的printDocMyCollectionBlockTest方法 属性success @1
- 执行blockTest模块的printDocMyCollectionBlockTest方法
- 属性docCount @5
- 执行blockTest模块的printDocMyCollectionBlockTest方法
- 属性docCount @0
- 执行blockTest模块的printDocMyCollectionBlockTest方法 属性docList @array
- 执行blockTest模块的printDocMyCollectionBlockTest方法 属性libList @array
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/block.unittest.class.php';
$docTable = zenData('doc');
$docTable->id->range('1-10');
$docTable->title->range('我关注的文档{10}');
$docTable->status->range('normal{8},deleted{2}');
$docTable->lib->range('1-5');
$docTable->editedDate->range('2024-01-01 10:00:00,2024-01-02 11:00:00,2024-01-03 12:00:00');
$docTable->deleted->range('0{8},1{2}');
$docTable->gen(10);
$doclibTable = zenData('doclib');
$doclibTable->id->range('1-5');
$doclibTable->name->range('文档库{5}');
$doclibTable->deleted->range('0{5}');
$doclibTable->gen(5);
$docactionTable = zenData('docaction');
$docactionTable->id->range('1-8');
$docactionTable->doc->range('1-8');
$docactionTable->action->range('collect{8}');
$docactionTable->actor->range('admin{5},user1{3}');
$docactionTable->date->range('2024-01-01 09:00:00,2024-01-02 09:00:00,2024-01-03 09:00:00');
$docactionTable->gen(8);
su('admin');
$blockTest = new blockTest();
r($blockTest->printDocMyCollectionBlockTest()) && p('success') && e('1');
r($blockTest->printDocMyCollectionBlockTest()) && p('docCount') && e('5,<=');
r($blockTest->printDocMyCollectionBlockTest()) && p('docCount') && e('0,>=');
r($blockTest->printDocMyCollectionBlockTest()) && p('docList') && e('array');
r($blockTest->printDocMyCollectionBlockTest()) && p('libList') && e('array');
@@ -0,0 +1,134 @@
---
title: 我关注的文档测试数据
desc: 用于printDocMyCollectionBlock方法测试的doc表数据
fields:
- field: id
range: 1-10
note: 文档ID
- field: vision
range: 'rnd{10}'
note: 视图类型
- field: project
range: '[0,1,2]{10}'
note: 项目ID
- field: product
range: '[0,1,2]{10}'
note: 产品ID
- field: execution
range: '0{10}'
note: 执行ID
- field: lib
range: '1-5'
note: 文档库ID
- field: template
range: ''
note: 模板
- field: templateType
range: ''
note: 模板类型
- field: chapterType
range: ''
note: 章节类型
- field: module
range: '0{10}'
note: 模块ID
- field: title
range: '我关注的文档{5},重要资料{3},技术文档{2}'
note: 文档标题
- field: keywords
range: '关注,收藏,重要'
note: 关键词
- field: type
range: 'text{6},markdown{4}'
note: 文档类型
- field: status
range: 'normal{8},deleted{2}'
note: 文档状态
- field: parent
range: '0{10}'
note: 父文档ID
- field: path
range: ',1,{5},2,{3},3,{2}'
note: 文档路径
- field: grade
range: '1{10}'
note: 文档等级
- field: order
range: '1-10'
note: 排序
- field: views
range: '1-50:R'
note: 查看次数
- field: assetLib
range: '0{10}'
note: 资产库ID
- field: assetLibType
range: ''
note: 资产库类型
- field: from
range: '0{10}'
note: 来源文档ID
- field: fromVersion
range: '1{10}'
note: 来源版本
- field: draft
range: '[]{10}'
note: 草稿内容
- field: collects
range: '1-10:R'
note: 收藏数
- field: addedBy
range: 'admin{8},user1{2}'
note: 创建者
- field: addedDate
range: '(-10d)-(-5d):1d'
format: 'YYYY-MM-DD hh:mm:ss'
note: 创建时间
- field: assignedTo
range: ''
note: 指派给
- field: assignedDate
range: '[]{10}'
note: 指派时间
- field: editedBy
range: 'admin{6},user1{4}'
note: 编辑者
- field: editedDate
range: '(-5d)-(now):1d'
format: 'YYYY-MM-DD hh:mm:ss'
note: 编辑时间
- field: deleted
range: '0{8},1{2}'
note: 是否删除
@@ -0,0 +1,25 @@
---
title: 文档收藏动作测试数据
desc: 用于printDocMyCollectionBlock方法测试的docaction表数据
fields:
- field: id
range: 1-8
note: 动作ID
- field: doc
range: 1-8
note: 文档ID
- field: action
range: 'collect{8}'
note: 动作类型
- field: actor
range: 'admin{5},user1{3}'
note: 操作者
- field: date
range: '(-7d)-(now):1d'
format: 'YYYY-MM-DD hh:mm:ss'
note: 操作时间
@@ -0,0 +1,37 @@
---
title: 文档库测试数据
desc: 用于printDocMyCollectionBlock方法测试的doclib表数据
fields:
- field: id
range: 1-5
note: 文档库ID
- field: type
range: 'product{3},project{2}'
note: 文档库类型
- field: vision
range: 'rnd{5}'
note: 视图类型
- field: name
range: '产品文档库{3},项目文档库{2}'
note: 文档库名称
- field: acl
range: 'open{3},private{2}'
note: 访问控制
- field: deleted
range: '0{4},1{1}'
note: 是否删除
- field: addedBy
range: 'admin{5}'
note: 创建者
- field: addedDate
range: '(-30d)-(-10d):5d'
format: 'YYYY-MM-DD hh:mm:ss'
note: 创建时间