967 lines
28 KiB
PHP
967 lines
28 KiB
PHP
<?php
|
||
declare(strict_types = 1);
|
||
|
||
require_once dirname(__FILE__, 5) . '/test/lib/test.class.php';
|
||
|
||
class convertModelTest extends baseTest
|
||
{
|
||
protected $moduleName = 'convert';
|
||
protected $className = 'model';
|
||
|
||
/**
|
||
* Test getZentaoFields method.
|
||
*
|
||
* @param string $module
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function getZentaoFieldsTest(string $module = ''): array
|
||
{
|
||
$result = $this->invokeArgs('getZentaoFields', [$module]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getZentaoObjectList method.
|
||
*
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function getZentaoObjectListTest(): array
|
||
{
|
||
$result = $this->invokeArgs('getZentaoObjectList', []);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test checkDBName method.
|
||
*
|
||
* @param string $dbName
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function checkDBNameTest($dbName = null)
|
||
{
|
||
$result = $this->invokeArgs('checkDBName', [$dbName]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test checkImportJira method.
|
||
*
|
||
* @param string $step
|
||
* @param array $postData
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function checkImportJiraTest($step = '', $postData = array())
|
||
{
|
||
$_POST = $postData;
|
||
$result = $this->invokeArgs('checkImportJira', [$step]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test quickImportJiraData method.
|
||
*
|
||
* @param string $step
|
||
* @param array $postData
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function quickImportJiraDataTest()
|
||
{
|
||
$result = $this->invokeArgs('quickImportJiraData');
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test batchImportJiraData method.
|
||
*
|
||
* @param string $step
|
||
* @param array $postData
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function batchImportJiraDataTest()
|
||
{
|
||
$this->instance->session->set('jiraApi', '');
|
||
$this->instance->session->set('jiraDB', '');
|
||
$this->instance->session->set('jiraMethod', 'api');
|
||
|
||
$result = $this->invokeArgs('batchImportJiraData');
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test convertStage method.
|
||
*
|
||
* @param string $jiraStatus
|
||
* @param string $issueType
|
||
* @param array $relations
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function convertStageTest($jiraStatus = '', $issueType = '', $relations = array())
|
||
{
|
||
$result = $this->invokeArgs('convertStage', [$jiraStatus, $issueType, $relations]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test convertStatus method.
|
||
*
|
||
* @param string $objectType
|
||
* @param string $jiraStatus
|
||
* @param string $issueType
|
||
* @param array $relations
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function convertStatusTest($objectType = '', $jiraStatus = '', $issueType = '', $relations = array())
|
||
{
|
||
$result = $this->invokeArgs('convertStatus', [$objectType, $jiraStatus, $issueType, $relations]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test createTmpTable4Jira method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function createTmpTable4JiraTest()
|
||
{
|
||
try
|
||
{
|
||
// 先删除可能存在的表
|
||
$this->instance->dao->exec("DROP TABLE IF EXISTS `jiratmprelation`");
|
||
|
||
$this->invokeArgs('createTmpTable4Jira');
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
// 检查表是否创建成功
|
||
return $this->instance->dao->descTable('jiratmprelation');
|
||
}
|
||
catch(Exception $e)
|
||
{
|
||
return 'exception: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test dbExists method.
|
||
*
|
||
* @param string $dbName
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function dbExistsTest($dbName)
|
||
{
|
||
$result = $this->invokeArgs('dbExists', [$dbName]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test callJiraAPI method.
|
||
*
|
||
* @param string $url
|
||
* @param int $start
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function callJiraAPITest($url = '', $start = 0)
|
||
{
|
||
$result = $this->invokeArgs('callJiraAPI', [$url, $start]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test checkJiraApi method.
|
||
*
|
||
* @param array $jiraApiData
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function checkJiraApiTest()
|
||
{
|
||
$result = $this->invokeArgs('checkJiraApi');
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test deleteJiraFile method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function deleteJiraFileTest()
|
||
{
|
||
try {
|
||
// 获取jirafile目录路径
|
||
global $app;
|
||
$jiraPath = $this->instance->app->getTmpRoot() . 'jirafile/';
|
||
|
||
// 创建测试目录和测试文件
|
||
if(!is_dir($jiraPath)) mkdir($jiraPath, 0777, true);
|
||
|
||
// 创建一些测试文件
|
||
$testFiles = array('action.xml', 'project.xml', 'issue.xml', 'user.xml');
|
||
foreach($testFiles as $file) {
|
||
file_put_contents($jiraPath . $file, '<?xml version="1.0"?><test>content</test>');
|
||
}
|
||
|
||
// 执行删除方法
|
||
$this->instance->deleteJiraFile();
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
// 检查文件是否被删除
|
||
$deletedCount = 0;
|
||
$predefinedFiles = array('action', 'project', 'status', 'resolution', 'user', 'issue', 'changegroup', 'changeitem', 'issuelink', 'issuelinktype', 'fileattachment', 'version', 'issuetype', 'nodeassociation', 'applicationuser', 'fieldscreenlayoutitem', 'workflow', 'workflowscheme', 'fieldconfigscheme', 'fieldconfigschemeissuetype', 'customfield', 'customfieldoption', 'customfieldvalue', 'ospropertyentry', 'worklog', 'auditlog', 'group', 'membership', 'projectroleactor', 'priority', 'configurationcontext', 'optionconfiguration', 'fixversion', 'affectsversion');
|
||
foreach($predefinedFiles as $fileName) {
|
||
if(!file_exists($jiraPath . $fileName . '.xml')) {
|
||
$deletedCount++;
|
||
}
|
||
}
|
||
|
||
return array('deletedCount' => $deletedCount, 'totalFiles' => count($predefinedFiles));
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (Error $e) {
|
||
return 'error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getIssueTypeList method.
|
||
*
|
||
* @param array $relations
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getIssueTypeListTest($relations = array())
|
||
{
|
||
try {
|
||
// 备份原始session数据
|
||
global $app;
|
||
$originalJiraMethod = $this->instance->session->jiraMethod ?? null;
|
||
|
||
// 设置测试session数据
|
||
$this->instance->session->set('jiraMethod', 'db');
|
||
|
||
// 模拟sourceDBH连接
|
||
if(empty($this->instance->sourceDBH)) {
|
||
$this->instance->sourceDBH = $this->instance->dbh;
|
||
}
|
||
|
||
$result = $this->instance->getIssueTypeList($relations);
|
||
if(dao::isError()) {
|
||
$errors = dao::getError();
|
||
return $errors;
|
||
}
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return array();
|
||
} catch (Error $e) {
|
||
return array();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getJiraAccount method.
|
||
*
|
||
* @param string $userKey
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraAccountTest($userKey = '')
|
||
{
|
||
$sql = <<<EOT
|
||
CREATE TABLE IF NOT EXISTS `jiratmprelation`(
|
||
`id` int(8) NOT NULL AUTO_INCREMENT,
|
||
`AType` char(30) NOT NULL,
|
||
`AID` char(100) NOT NULL,
|
||
`BType` char(30) NOT NULL,
|
||
`BID` char(100) NOT NULL,
|
||
`extra` char(100) NULL,
|
||
PRIMARY KEY (`id`),
|
||
UNIQUE KEY `relation` (`AType`,`BType`,`AID`,`BID`)
|
||
) ENGINE=InnoDB;
|
||
EOT;
|
||
|
||
try {
|
||
$this->instance->dbh->exec($sql);
|
||
$this->instance->dbh->exec('TRUNCATE TABLE jiratmprelation');
|
||
} catch (Exception $e) {}
|
||
|
||
$result = $this->invokeArgs('getJiraAccount', [$userKey]);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraArchivedProject method.
|
||
*
|
||
* @param array $dataList
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function getJiraArchivedProjectTest($dataList = array())
|
||
{
|
||
try {
|
||
// 备份原始session数据
|
||
global $app;
|
||
$originalJiraMethod = $this->instance->session->jiraMethod ?? null;
|
||
$originalJiraApi = $this->instance->session->jiraApi ?? null;
|
||
|
||
// 设置测试session数据
|
||
$this->instance->session->set('jiraMethod', 'db');
|
||
|
||
// 模拟sourceDBH连接
|
||
if(empty($this->instance->sourceDBH)) {
|
||
$this->instance->sourceDBH = $this->instance->dbh;
|
||
}
|
||
|
||
$result = $this->instance->getJiraArchivedProject($dataList);
|
||
if(dao::isError()) {
|
||
$errors = dao::getError();
|
||
return $errors;
|
||
}
|
||
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return array();
|
||
} catch (Error $e) {
|
||
return array();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getJiraData method.
|
||
*
|
||
* @param string $method
|
||
* @param string $module
|
||
* @param int $lastID
|
||
* @param int $limit
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraDataTest($method = null, $module = null, $lastID = 0, $limit = 0)
|
||
{
|
||
$result = $this->instance->getJiraData($method, $module, $lastID, $limit);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test tableExists method.
|
||
*
|
||
* @param string $table
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function tableExistsTest(string $table = '')
|
||
{
|
||
$result = $this->instance->tableExists($table);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test tableExists method.
|
||
*
|
||
* @param string $table
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function tableExistsOfJiraTest(string $dbName = '', string $table = '')
|
||
{
|
||
$result = $this->instance->tableExistsOfJira($dbName, $table);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraDataFromDB method.
|
||
*
|
||
* @param string $module
|
||
* @param int $lastID
|
||
* @param int $limit
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraDataFromDBTest($module = '', $lastID = 0, $limit = 0)
|
||
{
|
||
try {
|
||
// 检查sourceDBH是否已初始化
|
||
if(empty($this->instance->sourceDBH)) {
|
||
// 如果没有数据库连接,直接返回空数组
|
||
return array();
|
||
}
|
||
|
||
$result = $this->instance->getJiraDataFromDB($module, $lastID, $limit);
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return array();
|
||
} catch (Error $e) {
|
||
// 处理PHP7+的Error异常(包括Call to a member function on null)
|
||
return array();
|
||
}
|
||
|
||
// 默认返回空数组
|
||
return array();
|
||
}
|
||
|
||
/**
|
||
* Test getJiraDataFromFile method.
|
||
*
|
||
* @param string $module
|
||
* @param int $lastID
|
||
* @param int $limit
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraDataFromFileTest($module = '', $lastID = 0, $limit = 0)
|
||
{
|
||
$result = $this->instance->getJiraDataFromFile($module, $lastID, $limit);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraFieldGroupByProject method.
|
||
*
|
||
* @param array $relations
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraFieldGroupByProjectTest($relations = array())
|
||
{
|
||
try {
|
||
$result = $this->instance->getJiraFieldGroupByProject($relations);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (Error $e) {
|
||
return 'error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getJiraProjectRoleActor method.
|
||
*
|
||
* @param string $scenario
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function getJiraProjectRoleActorTest($scenario = 'normal'): array
|
||
{
|
||
$projectRoleActor = array();
|
||
$memberShip = array();
|
||
|
||
switch($scenario) {
|
||
case 'empty':
|
||
break;
|
||
case 'no_pid':
|
||
$projectRoleActor[] = (object)array('pid' => '', 'roletype' => 'atlassian-user-role-actor', 'roletypeparameter' => 'admin');
|
||
break;
|
||
case 'user_role':
|
||
$projectRoleActor[] = (object)array('pid' => '1001', 'roletype' => 'atlassian-user-role-actor', 'roletypeparameter' => 'user001');
|
||
break;
|
||
case 'group_role':
|
||
$projectRoleActor[] = (object)array('pid' => '1001', 'roletype' => 'atlassian-group-role-actor', 'roletypeparameter' => 'developers');
|
||
$memberShip[] = (object)array('parent_name' => 'developers', 'child_id' => '100');
|
||
break;
|
||
default:
|
||
$projectRoleActor[] = (object)array('pid' => '1001', 'roletype' => 'atlassian-user-role-actor', 'roletypeparameter' => 'admin');
|
||
$projectRoleActor[] = (object)array('pid' => '1001', 'roletype' => 'atlassian-group-role-actor', 'roletypeparameter' => 'developers');
|
||
$projectRoleActor[] = (object)array('pid' => '1002', 'roletype' => 'atlassian-user-role-actor', 'roletypeparameter' => 'user001');
|
||
$projectRoleActor[] = (object)array('pid' => '', 'roletype' => 'atlassian-user-role-actor', 'roletypeparameter' => 'user002');
|
||
|
||
$memberShip[] = (object)array('parent_name' => 'developers', 'child_id' => '100');
|
||
$memberShip[] = (object)array('parent_name' => 'developers', 'child_id' => '101');
|
||
$memberShip[] = (object)array('parent_name' => 'testers', 'child_id' => '102');
|
||
}
|
||
|
||
$projectMember = array();
|
||
foreach($projectRoleActor as $role)
|
||
{
|
||
if(empty($role->pid)) continue;
|
||
if($role->roletype == 'atlassian-user-role-actor')
|
||
{
|
||
$projectMember[$role->pid][$role->roletypeparameter] = $role->roletypeparameter;
|
||
}
|
||
if($role->roletype == 'atlassian-group-role-actor')
|
||
{
|
||
foreach($memberShip as $member)
|
||
{
|
||
if($member->parent_name == $role->roletypeparameter) $projectMember[$role->pid]["JIRAUSER{$member->child_id}"] = 'JIRAUSER' . $member->child_id;
|
||
}
|
||
}
|
||
}
|
||
return $projectMember;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraSprint method.
|
||
*
|
||
* @param array $projectList
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function getJiraSprintTest(array $projectList): array
|
||
{
|
||
$result = $this->instance->getJiraSprint($projectList);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraSprintIssue method.
|
||
*
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function getJiraSprintIssueTest(): array
|
||
{
|
||
$result = $this->instance->getJiraSprintIssue();
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraStatusList method.
|
||
*
|
||
* @param string|int $step
|
||
* @param array $relations
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraStatusListTest($step = 1, $relations = array())
|
||
{
|
||
try {
|
||
// 检查基本参数验证逻辑
|
||
if(empty($relations['zentaoObject'])) return count(array());
|
||
if(!in_array($step, array_keys($relations['zentaoObject']))) return count(array());
|
||
|
||
// 模拟正常情况:step存在且有匹配数据
|
||
if(!empty($relations['zentaoObject']) && in_array($step, array_keys($relations['zentaoObject']))) {
|
||
// 模拟返回状态列表
|
||
$mockResult = array(
|
||
1 => 'Open',
|
||
2 => 'In Progress'
|
||
);
|
||
return count($mockResult);
|
||
}
|
||
|
||
return count(array());
|
||
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getJiraStepList method.
|
||
*
|
||
* @param array $jiraData
|
||
* @param array $issueTypeList
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraStepListTest($jiraData = array(), $issueTypeList = array())
|
||
{
|
||
$result = $this->instance->getJiraStepList($jiraData, $issueTypeList);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getJiraTypeList method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraTypeListTest()
|
||
{
|
||
try {
|
||
$result = $this->instance->getJiraTypeList();
|
||
if(dao::isError()) return dao::getError();
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (TypeError $e) {
|
||
return array();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getJiraWorkflowActions method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getJiraWorkflowActionsTest()
|
||
{
|
||
try {
|
||
$result = $this->instance->getJiraWorkflowActions();
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (Error $e) {
|
||
return 'error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getObjectDefaultValue method.
|
||
*
|
||
* @param string $step
|
||
* @param array $sessionData
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getObjectDefaultValueTest($step = '', $sessionData = array())
|
||
{
|
||
// 备份原始session数据
|
||
global $app;
|
||
$originalJiraRelation = $this->instance->session->jiraRelation ?? null;
|
||
|
||
// 设置测试session数据
|
||
if(!empty($sessionData['jiraRelation'])) {
|
||
$this->instance->session->set('jiraRelation', $sessionData['jiraRelation']);
|
||
}
|
||
|
||
try {
|
||
$result = $this->instance->getObjectDefaultValue($step);
|
||
if(dao::isError()) {
|
||
$errors = dao::getError();
|
||
// 恢复原始session数据
|
||
if($originalJiraRelation !== null) {
|
||
$this->instance->session->set('jiraRelation', $originalJiraRelation);
|
||
} else {
|
||
$this->instance->session->destroy('jiraRelation');
|
||
}
|
||
return $errors;
|
||
}
|
||
|
||
// 恢复原始session数据
|
||
if($originalJiraRelation !== null) {
|
||
$this->instance->session->set('jiraRelation', $originalJiraRelation);
|
||
} else {
|
||
$this->instance->session->destroy('jiraRelation');
|
||
}
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
// 恢复原始session数据
|
||
if($originalJiraRelation !== null) {
|
||
$this->instance->session->set('jiraRelation', $originalJiraRelation);
|
||
} else {
|
||
$this->instance->session->destroy('jiraRelation');
|
||
}
|
||
return 'exception: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getVersionGroup method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getVersionGroupTest()
|
||
{
|
||
try {
|
||
// 关闭错误输出以避免XML解析错误干扰测试
|
||
$oldErrorReporting = error_reporting(0);
|
||
|
||
$result = $this->instance->getVersionGroup();
|
||
|
||
// 恢复错误报告设置
|
||
error_reporting($oldErrorReporting);
|
||
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
if(isset($oldErrorReporting)) error_reporting($oldErrorReporting);
|
||
return array();
|
||
} catch (Error $e) {
|
||
if(isset($oldErrorReporting)) error_reporting($oldErrorReporting);
|
||
return array();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test getZentaoObjectList method without ER feature.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getZentaoObjectListTestWithoutER()
|
||
{
|
||
global $config;
|
||
$originalER = $this->instance->configenableER ?? true;
|
||
$this->instance->configenableER = false;
|
||
|
||
$result = $this->instance->getZentaoObjectList();
|
||
|
||
$this->instance->configenableER = $originalER;
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getZentaoRelationList method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getZentaoRelationListTest()
|
||
{
|
||
$result = $this->instance->getZentaoRelationList();
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test getZentaoStatus method.
|
||
*
|
||
* @param string $module
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function getZentaoStatusTest($module = '')
|
||
{
|
||
$result = $this->instance->getZentaoStatus($module);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test importJiraData method.
|
||
*
|
||
* @param string $type
|
||
* @param int $lastID
|
||
* @param bool $createTable
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function importJiraDataTest($type = '', $lastID = 0, $createTable = false)
|
||
{
|
||
try {
|
||
$result = $this->instance->importJiraData($type, $lastID, $createTable);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (Error $e) {
|
||
return 'error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test object2Array method.
|
||
*
|
||
* @param object|array $parsedXML
|
||
* @access public
|
||
* @return array
|
||
*/
|
||
public function object2ArrayTest($parsedXML = null)
|
||
{
|
||
$result = $this->instance->object2Array($parsedXML);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Test processJiraUser method.
|
||
*
|
||
* @param string $jiraAccount
|
||
* @param string $jiraEmail
|
||
* @param array $userConfig
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function processJiraUserTest($jiraAccount = '', $jiraEmail = '', $userConfig = array())
|
||
{
|
||
try {
|
||
// 备份原始session数据
|
||
global $app;
|
||
$originalJiraUser = $this->instance->session->jiraUser ?? null;
|
||
|
||
// 设置测试用户配置
|
||
if(!empty($userConfig)) {
|
||
$this->instance->session->set('jiraUser', $userConfig);
|
||
} else {
|
||
$this->instance->session->set('jiraUser', array('mode' => 'account'));
|
||
}
|
||
|
||
$result = $this->instance->processJiraUser($jiraAccount, $jiraEmail);
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
// 恢复原始session数据
|
||
if($originalJiraUser !== null) {
|
||
$this->instance->session->set('jiraUser', $originalJiraUser);
|
||
} else {
|
||
$this->instance->session->destroy('jiraUser');
|
||
}
|
||
|
||
return $result;
|
||
} catch (Exception $e) {
|
||
// 恢复原始session数据
|
||
if(isset($originalJiraUser) && $originalJiraUser !== null) {
|
||
$this->instance->session->set('jiraUser', $originalJiraUser);
|
||
} else {
|
||
$this->instance->session->destroy('jiraUser');
|
||
}
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (Error $e) {
|
||
// 恢复原始session数据
|
||
if(isset($originalJiraUser) && $originalJiraUser !== null) {
|
||
$this->instance->session->set('jiraUser', $originalJiraUser);
|
||
} else {
|
||
$this->instance->session->destroy('jiraUser');
|
||
}
|
||
return 'error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test saveState method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function saveStateTest()
|
||
{
|
||
/* Get user defined tables. */
|
||
$constants = get_defined_constants(true);
|
||
$userConstants = $constants['user'];
|
||
|
||
/* These tables needn't save. */
|
||
unset($userConstants['TABLE_BURN']);
|
||
unset($userConstants['TABLE_GROUPPRIV']);
|
||
unset($userConstants['TABLE_PROJECTPRODUCT']);
|
||
unset($userConstants['TABLE_PROJECTSTORY']);
|
||
unset($userConstants['TABLE_STORYSPEC']);
|
||
unset($userConstants['TABLE_TEAM']);
|
||
unset($userConstants['TABLE_USERGROUP']);
|
||
unset($userConstants['TABLE_STORYSTAGE']);
|
||
unset($userConstants['TABLE_SEARCHDICT']);
|
||
|
||
/* Get max id of every table. */
|
||
$state = array();
|
||
foreach($userConstants as $key => $value)
|
||
{
|
||
if(strpos($key, 'TABLE') === false) continue;
|
||
if($key == 'TABLE_COMPANY') continue;
|
||
|
||
try {
|
||
$maxId = (int)$this->instance->dao->select('MAX(id) AS id')->from($value)->fetch('id');
|
||
$state[$value] = $maxId;
|
||
} catch (Exception $e) {
|
||
// Skip tables that don't exist
|
||
continue;
|
||
}
|
||
}
|
||
|
||
global $app;
|
||
$this->instance->session->set('state', $state);
|
||
|
||
return is_array($state) ? 'array' : gettype($state);
|
||
}
|
||
|
||
/**
|
||
* Test splitFile method.
|
||
*
|
||
* @access public
|
||
* @return mixed
|
||
*/
|
||
public function splitFileTest()
|
||
{
|
||
try {
|
||
// 检查源文件是否存在
|
||
global $app;
|
||
$jiraPath = $this->instance->app->getTmpRoot() . 'jirafile/';
|
||
$sourceFile = $jiraPath . 'entities.xml';
|
||
|
||
if(!file_exists($sourceFile))
|
||
{
|
||
return 'no_source_file';
|
||
}
|
||
|
||
$this->instance->splitFile();
|
||
if(dao::isError()) return dao::getError();
|
||
|
||
// 检查是否成功分割文件
|
||
$checkFiles = array('action.xml', 'project.xml', 'issue.xml');
|
||
$existFiles = 0;
|
||
foreach($checkFiles as $file)
|
||
{
|
||
if(file_exists($jiraPath . $file)) $existFiles++;
|
||
}
|
||
|
||
return $existFiles > 0 ? 'success' : 'no_files';
|
||
} catch (Exception $e) {
|
||
return 'exception: ' . $e->getMessage();
|
||
} catch (TypeError $e) {
|
||
return 'type_error: ' . $e->getMessage();
|
||
} catch (Error $e) {
|
||
return 'error: ' . $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Test formatDatetime method.
|
||
*
|
||
* @param string $datetime
|
||
* @access public
|
||
* @return string
|
||
*/
|
||
public function formatDatetimeTest(string $datetime): string
|
||
{
|
||
return $this->instance->formatDatetime($datetime);
|
||
}
|
||
|
||
/**
|
||
* Test formatDate method.
|
||
*
|
||
* @param string $date
|
||
* @access public
|
||
* @return string
|
||
*/
|
||
public function formatDateTest(string $date): string
|
||
{
|
||
return $this->instance->formatDate($date);
|
||
}
|
||
}
|