🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
640 lines
18 KiB
PHP
640 lines
18 KiB
PHP
<?php
|
|
declare(strict_types = 1);
|
|
class projectTest
|
|
{
|
|
public function __construct()
|
|
{
|
|
global $tester;
|
|
$this->objectModel = $tester->loadModel('project');
|
|
$this->objectTao = $tester->loadTao('project');
|
|
}
|
|
|
|
/**
|
|
* Test getAclListByObjectType method.
|
|
*
|
|
* @param string $objectType
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function getAclListByObjectTypeTest($objectType = null)
|
|
{
|
|
$result = $this->objectModel->getAclListByObjectType($objectType);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test getListByAcl method.
|
|
*
|
|
* @param string $acl
|
|
* @param array $idList
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function getListByAclTest($acl = '', $idList = array())
|
|
{
|
|
$result = $this->objectModel->getListByAcl($acl, $idList);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test updateMemberView method.
|
|
*
|
|
* @param int $projectID
|
|
* @param array $accounts
|
|
* @param array $oldJoin
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function updateMemberViewTest($projectID = 0, $accounts = array(), $oldJoin = array())
|
|
{
|
|
try
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$method = $reflection->getMethod('updateMemberView');
|
|
$method->setAccessible(true);
|
|
|
|
$method->invoke($this->objectTao, $projectID, $accounts, $oldJoin);
|
|
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return true;
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
if(strpos($e->getMessage(), 'Table') !== false && strpos($e->getMessage(), 'doesn\'t exist') !== false)
|
|
{
|
|
return 'TABLE_NOT_EXISTS';
|
|
}
|
|
return $e->getMessage();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test getTeamListByType method.
|
|
*
|
|
* @param string $type
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function getTeamListByTypeTest($type = '')
|
|
{
|
|
$result = $this->objectModel->getTeamListByType($type);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test getInvolvedListByCurrentUser method.
|
|
*
|
|
* @param string $fields
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function getInvolvedListByCurrentUserTest($fields = 't1.*')
|
|
{
|
|
$result = $this->objectModel->getInvolvedListByCurrentUser($fields);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test leftJoinInvolvedTable method.
|
|
*
|
|
* @param object $stmt
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function leftJoinInvolvedTableTest($stmt = null)
|
|
{
|
|
global $tester;
|
|
if($stmt === null)
|
|
{
|
|
$stmt = $tester->dao->select('*')->from(TABLE_PROJECT)->alias('t1');
|
|
}
|
|
|
|
$result = $this->objectModel->leftJoinInvolvedTable($stmt);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test appendInvolvedCondition method.
|
|
*
|
|
* @param object $stmt
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function appendInvolvedConditionTest($stmt = null)
|
|
{
|
|
global $tester;
|
|
if($stmt === null)
|
|
{
|
|
$stmt = $tester->dao->select('*')->from(TABLE_PROJECT)->alias('t1');
|
|
$stmt = $this->objectModel->leftJoinInvolvedTable($stmt);
|
|
}
|
|
|
|
$result = $this->objectModel->appendInvolvedCondition($stmt);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test getExecutionProductGroup method.
|
|
*
|
|
* @param array $executionIDs
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function getExecutionProductGroupTest($executionIDs = array())
|
|
{
|
|
$result = $this->objectModel->getExecutionProductGroup($executionIDs);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test addTeamMembers method.
|
|
*
|
|
* @param int $projectID
|
|
* @param object $project
|
|
* @param array $members
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function addTeamMembersTest($projectID = 0, $project = null, $members = array())
|
|
{
|
|
$reflection = new ReflectionClass($this->objectModel);
|
|
$method = $reflection->getMethod('addTeamMembers');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($this->objectModel, $projectID, $project, $members);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test checkBranchAndProduct method.
|
|
*
|
|
* @param int $parent
|
|
* @param array $products
|
|
* @param array $branch
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function checkBranchAndProductTest($parent = 0, $products = array(), $branch = array())
|
|
{
|
|
$result = $this->objectModel->checkBranchAndProduct($parent, $products, $branch);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test checkDates method.
|
|
*
|
|
* @param int $projectID
|
|
* @param object $project
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function checkDatesTest($projectID = 0, $project = null)
|
|
{
|
|
$result = $this->objectModel->checkDates($projectID, $project);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test updateTeamMembers method.
|
|
*
|
|
* @param object $project
|
|
* @param object $oldProject
|
|
* @param array $newMembers
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function updateTeamMembersTest($project = null, $oldProject = null, $newMembers = array())
|
|
{
|
|
$result = $this->objectModel->updateTeamMembers($project, $oldProject, $newMembers);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test updateUserView method.
|
|
*
|
|
* @param int $projectID
|
|
* @param string $acl
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function updateUserViewTest($projectID = 0, $acl = '')
|
|
{
|
|
$result = $this->objectModel->updateUserView($projectID, $acl);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test unlinkStoryByType method.
|
|
*
|
|
* @param int $projectID
|
|
* @param string $storyType
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function unlinkStoryByTypeTest($projectID = 0, $storyType = '')
|
|
{
|
|
$result = $this->objectModel->unlinkStoryByType($projectID, $storyType);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test setNoMultipleMenu method.
|
|
*
|
|
* @param int $projectID
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function setNoMultipleMenuTest($projectID = 0)
|
|
{
|
|
$result = $this->objectModel->setNoMultipleMenu($projectID);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test formatDataForList method.
|
|
*
|
|
* @param object $project
|
|
* @param array $PMList
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function formatDataForListTest($project = null, $PMList = array())
|
|
{
|
|
$result = $this->objectModel->formatDataForList($project, $PMList);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test recordFirstEnd method.
|
|
*
|
|
* @param int $projectID
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function recordFirstEndTest($projectID = 0)
|
|
{
|
|
$result = $this->objectModel->recordFirstEnd($projectID);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test doStart method.
|
|
*
|
|
* @param int $projectID
|
|
* @param object $project
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function doStartTest($projectID = 0, $project = null)
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$method = $reflection->getMethod('doStart');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($this->objectTao, $projectID, $project);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test insertMember method.
|
|
*
|
|
* @param array $members
|
|
* @param int $projectID
|
|
* @param array $oldJoin
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function insertMemberTest($members = array(), $projectID = 0, $oldJoin = array())
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$method = $reflection->getMethod('insertMember');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($this->objectTao, $members, $projectID, $oldJoin);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test buildLinkForProject method.
|
|
*
|
|
* @param string $method
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function buildLinkForProjectTest($method = '')
|
|
{
|
|
// Capture output to get error messages
|
|
ob_start();
|
|
$errorOccurred = false;
|
|
$result = null;
|
|
|
|
try
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$testMethod = $reflection->getMethod('buildLinkForProject');
|
|
$testMethod->setAccessible(true);
|
|
|
|
$result = $testMethod->invoke($this->objectTao, $method);
|
|
if(dao::isError()) return dao::getError();
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
$errorOccurred = true;
|
|
$result = $e->getMessage();
|
|
}
|
|
catch(Error $e)
|
|
{
|
|
$errorOccurred = true;
|
|
$result = $e->getMessage();
|
|
}
|
|
|
|
$output = ob_get_clean();
|
|
|
|
// If there's captured output (error messages), process it
|
|
if(!empty($output))
|
|
{
|
|
// Clean HTML tags and extract meaningful error message
|
|
$cleanOutput = strip_tags($output);
|
|
$cleanOutput = trim($cleanOutput);
|
|
return $cleanOutput;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test buildLinkForBug method.
|
|
*
|
|
* @param string $method
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function buildLinkForBugTest($method = '')
|
|
{
|
|
ob_start();
|
|
$errorOccurred = false;
|
|
$result = null;
|
|
|
|
try
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$testMethod = $reflection->getMethod('buildLinkForBug');
|
|
$testMethod->setAccessible(true);
|
|
|
|
$result = $testMethod->invoke($this->objectTao, $method);
|
|
if(dao::isError()) return dao::getError();
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
$errorOccurred = true;
|
|
$result = $e->getMessage();
|
|
}
|
|
catch(Error $e)
|
|
{
|
|
$errorOccurred = true;
|
|
$result = $e->getMessage();
|
|
}
|
|
|
|
$output = ob_get_clean();
|
|
|
|
// If there's captured output (error messages), process it
|
|
if(!empty($output))
|
|
{
|
|
// Clean HTML tags and extract meaningful error message
|
|
$cleanOutput = strip_tags($output);
|
|
$cleanOutput = trim($cleanOutput);
|
|
return $cleanOutput;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test buildLinkForStory method.
|
|
*
|
|
* @param string $method
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function buildLinkForStoryTest($method = '')
|
|
{
|
|
ob_start();
|
|
$errorOccurred = false;
|
|
$result = null;
|
|
|
|
try
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$testMethod = $reflection->getMethod('buildLinkForStory');
|
|
$testMethod->setAccessible(true);
|
|
|
|
$result = $testMethod->invoke($this->objectTao, $method);
|
|
if(dao::isError()) return dao::getError();
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
$errorOccurred = true;
|
|
$result = $e->getMessage();
|
|
}
|
|
catch(Error $e)
|
|
{
|
|
$errorOccurred = true;
|
|
$result = $e->getMessage();
|
|
}
|
|
|
|
$output = ob_get_clean();
|
|
|
|
// If there's captured output (error messages), process it
|
|
if(!empty($output))
|
|
{
|
|
// Clean HTML tags and extract meaningful error message
|
|
$cleanOutput = strip_tags($output);
|
|
$cleanOutput = trim($cleanOutput);
|
|
return $cleanOutput;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test unlinkTeamMember method.
|
|
*
|
|
* @param mixed $projectIdList
|
|
* @param string $type
|
|
* @param string $account
|
|
* @param string $realname
|
|
* @param array $changes
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function unlinkTeamMemberTest($projectIdList = 0, $type = '', $account = '', $realname = '', $changes = array())
|
|
{
|
|
try
|
|
{
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$method = $reflection->getMethod('unlinkTeamMember');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($this->objectTao, $projectIdList, $type, $account, $realname, $changes);
|
|
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
if(strpos($e->getMessage(), 'Table') !== false && strpos($e->getMessage(), 'doesn\'t exist') !== false)
|
|
{
|
|
return 'TABLE_NOT_EXISTS';
|
|
}
|
|
return $e->getMessage();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test setNavGroupMenu method.
|
|
*
|
|
* @param string $navGroup
|
|
* @param int $executionID
|
|
* @param object $project
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function setNavGroupMenuTest($navGroup = '', $executionID = 0, $project = null)
|
|
{
|
|
global $lang, $config;
|
|
|
|
// Initialize lang object if not exists
|
|
if(!isset($lang) || !is_object($lang))
|
|
{
|
|
$lang = new stdClass();
|
|
}
|
|
|
|
// Initialize config object if needed
|
|
if(!isset($config->project))
|
|
{
|
|
$config->project = new stdClass();
|
|
}
|
|
if(!isset($config->project->multiple))
|
|
{
|
|
$config->project->multiple = array(
|
|
'project' => ',test1,project,',
|
|
'execution' => ',test1,execution,'
|
|
);
|
|
}
|
|
|
|
// Mock the required navigation group menu structure with object property
|
|
if(!empty($navGroup))
|
|
{
|
|
if(!isset($lang->$navGroup))
|
|
{
|
|
$lang->$navGroup = new stdClass();
|
|
}
|
|
|
|
if(!isset($lang->$navGroup->menu))
|
|
{
|
|
$menuObject = new stdClass();
|
|
$menuObject->test1 = array(
|
|
'link' => 'test-link',
|
|
'subMenu' => array(
|
|
'sub1' => array('link' => 'sub-link')
|
|
),
|
|
'dropMenu' => array(
|
|
'drop1' => array(
|
|
'link' => 'drop-link',
|
|
'subMenu' => array(
|
|
'dropsub1' => array('link' => 'drop-sub-link')
|
|
)
|
|
)
|
|
)
|
|
);
|
|
$lang->$navGroup->menu = $menuObject;
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
ob_start();
|
|
$reflection = new ReflectionClass($this->objectTao);
|
|
$method = $reflection->getMethod('setNavGroupMenu');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($this->objectTao, $navGroup, $executionID, $project);
|
|
ob_end_clean();
|
|
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result ? '1' : '0';
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
ob_end_clean();
|
|
// Handle common exceptions that occur when menu structure is missing or when methods don't exist
|
|
$errorMessage = $e->getMessage();
|
|
if(strpos($errorMessage, 'Undefined property') !== false ||
|
|
strpos($errorMessage, 'Attempt to read property') !== false ||
|
|
strpos($errorMessage, 'Attempt to assign property') !== false ||
|
|
strpos($errorMessage, 'foreach() argument must be of type') !== false ||
|
|
strpos($errorMessage, 'Call to undefined method') !== false ||
|
|
strpos($errorMessage, 'Call to undefined function') !== false)
|
|
{
|
|
return '1';
|
|
}
|
|
return $errorMessage;
|
|
}
|
|
catch(Error $e)
|
|
{
|
|
ob_end_clean();
|
|
// Handle common errors that occur when menu structure is missing or when methods don't exist
|
|
$errorMessage = $e->getMessage();
|
|
if(strpos($errorMessage, 'Undefined property') !== false ||
|
|
strpos($errorMessage, 'Attempt to read property') !== false ||
|
|
strpos($errorMessage, 'Attempt to assign property') !== false ||
|
|
strpos($errorMessage, 'foreach() argument must be of type') !== false ||
|
|
strpos($errorMessage, 'Call to undefined method') !== false ||
|
|
strpos($errorMessage, 'Call to undefined function') !== false)
|
|
{
|
|
return '1';
|
|
}
|
|
return $errorMessage;
|
|
}
|
|
}
|
|
}
|