* [bug#64713] Add the unit test file of fileModel::buildFileActions.

This commit is contained in:
xieqiyu
2025-08-21 08:38:51 +08:00
committed by tianshujie
parent aee6b3c9fc
commit d2c063c8ad
2 changed files with 55 additions and 0 deletions
@@ -460,4 +460,20 @@ class fileTest
$file = $this->objectModel->dao->select('*')->from(TABLE_FILE)->where('id')->eq($fileID)->fetch();
return $this->objectModel->printFile($file, $method, $showDelete, $showEdit, null);
}
/**
* Build file actions.
*
* @param int $fileID
* @param bool $showEdit
* @param bool $showDelete
* @access public
* @return string
*/
public function buildFileActionsTest(int $fileID, bool $showEdit, bool $showDelete): string
{
$file = $this->objectModel->dao->select('*')->from(TABLE_FILE)->where('id')->eq($fileID)->fetch();
$downloadLink = helper::createLink('file', 'download', "fileID=$fileID");
return $this->objectModel->buildFileActions('', $downloadLink, 0, $showEdit, $showDelete, $file, null);
}
}
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php
/**
title=测试 fileModel->printFile();
timeout=0
cid=0
- 测试非详情/编辑页面的情况 @1
- 测试编辑页面不展示删除按钮的情况 @0
- 测试编辑页面不展示编辑按钮的情况 @1
- 测试详情页面不展示删除按钮的情况 @0
- 测试详情页面不展示编辑按钮的情况 @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/file.unittest.class.php';
su('admin');
zenData('file')->gen(5);
$fileIdList = range(1, 5);
$showDeleteList = array(true, false);
$showEdit = array(true, false);
$fileTester = new fileTest();
$result1 = $fileTester->buildFileActionsTest($fileIdList[0], $showDeleteList[0], $showEdit[0]);
$result2 = $fileTester->buildFileActionsTest($fileIdList[1], $showDeleteList[1], $showEdit[0]);
$result3 = $fileTester->buildFileActionsTest($fileIdList[2], $showDeleteList[0], $showEdit[1]);
$result4 = $fileTester->buildFileActionsTest($fileIdList[3], $showDeleteList[1], $showEdit[0]);
$result5 = $fileTester->buildFileActionsTest($fileIdList[4], $showDeleteList[0], $showEdit[1]);
r(strpos($result1, '文件标题1') !== false) && p() && e('1'); // 测试非详情/编辑页面的情况
r(strpos($result2, '删除') === false) && p() && e('0'); // 测试编辑页面不展示删除按钮的情况
r(strpos($result3, '编辑') === false) && p() && e('1'); // 测试编辑页面不展示编辑按钮的情况
r(strpos($result4, '删除') === false) && p() && e('0'); // 测试详情页面不展示删除按钮的情况
r(strpos($result5, '编辑') === false) && p() && e('1'); // 测试详情页面不展示编辑按钮的情况