+ [misc] Add unit tests for docZen::setAclForEditLib() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -789,4 +789,70 @@ class docZenTest extends baseTest
|
||||
'count' => count($aclList)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setAclForEditLib method.
|
||||
*
|
||||
* @param object $lib
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function setAclForEditLibTest(object $lib)
|
||||
{
|
||||
/* Load language files for different types. */
|
||||
global $app, $lang;
|
||||
|
||||
/* Save initial aclList state. */
|
||||
static $initialAclList = null;
|
||||
static $initialMySpaceAclList = null;
|
||||
static $initialPrivateACL = null;
|
||||
|
||||
/* Initialize on first call. */
|
||||
if($initialAclList === null)
|
||||
{
|
||||
$app->loadLang('doc');
|
||||
$initialAclList = $lang->doclib->aclList;
|
||||
$initialMySpaceAclList = $lang->doclib->mySpaceAclList;
|
||||
$initialPrivateACL = $lang->doclib->privateACL;
|
||||
}
|
||||
|
||||
/* Reset doc language to get fresh aclList. */
|
||||
$lang->doclib->aclList = $initialAclList;
|
||||
$lang->doclib->mySpaceAclList = $initialMySpaceAclList;
|
||||
$lang->doclib->privateACL = $initialPrivateACL;
|
||||
|
||||
$libType = $lib->type;
|
||||
if(in_array($libType, array('product', 'project', 'execution')))
|
||||
{
|
||||
$app->loadLang($libType);
|
||||
}
|
||||
|
||||
/* Update instance language reference. */
|
||||
$this->instance->lang = $lang;
|
||||
|
||||
$result = $this->invokeArgs('setAclForEditLib', [$lib]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
/* Return the modified aclList for verification. */
|
||||
$aclList = $this->instance->lang->doclib->aclList;
|
||||
|
||||
/* Check if api language is loaded. */
|
||||
$hasApiLang = isset($this->instance->lang->api) ? 1 : 0;
|
||||
|
||||
/* Check if using mySpaceAclList. */
|
||||
$isMySpaceAclList = 0;
|
||||
if($libType == 'mine' && isset($this->instance->lang->doclib->mySpaceAclList))
|
||||
{
|
||||
$isMySpaceAclList = ($aclList == $this->instance->lang->doclib->mySpaceAclList) ? 1 : 0;
|
||||
}
|
||||
|
||||
return array(
|
||||
'hasDefault' => isset($aclList['default']) ? 1 : 0,
|
||||
'hasOpen' => isset($aclList['open']) ? 1 : 0,
|
||||
'hasPrivate' => isset($aclList['private']) ? 1 : 0,
|
||||
'count' => count($aclList),
|
||||
'hasApiLang' => $hasApiLang,
|
||||
'isMySpaceAclList' => $isMySpaceAclList
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 docZen::setAclForEditLib();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:测试custom类型文档库权限设置属性hasDefault @0
|
||||
- 步骤2:测试api类型文档库(product)权限设置属性hasApiLang @1
|
||||
- 步骤3:测试api类型文档库(project)权限设置属性hasApiLang @1
|
||||
- 步骤4:测试mine类型文档库权限设置属性isMySpaceAclList @1
|
||||
- 步骤5:测试product类型文档库权限设置属性hasOpen @0
|
||||
- 步骤6:测试project类型文档库权限设置属性hasOpen @0
|
||||
- 步骤7:测试execution类型文档库权限设置属性hasOpen @0
|
||||
- 步骤8:测试main库的product类型
|
||||
- 属性hasPrivate @0
|
||||
- 属性hasOpen @0
|
||||
- 步骤9:测试main库的mine类型属性isMySpaceAclList @1
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zen.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$docTest = new docZenTest();
|
||||
|
||||
$customLib = new stdClass();
|
||||
$customLib->type = 'custom';
|
||||
$customLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($customLib)) && p('hasDefault') && e('0'); // 步骤1:测试custom类型文档库权限设置
|
||||
|
||||
$apiProductLib = new stdClass();
|
||||
$apiProductLib->type = 'api';
|
||||
$apiProductLib->product = 1;
|
||||
$apiProductLib->project = 0;
|
||||
$apiProductLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($apiProductLib)) && p('hasApiLang') && e('1'); // 步骤2:测试api类型文档库(product)权限设置
|
||||
|
||||
$apiProjectLib = new stdClass();
|
||||
$apiProjectLib->type = 'api';
|
||||
$apiProjectLib->product = 0;
|
||||
$apiProjectLib->project = 1;
|
||||
$apiProjectLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($apiProjectLib)) && p('hasApiLang') && e('1'); // 步骤3:测试api类型文档库(project)权限设置
|
||||
|
||||
$mineLib = new stdClass();
|
||||
$mineLib->type = 'mine';
|
||||
$mineLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($mineLib)) && p('isMySpaceAclList') && e('1'); // 步骤4:测试mine类型文档库权限设置
|
||||
|
||||
$productLib = new stdClass();
|
||||
$productLib->type = 'product';
|
||||
$productLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($productLib)) && p('hasOpen') && e('0'); // 步骤5:测试product类型文档库权限设置
|
||||
|
||||
$projectLib = new stdClass();
|
||||
$projectLib->type = 'project';
|
||||
$projectLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($projectLib)) && p('hasOpen') && e('0'); // 步骤6:测试project类型文档库权限设置
|
||||
|
||||
$executionLib = new stdClass();
|
||||
$executionLib->type = 'execution';
|
||||
$executionLib->main = '0';
|
||||
r($docTest->setAclForEditLibTest($executionLib)) && p('hasOpen') && e('0'); // 步骤7:测试execution类型文档库权限设置
|
||||
|
||||
$mainProductLib = new stdClass();
|
||||
$mainProductLib->type = 'product';
|
||||
$mainProductLib->main = '1';
|
||||
r($docTest->setAclForEditLibTest($mainProductLib)) && p('hasPrivate;hasOpen') && e('0;0'); // 步骤8:测试main库的product类型
|
||||
|
||||
$mainMineLib = new stdClass();
|
||||
$mainMineLib->type = 'mine';
|
||||
$mainMineLib->main = '1';
|
||||
r($docTest->setAclForEditLibTest($mainMineLib)) && p('isMySpaceAclList') && e('1'); // 步骤9:测试main库的mine类型
|
||||
Reference in New Issue
Block a user