2572 lines
99 KiB
PHP
Executable File
2572 lines
99 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* The model file of test task module of ZenTaoPMS.
|
|
*
|
|
* @copyright Copyright 2009-2015 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
|
|
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
|
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
|
|
* @package testtask
|
|
* @version $Id: model.php 5114 2013-07-12 06:02:59Z chencongzhi520@gmail.com $
|
|
* @link http://www.zentao.net
|
|
*/
|
|
?>
|
|
<?php
|
|
class testtaskModel extends model
|
|
{
|
|
/**
|
|
* 创建一个测试单。
|
|
* Create a test task.
|
|
*
|
|
* @param object $testtask
|
|
* @access public
|
|
* @return int|false
|
|
*/
|
|
function create(object $testtask): int|false
|
|
{
|
|
$this->dao->insert(TABLE_TESTTASK)->data($testtask)
|
|
->autoCheck($skipFields = 'begin,end')
|
|
->batchcheck($this->config->testtask->create->requiredFields, 'notempty')
|
|
->checkIF(!empty($testtask->begin) && $testtask->begin != '', 'begin', 'date')
|
|
->checkIF(!empty($testtask->end) && $testtask->end != '', 'end', 'date')
|
|
->checkIF(!empty($testtask->begin) && $testtask->begin != '', 'end', 'ge', zget($testtask, 'begin', ''))
|
|
->checkFlow()
|
|
->exec();
|
|
|
|
if(dao::isError()) return false;
|
|
|
|
$taskID = $this->dao->lastInsertID();
|
|
$this->loadModel('action')->create('testtask', $taskID, 'opened');
|
|
|
|
return $taskID;
|
|
}
|
|
|
|
/**
|
|
* Get test tasks of a product.
|
|
*
|
|
* @param int $productID
|
|
* @param string $branch
|
|
* @param string $type
|
|
* @param string $begin
|
|
* @param string $end
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getProductTasks(int $productID, string $branch = 'all', string $type = '', string $begin = '', string $end = '', string $orderBy = 'id_desc', object $pager = null): array
|
|
{
|
|
$scopeAndStatus = explode(',', $type);
|
|
$scope = !empty($scopeAndStatus[0]) ? $scopeAndStatus[0] : '';
|
|
$status = !empty($scopeAndStatus[1]) ? $scopeAndStatus[1] : '';
|
|
$branch = $scope == 'all' ? 'all' : $branch;
|
|
|
|
$tasks = $this->fetchTesttaskList($productID, $branch, 0, '', $scope, $status, $begin, $end, $orderBy, $pager);
|
|
|
|
foreach($tasks as $taskID => $task)
|
|
{
|
|
if($task->multiple)
|
|
{
|
|
if($task->projectName and $task->executionName)
|
|
{
|
|
$task->executionName = $task->projectName . '/' . $task->executionName;
|
|
}
|
|
elseif(!$task->executionName)
|
|
{
|
|
$task->executionName = $task->projectName;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $tasks;
|
|
}
|
|
|
|
/**
|
|
* 获取产品对应的单元测试类型的测试单。
|
|
* Get product unit tasks.
|
|
*
|
|
* @param int $productID
|
|
* @param string $browseType
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getProductUnitTasks(int $productID, string $browseType = 'newest', string $orderBy = 'id_desc', object $pager = null): array
|
|
{
|
|
$begin = '';
|
|
$end = '';
|
|
$beginAndEnd = $this->loadModel('action')->computeBeginAndEnd($browseType);
|
|
if($browseType != 'all' and $browseType != 'newest' and !empty($beginAndEnd))
|
|
{
|
|
$begin = $beginAndEnd['begin'];
|
|
$end = $beginAndEnd['end'];
|
|
}
|
|
if($browseType == 'newest') $orderBy = 'end_desc,' . $orderBy;
|
|
|
|
$projectID = $this->lang->navGroup->testtask != 'qa' ? $this->session->project : 0;
|
|
$tasks = $this->fetchTesttaskList($productID, '', 0, 'unit', 'local', '', $begin, $end, $orderBy, $pager);
|
|
|
|
$resultGroups = $this->dao->select('t1.task, t2.*')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_TESTRESULT)->alias('t2')->on('t1.id=t2.run')
|
|
->where('t1.task')->in(array_keys($tasks))
|
|
->fetchGroup('task', 'run');
|
|
|
|
/* 计算本测试单执行的用例数、成功数、失败数。 */
|
|
foreach($tasks as $taskID => $task)
|
|
{
|
|
$results = zget($resultGroups, $taskID, array());
|
|
|
|
$task->caseCount = count($results);
|
|
$task->passCount = 0;
|
|
$task->failCount = 0;
|
|
foreach($results as $result)
|
|
{
|
|
if($result->caseResult == 'pass') $task->passCount ++;
|
|
if($result->caseResult == 'fail') $task->failCount ++;
|
|
}
|
|
|
|
if($task->multiple)
|
|
{
|
|
if($task->projectName and $task->executionName)
|
|
{
|
|
$task->executionName = $task->projectName . '/' . $task->executionName;
|
|
}
|
|
elseif(!$task->executionName)
|
|
{
|
|
$task->executionName = $task->projectName;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $tasks;
|
|
}
|
|
|
|
/**
|
|
* Get test tasks of a project.
|
|
*
|
|
* @param int $projectID
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getProjectTasks($projectID, $orderBy = 'id_desc', $pager = null)
|
|
{
|
|
$tasks = $this->dao->select('t1.*, t5.multiple, IF(t4.shadow = 1, t5.name, t4.name) AS productName, t3.name as executionName, t2.name AS buildName, t2.branch AS branch, t5.name AS projectName')
|
|
->from(TABLE_TESTTASK)->alias('t1')
|
|
->leftJoin(TABLE_BUILD)->alias('t2')->on('t1.build = t2.id')
|
|
->leftJoin(TABLE_EXECUTION)->alias('t3')->on('t1.execution = t3.id')
|
|
->leftJoin(TABLE_PRODUCT)->alias('t4')->on('t1.product = t4.id')
|
|
->leftJoin(TABLE_PROJECT)->alias('t5')->on('t3.project = t5.id')
|
|
->where('t1.project')->eq((int)$projectID)
|
|
->andWhere('t1.auto')->ne('unit')
|
|
->andWhere('t1.deleted')->eq(0)
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll('id');
|
|
|
|
foreach($tasks as $taskID => $task)
|
|
{
|
|
if($task->multiple)
|
|
{
|
|
if($task->projectName and $task->executionName)
|
|
{
|
|
$tasks[$taskID]->executionName = $task->projectName . '/' . $task->executionName;
|
|
}
|
|
elseif(!$task->executionName)
|
|
{
|
|
$tasks[$taskID]->executionName = $task->projectName;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $tasks;
|
|
}
|
|
|
|
/**
|
|
* Get test tasks of a execution.
|
|
*
|
|
* @param int $executionID
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getExecutionTasks($executionID, $objectType = 'execution', $orderBy = 'id_desc', $pager = null)
|
|
{
|
|
return $this->dao->select('t1.*, t2.name AS buildName, t3.name AS productName')
|
|
->from(TABLE_TESTTASK)->alias('t1')
|
|
->leftJoin(TABLE_BUILD)->alias('t2')->on('t1.build = t2.id')
|
|
->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t1.product = t3.id')
|
|
->where('t1.deleted')->eq(0)
|
|
->beginIF($objectType == 'execution')->andWhere('t1.execution')->eq((int)$executionID)->fi()
|
|
->beginIF($objectType == 'project')->andWhere('t1.project')->eq((int)$executionID)->fi()
|
|
->andWhere('t1.auto')->ne('unit')
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll('id');
|
|
}
|
|
|
|
/**
|
|
* 获取测试单键值对。
|
|
* Get key-value pairs of testtask.
|
|
*
|
|
* @param int $productID
|
|
* @param int $executionID
|
|
* @param string|array $appendIdList
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getPairs(int $productID, int $executionID = 0, string|array $appendIdList = ''): array
|
|
{
|
|
$pairs = $this->dao->select('id, name')->from(TABLE_TESTTASK)
|
|
->where('deleted')->eq('0')
|
|
->andWhere('product')->eq($productID)
|
|
->beginIF($executionID)->andWhere('execution')->eq($executionID)->fi()
|
|
->andWhere('auto')->ne('unit')
|
|
->orderBy('id_desc')
|
|
->fetchPairs();
|
|
|
|
if($appendIdList) $pairs += $this->dao->select('id, name')->from(TABLE_TESTTASK)->where('id')->in($appendIdList)->andWhere('auto')->ne('unit')->fetchPairs();
|
|
|
|
return $pairs;
|
|
}
|
|
|
|
/**
|
|
* Get task by idList.
|
|
*
|
|
* @param array $idList
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getByList($idList)
|
|
{
|
|
return $this->dao->select('*')->from(TABLE_TESTTASK)->where('id')->in($idList)->fetchAll('id');
|
|
}
|
|
|
|
/**
|
|
* 根据ID获取单条测试单的数据。
|
|
* Get test task info by id.
|
|
*
|
|
* @param int $taskID
|
|
* @param bool $setImgSize
|
|
* @access public
|
|
* @return object|false
|
|
*/
|
|
public function getByID(int $testtaskID, bool $setImgSize = false): object|false
|
|
{
|
|
$testtask = $this->dao->select('*')->from(TABLE_TESTTASK)->where('id')->eq($testtaskID)->fetch();
|
|
if($testtask)
|
|
{
|
|
$product = $this->dao->select('name,type')->from(TABLE_PRODUCT)->where('id')->eq($testtask->product)->fetch();
|
|
$testtask->productName = $product->name;
|
|
$testtask->productType = $product->type;
|
|
$testtask->branch = 0;
|
|
$testtask->executionName = '';
|
|
$testtask->buildName = '';
|
|
|
|
if($testtask->execution)
|
|
{
|
|
$testtask->executionName = $this->dao->select('name')->from(TABLE_EXECUTION)->where('id')->eq($testtask->execution)->fetch('name');
|
|
$testtask->branch = $this->dao->select('branch')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($testtask->execution)->andWhere('product')->eq($testtask->product)->fetch('branch');
|
|
}
|
|
|
|
if($testtask->build)
|
|
{
|
|
$build = $this->dao->select('branch,name')->from(TABLE_BUILD)->where('id')->eq($testtask->build)->fetch();
|
|
$testtask->buildName = zget($build, 'name', '');
|
|
$testtask->branch = zget($build, 'branch', '');
|
|
}
|
|
}
|
|
|
|
if(!$testtask) return false;
|
|
|
|
$testtask = $this->loadModel('file')->replaceImgURL($testtask, 'desc');
|
|
if($setImgSize) $testtask->desc = $this->loadModel('file')->setImgSize($testtask->desc);
|
|
$testtask->files = $this->loadModel('file')->getByObject('testtask', $testtask->id);
|
|
return $testtask;
|
|
}
|
|
|
|
/**
|
|
* Get test tasks by user.
|
|
*
|
|
* @param string $account
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getByUser($account, $pager = null, $orderBy = 'id_desc', $type = '')
|
|
{
|
|
return $this->dao->select("t1.*, t2.name AS executionName, t2.multiple AS executionMultiple, t5.name AS projectName, t3.name AS buildName, t4.name AS productName")
|
|
->from(TABLE_TESTTASK)->alias('t1')
|
|
->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.execution = t2.id')
|
|
->leftJoin(TABLE_BUILD)->alias('t3')->on('t1.build = t3.id')
|
|
->leftJoin(TABLE_PRODUCT)->alias('t4')->on('t1.product = t4.id')
|
|
->leftJoin(TABLE_PROJECT)->alias('t5')->on('t2.project = t5.id')
|
|
->where('t1.deleted')->eq(0)
|
|
->andWhere('t4.deleted')->eq(0)
|
|
->andWhere('t1.auto')->ne('unit')
|
|
->andWhere('t1.owner')->eq($account)
|
|
->andWhere('t2.id')->in($this->app->user->view->sprints)
|
|
->beginIF($type == 'wait')->andWhere('t1.status')->ne('done')->fi()
|
|
->beginIF($type == 'done')->andWhere('t1.status')->eq('done')->fi()
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Get taskrun by case id.
|
|
*
|
|
* @param int $taskID
|
|
* @param int $caseID
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function getRunByCase($taskID, $caseID)
|
|
{
|
|
return $this->dao->select('*')->from(TABLE_TESTRUN)->where('task')->eq($taskID)->andWhere('`case`')->eq($caseID)->fetch();
|
|
}
|
|
|
|
/**
|
|
* Get linkable casses.
|
|
*
|
|
* @param int $productID
|
|
* @param object $task
|
|
* @param int $taskID
|
|
* @param string $type
|
|
* @param string $param
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getLinkableCases($productID, $task, $taskID, $type, $param, $pager)
|
|
{
|
|
if($this->session->testcaseQuery == false) $this->session->set('testcaseQuery', ' 1 = 1');
|
|
$query = $this->session->testcaseQuery;
|
|
$allProduct = "`product` = 'all'";
|
|
if(strpos($query, '`product` =') === false && $type != 'bysuite') $query .= " AND `product` = $productID";
|
|
if(strpos($query, $allProduct) !== false) $query = str_replace($allProduct, '1', $query);
|
|
|
|
$cases = array();
|
|
$linkedCases = $this->dao->select('`case`')->from(TABLE_TESTRUN)->where('task')->eq($taskID)->fetchPairs('case');
|
|
if($type == 'all') $cases = $this->getAllLinkableCases($task, $query, $linkedCases, $pager);
|
|
if($type == 'bystory') $cases = $this->getLinkableCasesByStory($productID, $task, $query, $linkedCases, $pager);
|
|
if($type == 'bybug') $cases = $this->getLinkableCasesByBug($productID, $task, $query, $linkedCases, $pager);
|
|
if($type == 'bysuite') $cases = $this->getLinkableCasesBySuite($productID, $task, $query, $param, $linkedCases, $pager);
|
|
if($type == 'bybuild') $cases = $this->getLinkableCasesByTestTask($param, $linkedCases, $query, $pager);
|
|
|
|
return $cases;
|
|
}
|
|
|
|
/**
|
|
* Get all linkable cases.
|
|
*
|
|
* @param object $task
|
|
* @param string $query
|
|
* @param array $linkedCases
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getAllLinkableCases($task, $query, $linkedCases, $pager)
|
|
{
|
|
return $this->dao->select('*')->from(TABLE_CASE)->where($query)
|
|
->beginIF(!empty($linkedCases))->andWhere('id')->notIN($linkedCases)->fi()
|
|
->andWhere('status')->ne('wait')
|
|
->andWhere('type')->ne('unit')
|
|
->beginIF($task->branch !== '')->andWhere('branch')->in("0,$task->branch")->fi()
|
|
->andWhere('deleted')->eq(0)
|
|
->orderBy('id desc')
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* Get linkable cases by story.
|
|
*
|
|
* @param int $productID
|
|
* @param object $task
|
|
* @param string $query
|
|
* @param array $linkedCases
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getLinkableCasesByStory($productID, $task, $query, $linkedCases, $pager)
|
|
{
|
|
$stories = $this->dao->select('stories')->from(TABLE_BUILD)->where('id')->eq($task->build)->fetch('stories');
|
|
$cases = array();
|
|
$query = preg_replace('/`(\w+)`/', 't1.`$1`', $query);
|
|
if($stories)
|
|
{
|
|
$cases = $this->dao->select('t1.*,t2.title as storyTitle')->from(TABLE_CASE)->alias('t1')
|
|
->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id')
|
|
->where($query)
|
|
->beginIF($this->lang->navGroup->testtask != 'qa')->andWhere('t1.project')->eq($this->session->project)->fi()
|
|
->andWhere('t1.product')->eq($productID)
|
|
->andWhere('t1.status')->ne('wait')
|
|
->beginIF(!empty($linkedCases))->andWhere('t1.id')->notIN($linkedCases)->fi()
|
|
->beginIF($task->branch !== '')->andWhere('t1.branch')->in("0,$task->branch")->fi()
|
|
->andWhere('t1.story')->in(trim($stories, ','))
|
|
->andWhere('t1.deleted')->eq(0)
|
|
->orderBy('t1.id desc')
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
return $cases;
|
|
}
|
|
|
|
/**
|
|
* Get linkable cases by bug.
|
|
*
|
|
* @param int $productID
|
|
* @param object $task
|
|
* @param string $query
|
|
* @param array $linkedCases
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getLinkableCasesByBug($productID, $task, $query, $linkedCases, $pager)
|
|
{
|
|
$bugs = $this->dao->select('bugs')->from(TABLE_BUILD)->where('id')->eq($task->build)->fetch('bugs');
|
|
$cases = array();
|
|
if($bugs)
|
|
{
|
|
$cases = $this->dao->select('*')->from(TABLE_CASE)->where($query)
|
|
->beginIF($this->lang->navGroup->testtask != 'qa')->andWhere('project')->eq($this->session->project)->fi()
|
|
->andWhere('product')->eq($productID)
|
|
->andWhere('status')->ne('wait')
|
|
->beginIF($linkedCases)->andWhere('id')->notIN($linkedCases)->fi()
|
|
->beginIF($task->branch !== '')->andWhere('branch')->in("0,$task->branch")->fi()
|
|
->andWhere('fromBug')->in(trim($bugs, ','))
|
|
->andWhere('deleted')->eq(0)
|
|
->orderBy('id desc')
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
return $cases;
|
|
}
|
|
|
|
/**
|
|
* Get linkable cases by suite.
|
|
*
|
|
* @param int $productID
|
|
* @param object $task
|
|
* @param string $query
|
|
* @param string $suite
|
|
* @param array $linkedCases
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getLinkableCasesBySuite($productID, $task, $query, $suite, $linkedCases, $pager)
|
|
{
|
|
if(strpos($query, '`product`') !== false) $query = str_replace('`product`', 't1.`product`', $query);
|
|
return $this->dao->select('t1.*,t2.version as version')->from(TABLE_CASE)->alias('t1')
|
|
->leftJoin(TABLE_SUITECASE)->alias('t2')->on('t1.id=t2.case')
|
|
->where($query)
|
|
->beginIF($this->lang->navGroup->testtask != 'qa')->andWhere('t1.project')->eq($this->session->project)->fi()
|
|
->andWhere('t2.suite')->eq((int)$suite)
|
|
->andWhere('t1.product')->eq($productID)
|
|
->andWhere('status')->ne('wait')
|
|
->beginIF($linkedCases)->andWhere('t1.id')->notIN($linkedCases)->fi()
|
|
->beginIF($task->branch !== '')->andWhere('t1.branch')->in("0,$task->branch")->fi()
|
|
->andWhere('deleted')->eq(0)
|
|
->orderBy('id desc')
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* Get linkeable cases by test task.
|
|
*
|
|
* @param string $testTask
|
|
* @param array $linkedCases
|
|
* @param string $query
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getLinkableCasesByTestTask($testTask, $linkedCases, $query, $pager)
|
|
{
|
|
/* Format the query condition. */
|
|
$query = preg_replace('/`(\w+)`/', 't1.`$1`', $query);
|
|
$query = str_replace('t1.`lastRunner`', 't2.`lastRunner`', $query);
|
|
$query = str_replace('t1.`lastRunDate`', 't2.`lastRunDate`', $query);
|
|
$query = str_replace('t1.`lastRunResult`', 't2.`lastRunResult`', $query);
|
|
|
|
return $this->dao->select("t1.*,t2.lastRunner,t2.lastRunDate,t2.lastRunResult")->from(TABLE_CASE)->alias('t1')
|
|
->leftJoin(TABLE_TESTRUN)->alias('t2')->on('t1.id = t2.case')
|
|
->where($query)
|
|
->andWhere('t1.id')->notin($linkedCases)
|
|
->andWhere('t2.task')->eq($testTask)
|
|
->beginIF($this->lang->navGroup->testtask != 'qa')->andWhere('t1.project')->eq($this->session->project)->fi()
|
|
->andWhere('t1.status')->ne('wait')
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* Get related test tasks.
|
|
*
|
|
* @param int $productID
|
|
* @param int $testtaskID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getRelatedTestTasks($productID, $testTaskID)
|
|
{
|
|
$beginDate = $this->dao->select('begin')->from(TABLE_TESTTASK)->where('id')->eq($testTaskID)->fetch('begin');
|
|
|
|
return $this->dao->select('id, name')->from(TABLE_TESTTASK)
|
|
->where('product')->eq($productID)
|
|
->andWhere('auto')->ne('unit')
|
|
->beginIF($beginDate)->andWhere('begin')->le($beginDate)->fi()
|
|
->andWhere('deleted')->eq('0')
|
|
->andWhere('id')->notin($testTaskID)
|
|
->orderBy('begin desc')
|
|
->fetchPairs('id', 'name');
|
|
}
|
|
|
|
/**
|
|
* Get report data of test task per run result.
|
|
*
|
|
* @param int $taskID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getDataOfTestTaskPerRunResult($taskID)
|
|
{
|
|
$datas = $this->dao->select("t1.lastRunResult AS name, COUNT('t1.*') AS value")->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')
|
|
->on('t1.case = t2.id')
|
|
->where('t1.task')->eq($taskID)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->groupBy('t1.lastRunResult')
|
|
->orderBy('value DESC')
|
|
->fetchAll('name');
|
|
|
|
if(!$datas) return array();
|
|
|
|
$this->app->loadLang('testcase');
|
|
foreach($datas as $result => $data) $data->name = isset($this->lang->testcase->resultList[$result])? $this->lang->testcase->resultList[$result] : $this->lang->testtask->unexecuted;
|
|
|
|
return $datas;
|
|
}
|
|
|
|
/**
|
|
* Get report data of test task per Type.
|
|
*
|
|
* @param int $taskID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getDataOfTestTaskPerType($taskID)
|
|
{
|
|
$datas = $this->dao->select('t2.type as name,count(*) as value')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->where('t1.task')->eq($taskID)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->groupBy('t2.type')
|
|
->orderBy('value desc')
|
|
->fetchAll('name');
|
|
if(!$datas) return array();
|
|
|
|
foreach($datas as $result => $data) if(isset($this->lang->testcase->typeList[$result])) $data->name = $this->lang->testcase->typeList[$result];
|
|
|
|
return $datas;
|
|
}
|
|
|
|
/**
|
|
* Get report data of test task per module
|
|
*
|
|
* @param int $taskID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getDataOfTestTaskPerModule($taskID)
|
|
{
|
|
$datas = $this->dao->select('t2.module as name,count(*) as value')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->where('t1.task')->eq($taskID)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->groupBy('t2.module')
|
|
->orderBy('value desc')
|
|
->fetchAll('name');
|
|
if(!$datas) return array();
|
|
|
|
$modules = $this->loadModel('tree')->getModulesName(array_keys($datas));
|
|
foreach($datas as $moduleID => $data) $data->name = isset($modules[$moduleID]) ? $modules[$moduleID] : '/';
|
|
|
|
return $datas;
|
|
}
|
|
|
|
/**
|
|
* Get report data of test task per runner
|
|
*
|
|
* @param int $taskID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getDataOfTestTaskPerRunner($taskID)
|
|
{
|
|
$datas = $this->dao->select("t1.lastRunner AS name, COUNT('t1.*') AS value")->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->where('t1.task')->eq($taskID)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->groupBy('t1.lastRunner')
|
|
->orderBy('value DESC')
|
|
->fetchAll('name');
|
|
if(!$datas) return array();
|
|
$users = $this->loadModel('user')->getPairs('noclosed|noletter');
|
|
foreach($datas as $result => $data) $data->name = $result ? zget($users, $result, $result) : $this->lang->testtask->unexecuted;
|
|
|
|
return $datas;
|
|
}
|
|
|
|
/**
|
|
* Get bug info.
|
|
*
|
|
* @param int $taskID
|
|
* @param int $productID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getBugInfo($taskID, $productID)
|
|
{
|
|
$foundBugs = $this->dao->select('*')->from(TABLE_BUG)->where('product')->in($productID)->andWhere('testtask')->eq($taskID)->andWhere('deleted')->eq(0)->fetchAll();
|
|
|
|
$severityGroups = $statusGroups = $openedByGroups = $resolvedByGroups = $resolutionGroups = $moduleGroups = array();
|
|
$resolvedBugs = 0;
|
|
foreach($foundBugs as $bug)
|
|
{
|
|
$severityGroups[$bug->severity] = isset($severityGroups[$bug->severity]) ? $severityGroups[$bug->severity] + 1 : 1;
|
|
$statusGroups[$bug->status] = isset($statusGroups[$bug->status]) ? $statusGroups[$bug->status] + 1 : 1;
|
|
$openedByGroups[$bug->openedBy] = isset($openedByGroups[$bug->openedBy]) ? $openedByGroups[$bug->openedBy] + 1 : 1;
|
|
$moduleGroups[$bug->module] = isset($moduleGroups[$bug->module]) ? $moduleGroups[$bug->module] + 1 : 1;
|
|
|
|
if($bug->resolvedBy) $resolvedByGroups[$bug->resolvedBy] = isset($resolvedByGroups[$bug->resolvedBy]) ? $resolvedByGroups[$bug->resolvedBy] + 1 : 1;
|
|
if($bug->resolution) $resolutionGroups[$bug->resolution] = isset($resolutionGroups[$bug->resolution]) ? $resolutionGroups[$bug->resolution] + 1 : 1;
|
|
if($bug->status == 'resolved' or $bug->status == 'closed') $resolvedBugs ++;
|
|
}
|
|
|
|
$bugInfo['bugConfirmedRate'] = empty($resolvedBugs) ? 0 : round((zget($resolutionGroups, 'fixed', 0) + zget($resolutionGroups, 'postponed', 0)) / $resolvedBugs * 100, 2);
|
|
$bugInfo['bugCreateByCaseRate'] = empty($byCaseNum) ? 0 : round($byCaseNum / count($foundBugs) * 100, 2);
|
|
|
|
$this->app->loadLang('bug');
|
|
$users = $this->loadModel('user')->getPairs('noclosed|noletter|nodeleted');
|
|
$data = array();
|
|
foreach($severityGroups as $severity => $count)
|
|
{
|
|
$data[$severity] = new stdclass();
|
|
$data[$severity]->name = zget($this->lang->bug->severityList, $severity);
|
|
$data[$severity]->value = $count;
|
|
}
|
|
$bugInfo['bugSeverityGroups'] = $data;
|
|
|
|
$data = array();
|
|
foreach($statusGroups as $status => $count)
|
|
{
|
|
$data[$status] = new stdclass();
|
|
$data[$status]->name = zget($this->lang->bug->statusList, $status);
|
|
$data[$status]->value = $count;
|
|
}
|
|
$bugInfo['bugStatusGroups'] = $data;
|
|
|
|
$data = array();
|
|
foreach($resolutionGroups as $resolution => $count)
|
|
{
|
|
$data[$resolution] = new stdclass();
|
|
$data[$resolution]->name = zget($this->lang->bug->resolutionList, $resolution);
|
|
$data[$resolution]->value = $count;
|
|
}
|
|
$bugInfo['bugResolutionGroups'] = $data;
|
|
|
|
$data = array();
|
|
foreach($openedByGroups as $openedBy => $count)
|
|
{
|
|
$data[$openedBy] = new stdclass();
|
|
$data[$openedBy]->name = zget($users, $openedBy);
|
|
$data[$openedBy]->value = $count;
|
|
}
|
|
$bugInfo['bugOpenedByGroups'] = $data;
|
|
|
|
$this->loadModel('tree');
|
|
$modules = $this->tree->getOptionMenu($productID, $viewType = 'bug');
|
|
$data = array();
|
|
foreach($moduleGroups as $moduleID => $count)
|
|
{
|
|
$data[$moduleID] = new stdclass();
|
|
$data[$moduleID]->name = zget($modules, $moduleID);
|
|
$data[$moduleID]->value = $count;
|
|
}
|
|
$bugInfo['bugModuleGroups'] = $data;
|
|
|
|
$data = array();
|
|
foreach($resolvedByGroups as $resolvedBy => $count)
|
|
{
|
|
$data[$resolvedBy] = new stdclass();
|
|
$data[$resolvedBy]->name = zget($users, $resolvedBy);
|
|
$data[$resolvedBy]->value = $count;
|
|
}
|
|
$bugInfo['bugResolvedByGroups'] = $data;
|
|
|
|
return $bugInfo;
|
|
}
|
|
|
|
/**
|
|
* Merge the default chart settings and the settings of current chart.
|
|
*
|
|
* @param string $chartType
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function mergeChartOption($chartType)
|
|
{
|
|
$chartOption = isset($this->lang->testtask->report->$chartType) ? $this->lang->testtask->report->$chartType : new stdclass();
|
|
$commonOption = $this->lang->testtask->report->options;
|
|
|
|
if(!isset($chartOption->graph)) $chartOption->graph = new stdclass();
|
|
$chartOption->graph->caption = $this->lang->testtask->report->charts[$chartType];
|
|
if(!isset($chartOption->type)) $chartOption->type = $commonOption->type;
|
|
if(!isset($chartOption->width)) $chartOption->width = $commonOption->width;
|
|
if(!isset($chartOption->height)) $chartOption->height = $commonOption->height;
|
|
|
|
/* 合并配置。*/
|
|
foreach($commonOption->graph as $key => $value) if(!isset($chartOption->graph->$key)) $chartOption->graph->$key = $value;
|
|
return $chartOption;
|
|
}
|
|
|
|
/**
|
|
* 更新测试单。
|
|
* Update a test task.
|
|
*
|
|
* @param object $task
|
|
* @access public
|
|
* @return array|bool
|
|
*/
|
|
public function update(object $task, object $oldTask): array|bool
|
|
{
|
|
$this->dao->update(TABLE_TESTTASK)->data($task, 'deleteFiles')
|
|
->autoCheck()
|
|
->batchcheck($this->config->testtask->edit->requiredFields, 'notempty')
|
|
->checkIF($task->end != '', 'end', 'ge', $task->begin)
|
|
->checkFlow()
|
|
->where('id')->eq($task->id)
|
|
->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$this->loadModel('file')->processFile4Object('testtask', $oldTask, $task);
|
|
return common::createChanges($oldTask, $task);
|
|
}
|
|
|
|
/**
|
|
* 开始一个测试单。
|
|
* Start testtask.
|
|
*
|
|
* @param object $task
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function start(object $task): bool
|
|
{
|
|
$taskID = (int)$task->id;
|
|
$oldTask = $this->fetchByID($taskID);
|
|
if(!$oldTask || !self::isClickable($oldTask, 'start')) return false;
|
|
|
|
$this->dao->update(TABLE_TESTTASK)->data($task, 'comment,uid')
|
|
->autoCheck()
|
|
->checkFlow()
|
|
->where('id')->eq($taskID)
|
|
->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$changes = common::createChanges($oldTask, $task);
|
|
if($changes || $task->comment)
|
|
{
|
|
$actionID = $this->loadModel('action')->create('testtask', $taskID, 'Started', $task->comment);
|
|
$this->action->logHistory($actionID, $changes);
|
|
}
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 关闭一个测试单。
|
|
* Close a testtask.
|
|
*
|
|
* @param object $task
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function close(object $task): bool
|
|
{
|
|
$taskID = (int)$task->id;
|
|
$oldTask = $this->fetchByID($taskID);
|
|
if(!$oldTask || !self::isClickable($oldTask, 'close')) return false;
|
|
|
|
if($task->realFinishedDate <= $oldTask->begin) dao::$errors['realFinishedDate'][] = sprintf($this->lang->testtask->finishedDateLess, $oldTask->begin);
|
|
if($task->realFinishedDate > date("Y-m-d 00:00:00", strtotime("+1 day"))) dao::$errors['realFinishedDate'][] = $this->lang->testtask->finishedDateMore;
|
|
if(dao::isError()) return false;
|
|
|
|
$this->dao->update(TABLE_TESTTASK)->data($task, 'comment,uid')
|
|
->autoCheck()
|
|
->checkFlow()
|
|
->where('id')->eq($taskID)
|
|
->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$changes = common::createChanges($oldTask, $task);
|
|
if($changes || $task->comment)
|
|
{
|
|
$actionID = $this->loadModel('action')->create('testtask', $taskID, 'Closed', $task->comment);
|
|
$this->action->logHistory($actionID, $changes);
|
|
}
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 阻塞一个测试单。
|
|
* Block a testtask.
|
|
*
|
|
* @param object $task
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function block(object $task): bool
|
|
{
|
|
$taskID = (int)$task->id;
|
|
$oldTask = $this->fetchByID($taskID);
|
|
if(!$oldTask || !self::isClickable($oldTask, 'block')) return false;
|
|
|
|
$this->dao->update(TABLE_TESTTASK)->data($task, 'comment,uid')
|
|
->autoCheck()
|
|
->checkFlow()
|
|
->where('id')->eq($taskID)
|
|
->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$changes = common::createChanges($oldTask, $task);
|
|
if($changes || $task->comment)
|
|
{
|
|
$actionID = $this->loadModel('action')->create('testtask', $taskID, 'Blocked', $task->comment);
|
|
$this->action->logHistory($actionID, $changes);
|
|
}
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 激活一个测试单。
|
|
* Activate a testtask.
|
|
*
|
|
* @param object $task
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function activate(object $task): bool
|
|
{
|
|
$taskID = (int)$task->id;
|
|
$oldTask = $this->fetchByID($taskID);
|
|
if(!$oldTask || !self::isClickable($oldTask, 'activate')) return false;
|
|
|
|
$this->dao->update(TABLE_TESTTASK)->data($task, 'comment,uid')
|
|
->autoCheck()
|
|
->checkFlow()
|
|
->where('id')->eq($taskID)
|
|
->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$changes = common::createChanges($oldTask, $task);
|
|
if($changes || $task->comment)
|
|
{
|
|
$actionID = $this->loadModel('action')->create('testtask', $taskID, 'Activated', $task->comment);
|
|
$this->action->logHistory($actionID, $changes);
|
|
}
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* Link cases.
|
|
*
|
|
* @param int $taskID
|
|
* @param string $type
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function linkCase($taskID, $type)
|
|
{
|
|
if($this->post->cases == false) return;
|
|
$postData = fixer::input('post')->get();
|
|
|
|
if($type == 'bybuild') $assignedToPairs = $this->dao->select('`case`, assignedTo')->from(TABLE_TESTRUN)->where('`case`')->in($postData)->fetchPairs('case', 'assignedTo');
|
|
foreach($postData->cases as $caseID)
|
|
{
|
|
$row = new stdclass();
|
|
$row->task = $taskID;
|
|
$row->case = $caseID;
|
|
$row->version = $postData->versions[$caseID];
|
|
$row->assignedTo = '';
|
|
$row->status = 'normal';
|
|
if($type == 'bybuild') $row->assignedTo = zget($assignedToPairs, $caseID, '');
|
|
$this->dao->replace(TABLE_TESTRUN)->data($row)->exec();
|
|
|
|
/* When the cases linked the testtask, the cases link to the project. */
|
|
if($this->app->tab != 'qa')
|
|
{
|
|
$projectID = $this->app->tab == 'project' ? $this->session->project : $this->session->execution;
|
|
$lastOrder = (int)$this->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($projectID)->orderBy('order_desc')->limit(1)->fetch('order');
|
|
|
|
$data = new stdclass();
|
|
$data->project = $projectID;
|
|
$data->product = $this->session->product;
|
|
$data->case = $caseID;
|
|
$data->version = 1;
|
|
$data->order = ++ $lastOrder;
|
|
$this->dao->replace(TABLE_PROJECTCASE)->data($data)->exec();
|
|
}
|
|
$this->loadModel('action')->create('case', $caseID, 'linked2testtask', '', $taskID);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 从测试单移除一个用例。
|
|
* Remove a case from a testtask.
|
|
*
|
|
* @param int $runID
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function unlinkCase(int $runID): bool
|
|
{
|
|
$run = $this->dao->select('t1.task,t1.`case`,t2.story')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id')
|
|
->where('t1.id')->eq($runID)
|
|
->fetch();
|
|
if(!$run) return false;
|
|
|
|
$linkedProjects = $run->story ? $this->dao->select('project')->from(TABLE_PROJECTSTORY)->where('story')->eq($run->story)->fetchPairs() : array();
|
|
if($linkedProjects) $this->dao->delete()->from(TABLE_PROJECTCASE)->where('`case`')->eq($run->case)->andWhere('project')->notin($linkedProjects)->exec();
|
|
|
|
$this->dao->delete()->from(TABLE_TESTRUN)->where('id')->eq($runID)->exec();
|
|
$this->loadModel('action')->create('case' ,$run->case, 'unlinkedfromtesttask', '', $run->task);
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 批量从测试单移除用例。
|
|
* Batch remove cases from a testtask.
|
|
*
|
|
* @param int $taskID
|
|
* @param array $caseIdList
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function batchUnlinkCases(int $taskID, array $caseIdList): bool
|
|
{
|
|
if(!$taskID || !$caseIdList) return false;
|
|
|
|
$cases = $this->dao->select('`case`')->from(TABLE_TESTRUN)->where('task')->eq($taskID)->andWhere('`case`')->in($caseIdList)->fetchPairs();
|
|
if(!$cases) return false;
|
|
|
|
$this->dao->delete()->from(TABLE_TESTRUN)->where('task')->eq($taskID)->andWhere('`case`')->in($cases)->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$this->loadModel('action');
|
|
foreach($cases as $caseID) $this->action->create('case', $caseID, 'unlinkedfromtesttask', '', $taskID);
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 批量指派一个测试单中的用例。
|
|
* Batch assign cases in a testtask.
|
|
*
|
|
* @param int $taskID
|
|
* @param string $account
|
|
* @param array $caseIdList
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function batchAssign(int $taskID, string $account, array $caseIdList): bool
|
|
{
|
|
if(!$taskID || !$account || !$caseIdList) return false;
|
|
|
|
$cases = $this->dao->select('`case`')->from(TABLE_TESTRUN)->where('task')->eq($taskID)->andWhere('`case`')->in($caseIdList)->fetchPairs();
|
|
if(!$cases) return false;
|
|
|
|
$this->dao->update(TABLE_TESTRUN)->set('assignedTo')->eq($account)->where('task')->eq($taskID)->andWhere('`case`')->in($cases)->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
$this->loadModel('action');
|
|
foreach($cases as $caseID) $this->action->create('case', $caseID, 'assigned', '', $account);
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 获取一个测试单关联的测试用例及相关需求。
|
|
* Get cases associated with a testtask.
|
|
*
|
|
* @param int $taskID
|
|
* @param int $moduleID
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getRuns(int $taskID, int $moduleID, string $orderBy, object $pager = null): array
|
|
{
|
|
/* Select the table for these special fields. */
|
|
$specialFields = ',assignedTo,status,lastRunResult,lastRunner,lastRunDate,';
|
|
$fieldToSort = substr($orderBy, 0, strpos($orderBy, '_'));
|
|
$orderBy = strpos($specialFields, ',' . $fieldToSort . ',') !== false ? ('t1.' . $orderBy) : ('t2.' . $orderBy);
|
|
|
|
return $this->dao->select('t2.*, t1.*, t2.version AS caseVersion, t3.title AS storyTitle, t2.status AS caseStatus')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id')
|
|
->where('t1.task')->eq($taskID)
|
|
->andWhere('t2.deleted')->eq('0')
|
|
->beginIF($moduleID)->andWhere('t2.module')->in($moduleID)->fi()
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll('id');
|
|
}
|
|
|
|
/**
|
|
* Get test runs of a suite.
|
|
*
|
|
* @param int $taskID
|
|
* @param int $suiteID
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getRunsBySuite($taskID, $suiteID, $orderBy, $pager = null)
|
|
{
|
|
/* Select the table for these special fields. */
|
|
$specialFields = ',assignedTo,status,lastRunResult,lastRunner,lastRunDate,';
|
|
$fieldToSort = substr($orderBy, 0, strpos($orderBy, '_'));
|
|
$orderBy = strpos($specialFields, ',' . $fieldToSort . ',') !== false ? ('t1.' . $orderBy) : ('t2.' . $orderBy);
|
|
|
|
$cases = $this->loadModel('testsuite')->getLinkedCasePairs($suiteID);
|
|
|
|
return $this->dao->select('t2.*,t1.*,t2.version as caseVersion,t3.title as storyTitle,t2.status as caseStatus')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id')
|
|
->where('t1.task')->eq((int)$taskID)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->andWhere('t2.id')->in(array_keys($cases))
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll('id');
|
|
}
|
|
|
|
/**
|
|
* 按照测试单分组展示用例。
|
|
* Group case run by suite.
|
|
*
|
|
* @param int $taskID
|
|
* @param string $orderBy
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function groupRunsBySuite(int $taskID, string $orderBy = 't1.id_desc', object $pager = null): array
|
|
{
|
|
return $this->dao->select('t2.*,t1.*,t2.version as caseVersion,t3.title as storyTitle,t2.status as caseStatus,t4.suite,t5.name as suiteTitle')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id')
|
|
->leftJoin(TABLE_SUITECASE)->alias('t4')->on('t1.case = t4.case')
|
|
->leftJoin(TABLE_TESTSUITE)->alias('t5')->on('t4.suite = t5.id')
|
|
->where('t1.task')->eq($taskID)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* Get test runs of a user.
|
|
*
|
|
* @param int $taskID
|
|
* @param int $user
|
|
* @param object $pager
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getUserRuns($taskID, $user, $modules = '', $orderBy = 'id_desc', $pager = null)
|
|
{
|
|
/* Select the table for these special fields. */
|
|
$specialFields = ',assignedTo,status,lastRunResult,lastRunner,lastRunDate,';
|
|
$fieldToSort = substr($orderBy, 0, strpos($orderBy, '_'));
|
|
$orderBy = strpos($specialFields, ',' . $fieldToSort . ',') !== false ? ('t1.' . $orderBy) : ('t2.' . $orderBy);
|
|
|
|
return $this->dao->select('t2.*,t1.*,t2.version as caseVersion,t3.title as storyTitle,t2.status as caseStatus')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id')
|
|
->where('t1.task')->eq((int)$taskID)
|
|
->andWhere('t1.assignedTo')->eq($user)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->beginIF($modules)->andWhere('t2.module')->in($modules)->fi()
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll('id');
|
|
}
|
|
|
|
/**
|
|
* Get testtask linked cases.
|
|
*
|
|
* @param int $productID
|
|
* @param string $browseType
|
|
* @param int $queryID
|
|
* @param int $moduleID
|
|
* @param string $sort
|
|
* @param object $pager
|
|
* @param object $task
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getTaskCases($productID, $browseType, $queryID, $moduleID, $sort, $pager, $task)
|
|
{
|
|
/* Set modules and browse type. */
|
|
$modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0';
|
|
$browseType = ($browseType == 'bymodule' and $this->session->taskCaseBrowseType and $this->session->taskCaseBrowseType != 'bysearch') ? $this->session->taskCaseBrowseType : $browseType;
|
|
$browseType = strtolower($browseType);
|
|
|
|
if($browseType == 'bymodule' or $browseType == 'all')
|
|
{
|
|
$runs = $this->getRuns($task->id, $modules, $sort, $pager);
|
|
}
|
|
elseif($browseType == 'bysuite')
|
|
{
|
|
$runs = $this->getRunsBySuite($task->id, $queryID, $sort, $pager);
|
|
}
|
|
elseif($browseType == 'assignedtome')
|
|
{
|
|
$runs = $this->getUserRuns($task->id, $this->session->user->account, $modules, $sort, $pager);
|
|
}
|
|
/* By search. */
|
|
elseif($browseType == 'bysearch')
|
|
{
|
|
if($this->session->testtaskQuery == false) $this->session->set('testtaskQuery', ' 1 = 1');
|
|
if($queryID)
|
|
{
|
|
$query = $this->loadModel('search')->getQuery($queryID);
|
|
if($query)
|
|
{
|
|
$this->session->set('testtaskQuery', $query->sql);
|
|
$this->session->set('testtaskForm', $query->form);
|
|
}
|
|
}
|
|
|
|
$queryProductID = $productID;
|
|
$allProduct = "`product` = 'all'";
|
|
$caseQuery = $this->session->testtaskQuery;
|
|
if(strpos($this->session->testtaskQuery, $allProduct) !== false)
|
|
{
|
|
$caseQuery = str_replace($allProduct, '1', $this->session->testtaskQuery);
|
|
$caseQuery = $caseQuery . ' AND `product` ' . helper::dbIN($this->app->user->view->products);
|
|
$queryProductID = 'all';
|
|
}
|
|
|
|
$caseQuery = preg_replace('/`(\w+)`/', 't2.`$1`', $caseQuery);
|
|
$caseQuery = str_replace(array('t2.`assignedTo`', 't2.`lastRunner`', 't2.`lastRunDate`', 't2.`lastRunResult`'), array('t1.`assignedTo`', 't1.`lastRunner`', 't1.`lastRunDate`', 't1.`lastRunResult`'), $caseQuery);
|
|
|
|
/* Select the table for these special fields. */
|
|
$specialFields = ',assignedTo,status,lastRunResult,lastRunner,lastRunDate,';
|
|
$fieldToSort = substr($sort, 0, strpos($sort, '_'));
|
|
$orderBy = strpos($specialFields, ',' . $fieldToSort . ',') !== false ? ('t1.' . $sort) : ('t2.' . $sort);
|
|
|
|
$runs = $this->dao->select('t2.*,t1.*, t2.version as caseVersion,t3.title as storyTitle,t2.status as caseStatus')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id')
|
|
->where($caseQuery)
|
|
->andWhere('t1.task')->eq($task->id)
|
|
->andWhere('t2.deleted')->eq(0)
|
|
->beginIF($queryProductID != 'all')->andWhere('t2.product')->eq($queryProductID)->fi()
|
|
->beginIF($task->branch)->andWhere('t2.branch')->in("0,{$task->branch}")->fi()
|
|
->orderBy($orderBy)
|
|
->page($pager)
|
|
->fetchAll('id');
|
|
}
|
|
|
|
return $runs;
|
|
}
|
|
|
|
/**
|
|
* Get testtask pairs of a user.
|
|
*
|
|
* @param string $account
|
|
* @param int $limit
|
|
* @param string $status all|wait|doing|done|blocked
|
|
* @param array $skipProductIDList
|
|
* @param array $skipExecutionIDList
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getUserTestTaskPairs($account, $limit = 0, $status = 'all', $skipProductIDList = array(), $skipExecutionIDList = array())
|
|
{
|
|
$stmt = $this->dao->select('t1.id, t1.name, t2.name as execution')
|
|
->from(TABLE_TESTTASK)->alias('t1')
|
|
->leftJoin(TABLE_EXTENSION)->alias('t2')->on('t1.execution = t2.id')
|
|
->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t1.product=t3.id')
|
|
->where('t1.owner')->eq($account)
|
|
->andWhere('t1.deleted')->eq(0)
|
|
->andWhere('t3.deleted')->eq(0)
|
|
->beginIF($status != 'all')->andWhere('t1.status')->in($status)->fi()
|
|
->beginIF(!empty($skipProductIDList))->andWhere('t1.product')->notin($skipProductIDList)->fi()
|
|
->beginIF(!empty($skipExecutionIDList))->andWhere('t1.execution')->notin($skipExecutionIDList)->fi()
|
|
->beginIF($limit)->limit($limit)->fi()
|
|
->query();
|
|
|
|
$testtaskPairs = array();
|
|
while($testtask = $stmt->fetch())
|
|
{
|
|
if($testtask->execution) $testtask->execution .= " / ";
|
|
$testtaskPairs[$testtask->id] = $testtask->execution . $testtask->name;
|
|
}
|
|
return $testtaskPairs;
|
|
}
|
|
|
|
/**
|
|
* 获取执行结果信息。
|
|
* Get information of a test run.
|
|
*
|
|
* @param int $runID
|
|
* @access public
|
|
* @return object
|
|
*/
|
|
public function getRunById(int $runID): object
|
|
{
|
|
$testRun = $this->dao->findById($runID)->from(TABLE_TESTRUN)->fetch();
|
|
$testRun->case = $this->loadModel('testcase')->getById($testRun->case, $testRun->version);
|
|
return $testRun;
|
|
}
|
|
|
|
/**
|
|
* Get testtasks by case id list.
|
|
*
|
|
* @param string|array $caseIDList
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getGroupByCases($caseIDList)
|
|
{
|
|
return $this->dao->select('t1.case, t2.*, t3.branch')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_TESTTASK)->alias('t2')->on('t1.task=t2.id')
|
|
->leftJoin(TABLE_BUILD)->alias('t3')->on('t2.build = t3.id')
|
|
->where('t1.case')->in($caseIDList)
|
|
->fetchGroup('case', 'id');
|
|
}
|
|
|
|
/**
|
|
* Init testtask result.
|
|
*
|
|
* @param int $runID
|
|
* @param int $caseID
|
|
* @param int $version
|
|
* @param int $nodeID
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function initResult($runID = 0, $caseID = 0, $version = 0, $nodeID = 0)
|
|
{
|
|
$result = new stdClass();
|
|
$result->run = $runID;
|
|
$result->case = $caseID;
|
|
$result->version = $version;
|
|
$result->node = $nodeID;
|
|
$result->date = helper::now();
|
|
$result->lastRunner = $this->app->user->account;
|
|
|
|
$this->dao->insert(TABLE_TESTRESULT)->data($result)->autoCheck()->exec();
|
|
if(!dao::isError()) return $resultID = $this->dao->lastInsertID();
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 保存一个测试用例的执行结果。
|
|
* Save the execution results of a test case.
|
|
*
|
|
* @param int $runID
|
|
* @param int $caseID
|
|
* @param int $version
|
|
* @param array $stepResults
|
|
* @access public
|
|
* @return bool|string
|
|
*/
|
|
public function createResult(int $runID = 0, int $caseID, int $version, array $stepResults): bool|string
|
|
{
|
|
/* 根据测试用例步骤的执行结果获取测试用例的执行结果。*/
|
|
/* Get the execution results of the test case based on the execution results of the test case steps. */
|
|
$caseResult = 'pass';
|
|
foreach($stepResults as $stepResult)
|
|
{
|
|
if($stepResult->result == 'fail' || $stepResult->result == 'blocked') $caseResult = $stepResult;
|
|
if($stepResult->result == 'fail') break;
|
|
}
|
|
|
|
/* 保存测试用例的执行结果。*/
|
|
/* Save the execution results of the test case. */
|
|
$now = helper::now();
|
|
$result = new stdclass();
|
|
$result->run = $runID;
|
|
$result->case = $caseID;
|
|
$result->version = $version;
|
|
$result->caseResult = $caseResult;
|
|
$result->stepResults = serialize($stepResults);
|
|
$result->lastRunner = $this->app->user->account;
|
|
$result->date = $now;
|
|
$this->dao->insert(TABLE_TESTRESULT)->data($result)->autoCheck()->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
/* 把上传的文件关联到到执行结果的用例步骤中。*/
|
|
/* Associated the uploaded files to the test case steps of the execution results. */
|
|
$resultID = $this->dao->lastInsertID();
|
|
foreach($stepResults as $stepID => $stepResult) $this->loadModel('file')->saveUpload('stepResult', $resultID, $stepID, "files{$stepID}", "labels{$stepID}");
|
|
|
|
/* 更新测试用例的执行结果。*/
|
|
/* Update the execution results of the test case. */
|
|
$case = new stdclass();
|
|
$case->lastRunner = $this->app->user->account;
|
|
$case->lastRunDate = $now;
|
|
$case->lastRunResult = $caseResult;
|
|
$this->dao->update(TABLE_CASE)->data($case)->where('id')->eq($caseID)->exec();
|
|
if(dao::isError()) return false;
|
|
|
|
if($runID)
|
|
{
|
|
/* 更新测试单中测试用例的执行结果。*/
|
|
/* Update the execution results of the test case in testtask. */
|
|
$run = new stdclass();
|
|
$run->status = $caseResult == 'blocked' ? 'blocked' : 'normal';
|
|
$run->lastRunResult = $caseResult;
|
|
$run->lastRunner = $this->app->user->account;
|
|
$run->lastRunDate = $now;
|
|
$this->dao->update(TABLE_TESTRUN)->data($run)->where('id')->eq($runID)->exec();
|
|
}
|
|
|
|
$this->loadModel('score')->create('testtask', 'runCase', $runID);
|
|
return $caseResult;
|
|
}
|
|
|
|
/**
|
|
* Batch run case
|
|
*
|
|
* @param string $runCaseType
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function batchRun($runCaseType = 'testcase', $taskID = 0)
|
|
{
|
|
$runs = array();
|
|
$postData = fixer::input('post')->get();
|
|
$caseIdList = isset($postData->caseIDList) ? array_keys($postData->caseIDList) : array_keys($postData->results);
|
|
if($runCaseType == 'testtask')
|
|
{
|
|
$runs = $this->dao->select('id, `case`')->from(TABLE_TESTRUN)
|
|
->where('`case`')->in($caseIdList)
|
|
->beginIF($taskID)->andWhere('task')->eq($taskID)->fi()
|
|
->fetchPairs('case', 'id');
|
|
}
|
|
|
|
$stepGroups = $this->dao->select('t1.*')->from(TABLE_CASESTEP)->alias('t1')
|
|
->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
|
|
->where('t1.case')->in($caseIdList)
|
|
->andWhere('t1.version=t2.version')
|
|
->andWhere('t2.status')->ne('wait')
|
|
->fetchGroup('case', 'id');
|
|
|
|
$now = helper::now();
|
|
foreach($postData->results as $caseID => $result)
|
|
{
|
|
$runID = isset($runs[$caseID]) ? $runs[$caseID] : (isset($postData->caseIDList) ? $caseID : 0);
|
|
$version = $postData->version[$caseID];
|
|
$dbSteps = isset($stepGroups[$caseID]) ? $stepGroups[$caseID] : array();
|
|
$postSteps = isset($postData->steps[$caseID]) ? $postData->steps[$caseID] : array();
|
|
$postReals = $postData->reals[$caseID];
|
|
|
|
$caseResult = $result ? $result : 'pass';
|
|
if(!empty($postData->node)) $caseResult = '';
|
|
$stepResults = array();
|
|
if($dbSteps)
|
|
{
|
|
foreach($dbSteps as $stepID => $step)
|
|
{
|
|
$step = array();
|
|
$step['result'] = $caseResult == 'pass' ? $caseResult : $postSteps[$stepID];
|
|
$step['real'] = $caseResult == 'pass' ? '' : $postReals[$stepID];
|
|
$stepResults[$stepID] = $step;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$step = array();
|
|
$step['result'] = $caseResult;
|
|
$step['real'] = $caseResult == 'pass' ? '' : $postReals[0];
|
|
$stepResults[] = $step;
|
|
}
|
|
|
|
/* Replace caseID if caseID is runID. */
|
|
if(isset($postData->caseIDList[$caseID])) $caseID = $postData->caseIDList[$caseID];
|
|
|
|
$result = new stdClass();
|
|
$result->run = $runID;
|
|
$result->case = $caseID;
|
|
$result->version = $version;
|
|
$result->caseResult = $caseResult;
|
|
$result->stepResults = serialize($stepResults);
|
|
$result->lastRunner = $this->app->user->account;
|
|
$result->date = $now;
|
|
|
|
$this->dao->insert(TABLE_TESTRESULT)->data($result)->autoCheck()->exec();
|
|
$this->dao->update(TABLE_CASE)->set('lastRunner')->eq($this->app->user->account)->set('lastRunDate')->eq($now)->set('lastRunResult')->eq($caseResult)->where('id')->eq($caseID)->exec();
|
|
|
|
if($runID)
|
|
{
|
|
/* Update testRun's status. */
|
|
if(!dao::isError())
|
|
{
|
|
$runStatus = $caseResult == 'blocked' ? 'blocked' : 'normal';
|
|
$this->dao->update(TABLE_TESTRUN)
|
|
->set('lastRunResult')->eq($caseResult)
|
|
->set('status')->eq($runStatus)
|
|
->set('lastRunner')->eq($this->app->user->account)
|
|
->set('lastRunDate')->eq($now)
|
|
->where('id')->eq($runID)
|
|
->exec();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 通过执行 ID 或用例 ID 获取用例的执行结果。
|
|
* Get results by runID or caseID
|
|
*
|
|
* @param int $runID
|
|
* @param int $caseID
|
|
* @param string $status all|done
|
|
* @param string $type all|fail
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function getResults(int $runID, int $caseID = 0, string $status = 'all', string $type = 'all'): array
|
|
{
|
|
$results = $this->dao->select('*')->from(TABLE_TESTRESULT)
|
|
->beginIF($runID > 0)->where('run')->eq($runID)->fi()
|
|
->beginIF($runID <= 0)->where('`case`')->eq($caseID)->fi()
|
|
->beginIF($status == 'done')->andWhere('caseResult')->ne('')->fi()
|
|
->beginIF($type != 'all')->andWhere('caseResult')->eq($type)->fi()
|
|
->orderBy('id desc')
|
|
->fetchAll('id');
|
|
if(!$results) return array();
|
|
|
|
list($resultFiles, $stepFiles) = $this->getResultsFiles(array_keys($results));
|
|
|
|
$runIdList = $nodeIdList = $relatedVersions = array();
|
|
foreach($results as $result)
|
|
{
|
|
$runIdList[$result->run] = $result->run;
|
|
$nodeIdList[$result->node] = $result->node;
|
|
$relatedVersions[$result->version] = $result->version;
|
|
$runCaseID = $result->case;
|
|
}
|
|
$relatedSteps = $this->dao->select('*')->from(TABLE_CASESTEP)
|
|
->where('`case`')->eq($runCaseID)
|
|
->andWhere('version')->in($relatedVersions)
|
|
->orderBy('id')
|
|
->fetchGroup('version', 'id');
|
|
$runs = $this->dao->select('t1.id,t1.task,t2.build')->from(TABLE_TESTRUN)->alias('t1')
|
|
->leftJoin(TABLE_TESTTASK)->alias('t2')->on('t1.task=t2.id')
|
|
->where('t1.id')->in($runIdList)
|
|
->fetchPairs();
|
|
$nodes = $this->dao->select('id,name')->from(TABLE_ZAHOST)->where('id')->in($nodeIdList)->fetchPairs();
|
|
|
|
foreach($results as $resultID => $result)
|
|
{
|
|
if($result->stepResults) $result->stepResults = '';
|
|
$result->stepResults = unserialize($result->stepResults);
|
|
$result->build = $result->run && !empty($runs[$result->run]->build) ? $runs[$result->run]->build : 0;
|
|
$result->task = $result->run && !empty($runs[$result->run]->task) ? $runs[$result->run]->task : 0;
|
|
$result->nodeName = zget($nodes, $result->node, '');
|
|
$result->files = zget($resultFiles, $resultID, array()); //Get files of case result.
|
|
if(isset($relatedSteps[$result->version])) $result->stepResults = $this->processResultSteps($result, $relatedSteps[$result->version]);
|
|
if(!empty($result->ZTFResult)) $result->ZTFResult = $this->formatZtfLog($result->ZTFResult, $result->stepResults);
|
|
|
|
/* Get files of step result. */
|
|
if(!empty($result->stepResults))
|
|
{
|
|
foreach(array_keys($result->stepResults) as $stepID) $result->stepResults[$stepID]['files'] = isset($stepFiles[$resultID][$stepID]) ? $stepFiles[$resultID][$stepID] : array();
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
/**
|
|
* 计算用例执行结果的步骤。
|
|
* Process steps of result.
|
|
*
|
|
* @param object $result
|
|
* @param array $relatedStep
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function processResultSteps(object $result, array $relatedStep): array
|
|
{
|
|
$this->loadModel('testcase');
|
|
|
|
$preGrade = 1;
|
|
$parentSteps = array();
|
|
$key = array(0, 0, 0);
|
|
foreach($relatedStep as $stepID => $step)
|
|
{
|
|
$parentSteps[$step->id] = $step->parent;
|
|
$grade = 1;
|
|
if(isset($parentSteps[$step->parent]))
|
|
{
|
|
$grade = isset($parentSteps[$parentSteps[$step->parent]]) ? 3 : 2;
|
|
}
|
|
|
|
if($grade > $preGrade)
|
|
{
|
|
$key[$grade - 1] = 1;
|
|
}
|
|
else
|
|
{
|
|
if($grade < $preGrade)
|
|
{
|
|
if($grade < 2) $key[1] = 0;
|
|
if($grade < 3) $key[2] = 0;
|
|
}
|
|
$key[$grade - 1] ++;
|
|
}
|
|
$name = implode('.', $key);
|
|
$name = str_replace('.0', '', $name);
|
|
|
|
$relatedStep[$stepID] = (array)$step;
|
|
$relatedStep[$stepID]['name'] = $name;
|
|
$relatedStep[$stepID]['grade'] = $grade;
|
|
$relatedStep[$stepID]['desc'] = html_entity_decode($relatedStep[$stepID]['desc']);
|
|
$relatedStep[$stepID]['expect'] = html_entity_decode($relatedStep[$stepID]['expect']);
|
|
if(isset($result->stepResults[$stepID]))
|
|
{
|
|
$relatedStep[$stepID]['result'] = $result->stepResults[$stepID]['result'];
|
|
$relatedStep[$stepID]['real'] = $result->stepResults[$stepID]['real'];
|
|
}
|
|
|
|
$preGrade = $grade;
|
|
}
|
|
return $relatedStep;
|
|
}
|
|
|
|
/**
|
|
* 获取结果的文件。
|
|
* Get files of the results.
|
|
*
|
|
* @param array $resultIdList
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getResultsFiles(array $resultIdList): array
|
|
{
|
|
$resultFiles = array();
|
|
$stepFiles = array();
|
|
$files = $this->dao->select('*')->from(TABLE_FILE)
|
|
->where("(objectType = 'caseResult' or objectType = 'stepResult')")
|
|
->andWhere('objectID')->in($resultIdList)
|
|
->andWhere('extra')->ne('editor')
|
|
->orderBy('id')
|
|
->fetchAll();
|
|
|
|
$this->loadModel('file');
|
|
foreach($files as $file)
|
|
{
|
|
$this->file->setFileWebAndRealPaths($file);
|
|
if($file->objectType == 'caseResult')
|
|
{
|
|
$resultFiles[$file->objectID][$file->id] = $file;
|
|
}
|
|
elseif($file->objectType == 'stepResult' && $file->extra !== '')
|
|
{
|
|
$stepFiles[$file->objectID][(int)$file->extra][$file->id] = $file;
|
|
}
|
|
}
|
|
|
|
return array($resultFiles, $stepFiles);
|
|
}
|
|
|
|
/**
|
|
* Format ztf log.
|
|
*
|
|
* @param string $log
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function formatZtfLog($result, $stepResults)
|
|
{
|
|
$logObj = json_decode($result);
|
|
$logs = empty($logObj->log) ? '' : $logObj->log;
|
|
if(empty($logs)) return '';
|
|
|
|
$logs = str_replace(array("\r", "\n", "\r\n"), "\n", $logs);
|
|
$logList = explode("\n", $logs);
|
|
$logHtml = "";
|
|
|
|
foreach($logList as $log)
|
|
{
|
|
$log = preg_replace("/^[\d\-:.\x20]+/", '', $log);
|
|
$log = trim($log);
|
|
if(empty($log)) continue;
|
|
|
|
$failHtml = ': <span class="result-testcase fail">' . $this->lang->testtask->fail . '</span>';
|
|
$passHtml = ': <span class="result-testcase pass">' . $this->lang->testtask->pass . '</span>';
|
|
|
|
$log = preg_replace(array("/:\x20失败/", "/:\x20fail/", "/:\x20成功/", "/:\x20pass/"), array($failHtml, $failHtml, $passHtml, $passHtml), $log);
|
|
|
|
$logHtml .= "<li>" . $log . "</li>";
|
|
}
|
|
|
|
if(!empty($stepResults))
|
|
{
|
|
$total = count($stepResults);
|
|
$failCount = $passCount = 0;
|
|
|
|
foreach($stepResults as $step)
|
|
{
|
|
if($step['result'] == 'pass')
|
|
{
|
|
$passCount++;
|
|
}
|
|
elseif($step['result'] == 'fail')
|
|
{
|
|
$failCount++;
|
|
}
|
|
}
|
|
|
|
$caseResult = $passCount ? 'pass':'fail';
|
|
$logHtml .= "<li class='result-testcase {$caseResult}'>"
|
|
. sprintf($this->lang->testtask->stepSummary, $total, $passCount, $failCount)
|
|
. "</li>";
|
|
}
|
|
|
|
return $logHtml;
|
|
}
|
|
|
|
/**
|
|
* Judge an action is clickable or not.
|
|
*
|
|
* @param object $product
|
|
* @param string $action
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public static function isClickable($testtask, $action)
|
|
{
|
|
$action = strtolower($action);
|
|
|
|
if($action == 'start') return $testtask->status == 'wait';
|
|
if($action == 'block') return ($testtask->status == 'doing' || $testtask->status == 'wait');
|
|
if($action == 'activate') return ($testtask->status == 'blocked' || $testtask->status == 'done');
|
|
if($action == 'close') return $testtask->status != 'done';
|
|
|
|
if($action == 'runcase')
|
|
{
|
|
if(isset($testtask->auto) && $testtask->auto == 'unit') return false;
|
|
if(isset($testtask->caseStatus)) return $testtask->version < $testtask->caseVersion ? $testtask->caseStatus == 'wait' : $testtask->caseStatus != 'wait';
|
|
return $testtask->status != 'wait';
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Print cell data.
|
|
*
|
|
* @param object $col
|
|
* @param object $run
|
|
* @param array $users
|
|
* @param object $task
|
|
* @param array $branches
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
public function printCell($col, $run, $users, $task, $branches, $mode = 'datatable')
|
|
{
|
|
$canBatchEdit = common::hasPriv('testcase', 'batchEdit');
|
|
$canBatchUnlink = common::hasPriv('testtask', 'batchUnlinkCases');
|
|
$canBatchAssign = common::hasPriv('testtask', 'batchAssign');
|
|
$canBatchRun = common::hasPriv('testtask', 'batchRun');
|
|
|
|
$canBatchAction = ($canBatchEdit or $canBatchUnlink or $canBatchAssign or $canBatchRun);
|
|
|
|
$canView = common::hasPriv('testcase', 'view');
|
|
$caseLink = helper::createLink('testcase', 'view', "caseID=$run->case&version=$run->version&from=testtask&taskID=$run->task");
|
|
$account = $this->app->user->account;
|
|
$id = $col->id;
|
|
$caseChanged = $run->version < $run->caseVersion;
|
|
$fromCaseID = $run->fromCaseID;
|
|
|
|
if($col->show)
|
|
{
|
|
$class = "c-$id ";
|
|
if($id == 'status') $class .= "{$run->status} status-testcase status-{$run->caseStatus}";
|
|
if($id == 'title') $class .= ' text-left';
|
|
if($id == 'id') $class .= ' cell-id';
|
|
if($id == 'lastRunResult') $class .= "result-testcase $run->lastRunResult";
|
|
if($id == 'assignedTo' && $run->assignedTo == $account) $class .= ' red';
|
|
if($id == 'actions') $class .= 'c-actions';
|
|
|
|
echo "<td class='" . $class . "'" . ($id=='title' ? "title='{$run->title}'":'') . ">";
|
|
if($this->config->edition != 'open') $this->loadModel('flow')->printFlowCell('testcase', $run, $id);
|
|
switch ($id)
|
|
{
|
|
case 'id':
|
|
if($canBatchAction)
|
|
{
|
|
echo html::checkbox('caseIDList', array($run->case => sprintf('%03d', $run->case)));
|
|
}
|
|
else
|
|
{
|
|
printf('%03d', $run->case);
|
|
}
|
|
break;
|
|
case 'pri':
|
|
echo "<span class='label-pri label-pri-" . $run->pri . "' title='" . zget($this->lang->testcase->priList, $run->pri, $run->pri) . "'>";
|
|
echo zget($this->lang->testcase->priList, $run->pri, $run->pri);
|
|
echo "</span>";
|
|
break;
|
|
case 'title':
|
|
if(!empty($branches)) echo "<span class='label label-badge label-outline'>{$branches[$run->branch]}</span>";
|
|
if($canView)
|
|
{
|
|
if($fromCaseID)
|
|
{
|
|
echo html::a($caseLink, $run->title, null, "style='color: $run->color'") . html::a(helper::createLink('testcase', 'view', "caseID=$fromCaseID"), "[<i class='icon icon-share' title='{$this->lang->testcase->fromCase}'></i>#$fromCaseID]");
|
|
}
|
|
else
|
|
{
|
|
echo html::a($caseLink, $run->title, null, "style='color: $run->color'");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "<span style='color: $run->color'>$run->title</span>";
|
|
}
|
|
break;
|
|
case 'branch':
|
|
echo $branches[$run->branch];
|
|
break;
|
|
case 'type':
|
|
echo $this->lang->testcase->typeList[$run->type];
|
|
break;
|
|
case 'stage':
|
|
foreach(explode(',', trim($run->stage, ',')) as $stage) echo $this->lang->testcase->stageList[$stage] . '<br />';
|
|
break;
|
|
case 'status':
|
|
if($run->caseStatus != 'wait' and $caseChanged)
|
|
{
|
|
echo "<span title='{$this->lang->testcase->changed}' class='warning'>{$this->lang->testcase->changed}</span>";
|
|
}
|
|
else
|
|
{
|
|
$case = new stdClass();
|
|
$case->status = $run->caseStatus;
|
|
|
|
$status = $this->processStatus('testcase', $case);
|
|
if($run->status == $status) $status = $this->processStatus('testtask', $run);
|
|
echo $status;
|
|
}
|
|
break;
|
|
case 'precondition':
|
|
echo $run->precondition;
|
|
break;
|
|
case 'keywords':
|
|
echo $run->keywords;
|
|
break;
|
|
case 'version':
|
|
echo $run->version;
|
|
break;
|
|
case 'openedBy':
|
|
echo zget($users, $run->openedBy);
|
|
break;
|
|
case 'openedDate':
|
|
echo substr($run->openedDate, 5, 11);
|
|
break;
|
|
case 'reviewedBy':
|
|
echo zget($users, $run->reviewedBy);
|
|
break;
|
|
case 'reviewedDate':
|
|
echo substr($run->reviewedDate, 5, 11);
|
|
break;
|
|
case 'lastEditedBy':
|
|
echo zget($users, $run->lastEditedBy);
|
|
break;
|
|
case 'lastEditedDate':
|
|
echo substr($run->lastEditedDate, 5, 11);
|
|
break;
|
|
case 'lastRunner':
|
|
echo zget($users, $run->lastRunner);
|
|
break;
|
|
case 'lastRunDate':
|
|
echo helper::isZeroDate($run->lastRunDate) ? '' : substr($run->lastRunDate, 5, 11);
|
|
break;
|
|
case 'lastRunResult':
|
|
$lastRunResultText = $run->lastRunResult ? zget($this->lang->testcase->resultList, $run->lastRunResult, $run->lastRunResult) : $this->lang->testcase->unexecuted;
|
|
echo $lastRunResultText;
|
|
break;
|
|
case 'story':
|
|
if($run->story and $run->storyTitle) echo html::a(helper::createLink('story', 'view', "storyID=$run->story"), $run->storyTitle);
|
|
break;
|
|
case 'assignedTo':
|
|
$btnTextClass = '';
|
|
if($run->assignedTo == $this->app->user->account) $btnTextClass = 'assigned-current';
|
|
if(!empty($run->assignedTo) and $run->assignedTo != $this->app->user->account) $btnTextClass = 'assigned-other';
|
|
echo "<span class='$btnTextClass'>" . zget($users, $run->assignedTo) . '</span>';
|
|
break;
|
|
case 'bugs':
|
|
echo (common::hasPriv('testcase', 'bugs') and $run->bugs) ? html::a(helper::createLink('testcase', 'bugs', "runID={$run->id}&caseID={$run->case}"), $run->bugs, '', "class='iframe'") : $run->bugs;
|
|
break;
|
|
case 'results':
|
|
echo (common::hasPriv('testtask', 'results') and $run->results) ? html::a(helper::createLink('testtask', 'results', "runID={$run->id}&caseID={$run->case}"), $run->results, '', "class='iframe'") : $run->results;
|
|
break;
|
|
case 'stepNumber':
|
|
echo $run->stepNumber;
|
|
break;
|
|
case 'actions':
|
|
if($run->caseStatus != 'wait' and $caseChanged)
|
|
{
|
|
common::printIcon('testcase', 'confirmChange', "id=$run->case&taskID=$run->task&from=list", $run, 'list', 'search', 'hiddenwin');
|
|
break;
|
|
}
|
|
|
|
common::printIcon('testcase', 'createBug', "product=$run->product&branch=$run->branch&extra=executionID=$task->execution,buildID=$task->build,caseID=$run->case,version=$run->version,runID=$run->id,testtask=$task->id", $run, 'list', 'bug', '', 'iframe', '', "data-width='90%'");
|
|
|
|
common::printIcon('testtask', 'runCase', "id=$run->id", $run, 'list', 'play', '', 'runCase iframe', false, "data-width='95%'");
|
|
common::printIcon('testtask', 'results', "id=$run->id", $run, 'list', '', '', 'iframe', '', "data-width='90%'");
|
|
|
|
if(common::hasPriv('testtask', 'unlinkCase', $run))
|
|
{
|
|
$unlinkURL = helper::createLink('testtask', 'unlinkCase', "caseID=$run->id&confirm=yes");
|
|
echo html::a("javascript:void(0)", '<i class="icon-unlink"></i>', '', "title='{$this->lang->testtask->unlinkCase}' class='btn' onclick='ajaxDelete(\"$unlinkURL\", \"casesForm\", confirmUnlink)'");
|
|
}
|
|
|
|
break;
|
|
}
|
|
echo '</td>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get toList and ccList.
|
|
*
|
|
* @param object $testtask
|
|
* @access public
|
|
* @return bool|array
|
|
*/
|
|
public function getToAndCcList($testtask)
|
|
{
|
|
/* Set toList and ccList. */
|
|
$toList = zget($testtask, 'owner', '');
|
|
$ccList = str_replace(' ', '', trim(zget($testtask, 'mailto', ''), ','));
|
|
|
|
if(empty($toList))
|
|
{
|
|
if(empty($ccList)) return false;
|
|
if(strpos($ccList, ',') === false)
|
|
{
|
|
$toList = $ccList;
|
|
$ccList = '';
|
|
}
|
|
else
|
|
{
|
|
$commaPos = strpos($ccList, ',');
|
|
$toList = substr($ccList, 0, $commaPos);
|
|
$ccList = substr($ccList, $commaPos + 1);
|
|
}
|
|
}
|
|
return array($toList, $ccList);
|
|
}
|
|
|
|
/**
|
|
* 导入单元测试结果。
|
|
* Import unit test results.
|
|
*
|
|
* @param object $task
|
|
* @access public
|
|
* @return bool|int
|
|
*/
|
|
public function importUnitResult(object $task): bool|int
|
|
{
|
|
/* 获取上传的单元测试文件。*/
|
|
/* Get uploaded unit test file. */
|
|
$files = $this->loadModel('file')->getUpload('resultFile');
|
|
if(empty($files[0]))
|
|
{
|
|
dao::$errors['resultFile'][] = $this->lang->testtask->unitXMLFormat;
|
|
return false;
|
|
}
|
|
|
|
/* 使用 simplexml 读取文件。*/
|
|
/* Use simplexml to read file. */
|
|
$file = $files[0];
|
|
$filePath = $this->file->savePath . $this->file->getSaveName($file['pathname']);
|
|
move_uploaded_file($file['tmpname'], $filePath);
|
|
$parsedXML = simplexml_load_file($filePath);
|
|
if($parsedXML === false)
|
|
{
|
|
dao::$errors['resultFile'][] = $this->lang->testtask->cannotBeParsed;
|
|
return false;
|
|
}
|
|
|
|
/* 解析 xml 文件。*/
|
|
/* Parse xml file. */
|
|
$data = $this->parseXMLResult($parsedXML, $task->product, $task->frame);
|
|
if(empty($data['cases']) && $task->frame == 'cppunit') $data = $this->parseCppXMLResult($parsedXML, $task->product, $task->frame);
|
|
if(empty($data['cases']))
|
|
{
|
|
dao::$errors['resultFile'][] = $this->lang->testtask->noImportData;
|
|
return false;
|
|
}
|
|
|
|
/* 创建测试单。*/
|
|
/* Create test task. */
|
|
unset($task->frame);
|
|
//$taskID = $this->create($task);
|
|
$taskID = 620;
|
|
if(dao::isError()) return false;
|
|
|
|
$this->loadModel('action')->create('testtask', $taskID, 'opened');
|
|
|
|
unlink($filePath);
|
|
unset($_SESSION['resultFile']);
|
|
|
|
/* 导入单元测试结果文件中包含的数据。*/
|
|
/* Import data in the unit test results. */
|
|
$this->importDataOfUnitResult($taskID, $task->product, $data['suites'], $data['cases'], $data['results'], $data['suiteNames'], $data['caseTitles'], 'unit');
|
|
|
|
return $taskID;
|
|
}
|
|
|
|
/**
|
|
* 导入单元测试结果文件中包含的数据。
|
|
* Import data in the unit test results.
|
|
*
|
|
* @param int $taskID
|
|
* @param int $productID
|
|
* @param array $suites
|
|
* @param array $cases
|
|
* @param array $results
|
|
* @param array $suiteNames
|
|
* @param array $caseTitles
|
|
* @param string $auto unit|func
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function importDataOfUnitResult(int $taskID, int $productID, array $suites, array $cases, array $results, array $suiteNames, array $caseTitles, string $auto = 'unit'): bool
|
|
{
|
|
$this->loadModel('action');
|
|
|
|
/* 初始化对象便于在循环中使用。*/
|
|
/* Initialize the object for use in loops. */
|
|
$suiteCase = new stdclass();
|
|
$testRun = new stdclass();
|
|
$testRun->task = $taskID;
|
|
$testRun->status = 'done';
|
|
|
|
$existSuites = $suiteNames ? $this->getExistSuitesOfUnitResult($suiteNames, $productID, $auto) : array();
|
|
|
|
foreach($suites as $suiteIndex => $suite)
|
|
{
|
|
$suiteID = 0;
|
|
if($suite) $suiteID = isset($existSuites[$suite->name]) ? $existSuites[$suite->name] : $this->importSuiteOfUnitResult($suite);
|
|
|
|
$suiteCase->suite = $suiteID;
|
|
|
|
$importCases = zget($cases, $suiteIndex, array());
|
|
$existCases = !empty($caseTitles[$suiteIndex]) ? $this->getExistCasesOfUnitResult($caseTitles[$suiteIndex], $suiteID, $productID, $auto) : array();
|
|
foreach($importCases as $key => $case)
|
|
{
|
|
$caseID = $this->importCaseOfUnitResult($case, $existCases);
|
|
$runID = $this->importRunOfUnitResult($case, $caseID, $testRun);
|
|
if($suiteID) $this->linkImportedCaseToSuite($case, $caseID, $suiteCase);
|
|
|
|
$testresult = $results[$suiteIndex][$key];
|
|
$testresult->run = $runID;
|
|
$testresult->case = $caseID;
|
|
$this->dao->insert(TABLE_TESTRESULT)->data($testresult)->exec();
|
|
}
|
|
}
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 导入单元测试结果文件中的测试套件。
|
|
* Import test suite in the unit test results.
|
|
*
|
|
* @param object $suite
|
|
* @access private
|
|
* @return int
|
|
*/
|
|
private function importSuiteOfUnitResult(object $suite): int
|
|
{
|
|
$this->dao->insert(TABLE_TESTSUITE)->data($suite)->exec();
|
|
$suiteID = $this->dao->lastInsertID();
|
|
$this->action->create('testsuite', $suiteID, 'opened');
|
|
|
|
return $suiteID;
|
|
}
|
|
|
|
/**
|
|
* 导入单元测试结果文件中的测试用例。
|
|
* Import test case in the unit test results.
|
|
*
|
|
* @param object $case
|
|
* @param array $existCases
|
|
* @access private
|
|
* @return int
|
|
*/
|
|
private function importCaseOfUnitResult(object &$case, array $existCases): int
|
|
{
|
|
if(!empty($case->id))
|
|
{
|
|
unset($case->steps);
|
|
|
|
$caseID = $case->id;
|
|
$oldCase = $this->dao->select('*')->from(TABLE_CASE)->where('id')->eq($caseID)->fetch();
|
|
$case->version = $oldCase->version;
|
|
$case->openedDate = $oldCase->openedDate;
|
|
|
|
$changes = common::createChanges($oldCase, $case);
|
|
if($changes)
|
|
{
|
|
$this->dao->update(TABLE_CASE)->data($case)->where('id')->eq($caseID)->exec();
|
|
$actionID = $this->action->create('case', $caseID, 'Edited');
|
|
$this->action->logHistory($actionID, $changes);
|
|
}
|
|
|
|
return $caseID;
|
|
}
|
|
|
|
if(!isset($existCases[$case->title]))
|
|
{
|
|
$this->dao->insert(TABLE_CASE)->data($case, 'steps')->exec();
|
|
$caseID = $this->dao->lastInsertID();
|
|
$steps = zget($case, 'steps', array());
|
|
foreach($steps as $step)
|
|
{
|
|
$step->case = $caseID;
|
|
$step->version = 1;
|
|
$this->dao->insert(TABLE_CASESTEP)->data($step)->exec();
|
|
}
|
|
$this->action->create('case', $caseID, 'Opened');
|
|
|
|
return $caseID;
|
|
}
|
|
|
|
return $existCases[$case->title];
|
|
}
|
|
|
|
/**
|
|
* 导入单元测试结果文件中的测试结果。
|
|
* Import test result in the unit test results.
|
|
*
|
|
* @param object $case
|
|
* @param int $caseID
|
|
* @param object $testRun
|
|
* @access private
|
|
* @return int
|
|
*/
|
|
private function importRunOfUnitResult(object $case, int $caseID, object $testRun): int
|
|
{
|
|
$testRun->case = $caseID;
|
|
$testRun->version = $case->version;
|
|
$testRun->lastRunner = $case->lastRunner;
|
|
$testRun->lastRunDate = $case->lastRunDate;
|
|
$testRun->lastRunResult = $case->lastRunResult;
|
|
|
|
$this->dao->replace(TABLE_TESTRUN)->data($testRun)->exec();
|
|
|
|
return $this->dao->lastInsertID();
|
|
}
|
|
|
|
/**
|
|
* 将导入的测试用例关联到测试套件。
|
|
* Link imported case to suite.
|
|
*
|
|
* @param object $case
|
|
* @param int $caseID
|
|
* @param object $suiteCase
|
|
* @access private
|
|
* @return bool
|
|
*/
|
|
private function linkImportedCaseToSuite(object $case, int $caseID, object $suiteCase): bool
|
|
{
|
|
$suiteCase->case = $caseID;
|
|
$suiteCase->version = $case->version;
|
|
$suiteCase->product = $case->product;
|
|
|
|
$this->dao->replace(TABLE_SUITECASE)->data($suiteCase)->exec();
|
|
|
|
return !dao::isError();
|
|
}
|
|
|
|
/**
|
|
* 获取单元测试结果文件中已存在的测试套件。
|
|
* Get exist suites in the unit test results.
|
|
*
|
|
* @param array $names
|
|
* @param int $productID
|
|
* @param string $auto
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
private function getExistSuitesOfUnitResult(array $names, int $productID, string $auto): array
|
|
{
|
|
if(!$names) return array();
|
|
|
|
return $this->dao->select('name, id')->from(TABLE_TESTSUITE)
|
|
->where('name')->in($names)
|
|
->andWhere('product')->eq($productID)
|
|
->andWhere('type')->eq($auto)
|
|
->andWhere('deleted')->eq('0')
|
|
->fetchPairs();
|
|
}
|
|
|
|
/**
|
|
* 获取单元测试结果文件中已存在的测试用例。
|
|
* Get exist cases in the unit test results.
|
|
*
|
|
* @param array $titles
|
|
* @param int $suiteID
|
|
* @param int $productID
|
|
* @param string $auto
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
private function getExistCasesOfUnitResult(array $titles, int $suiteID, int $productID, string $auto): array
|
|
{
|
|
if(!$titles) return array();
|
|
|
|
$this->dao->select('t1.title, t1.id')->from(TABLE_CASE)->alias('t1');
|
|
|
|
if($suiteID) $this->dao->leftJoin(TABLE_SUITECASE)->alias('t2')->on('t1.id=t2.case');
|
|
|
|
return $this->dao->where('t1.title')->in($titles)
|
|
->andWhere('t1.product')->eq($productID)
|
|
->beginIF($auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi()
|
|
->andWhere('t1.deleted')->eq('0')
|
|
->orderBy('t1.id')
|
|
->fetchPairs();
|
|
}
|
|
|
|
/**
|
|
* Parse cppunit XML result.
|
|
*
|
|
* @param object $parsedXML
|
|
* @param int $productID
|
|
* @param string $frame
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function parseCppXMLResult(object $parsedXML, int $productID, string $frame): array
|
|
{
|
|
/* Get testcase node. */
|
|
$failNodes = $parsedXML->xpath('FailedTests/FailedTest');
|
|
$passNodes = $parsedXML->xpath('SuccessfulTests/Test');
|
|
$matchNodes = array_merge($failNodes, $passNodes);
|
|
if(count($matchNodes) == 0) return array('suites' => array(), 'cases' => array(), 'results' => array(), 'suiteNames' => array(), 'caseTitles' => array());
|
|
|
|
/* Get cases and results by parsed node. */
|
|
$now = helper::now();
|
|
$cases = array();
|
|
$results = array();
|
|
$caseTitles = array();
|
|
$suiteNames = array();
|
|
$suiteIndex = 0;
|
|
$suites = array($suiteIndex => '');
|
|
foreach($matchNodes as $caseIndex => $matchNode)
|
|
{
|
|
$case = new stdclass();
|
|
$case->product = $productID;
|
|
$case->title = (string)$matchNode->Name;
|
|
$case->pri = 3;
|
|
$case->type = 'unit';
|
|
$case->stage = 'unittest';
|
|
$case->status = 'normal';
|
|
$case->openedBy = $this->app->user->account;
|
|
$case->openedDate = $now;
|
|
$case->version = 1;
|
|
$case->auto = 'unit';
|
|
$case->frame = $frame ? $frame : 'junit';
|
|
|
|
$result = new stdclass();
|
|
$result->case = 0;
|
|
$result->version = 1;
|
|
$result->caseResult = 'pass';
|
|
$result->lastRunner = $this->app->user->account;
|
|
$result->date = $now;
|
|
$result->duration = 0;
|
|
$result->xml = $matchNode->asXML();
|
|
$result->stepResults[0]['result'] = 'pass';
|
|
$result->stepResults[0]['real'] = '';
|
|
if(isset($matchNode->Message))
|
|
{
|
|
$result->caseResult = 'fail';
|
|
$result->stepResults[0]['result'] = 'fail';
|
|
$result->stepResults[0]['real'] = (string)$matchNode->Message;
|
|
}
|
|
$result->stepResults = serialize($result->stepResults);
|
|
$case->lastRunner = $this->app->user->account;
|
|
$case->lastRunDate = $now;
|
|
$case->lastRunResult = $result->caseResult;
|
|
|
|
$caseTitles[$suiteIndex][] = $case->title;
|
|
$cases[$suiteIndex][$caseIndex] = $case;
|
|
$results[$suiteIndex][$caseIndex] = $result;
|
|
}
|
|
|
|
return array('suites' => $suites, 'cases' => $cases, 'results' => $results, 'suiteNames' => $suiteNames, 'caseTitles' => $caseTitles);
|
|
}
|
|
|
|
/**
|
|
* Parse unit result from xml.
|
|
*
|
|
* @param object $parsedXML
|
|
* @param int $productID
|
|
* @param string $frame
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function parseXMLResult(object $parsedXML, int $productID, string $frame): array
|
|
{
|
|
/* Parse result xml. */
|
|
$rules = zget($this->config->testtask->unitResultRules, $frame, $this->config->testtask->unitResultRules->common);
|
|
|
|
/* Get testcase node. */
|
|
$matchPaths = $rules['path'];
|
|
$nameFields = $rules['name'];
|
|
$failure = $rules['failure'];
|
|
$skipped = $rules['skipped'];
|
|
$suiteField = $rules['suite'];
|
|
$aliasSuite = zget($rules, 'aliasSuite', array());
|
|
$aliasName = zget($rules, 'aliasName', array());
|
|
$matchNodes = array();
|
|
foreach($matchPaths as $matchPath)
|
|
{
|
|
$matchNodes = $parsedXML->xpath($matchPath);
|
|
if(count($matchNodes) != 0) break;
|
|
}
|
|
if(count($matchNodes) == 0) return array('suites' => array(), 'cases' => array(), 'results' => array(), 'suiteNames' => array(), 'caseTitles' => array());
|
|
|
|
$parentPath = '';
|
|
$caseNode = $matchPath;
|
|
$parentNodes = array($parsedXML);
|
|
if(strpos($matchPath, '/') !== false)
|
|
{
|
|
$explodedPath = explode('/', $matchPath);
|
|
$caseNode = array_pop($explodedPath);
|
|
$parentPath = implode('/', $explodedPath);
|
|
$parentNodes = $parsedXML->xpath($parentPath);
|
|
}
|
|
|
|
/* Get cases and results by parsed node. */
|
|
$now = helper::now();
|
|
$cases = array();
|
|
$results = array();
|
|
$suites = array();
|
|
$caseTitles = array();
|
|
$suiteNames = array();
|
|
foreach($parentNodes as $suiteIndex => $parentNode)
|
|
{
|
|
$caseNodes = $parentNode->xpath($caseNode);
|
|
$attributes = $parentNode->attributes();
|
|
$suite = '';
|
|
if(isset($attributes[$suiteField]))
|
|
{
|
|
$suite = new stdclass();
|
|
$suite->product = $productID;
|
|
$suite->name = (string)$attributes[$suiteField];
|
|
$suite->type = 'unit';
|
|
$suite->addedBy = $this->app->user->account;
|
|
$suite->addedDate = $now;
|
|
$suiteNames[] = $suite->name;
|
|
}
|
|
else
|
|
{
|
|
$attributes = $caseNodes[0]->attributes();
|
|
foreach($aliasSuite as $alias)
|
|
{
|
|
if(isset($attributes[$alias]))
|
|
{
|
|
$suite = new stdclass();
|
|
$suite->product = $productID;
|
|
$suite->name = (string)$attributes[$alias];
|
|
$suite->type = 'unit';
|
|
$suite->addedBy = $this->app->user->account;
|
|
$suite->addedDate = $now;
|
|
$suiteNames[] = $suite->name;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$suites[$suiteIndex] = $suite;
|
|
|
|
foreach($caseNodes as $caseIndex => $matchNode)
|
|
{
|
|
$case = new stdclass();
|
|
$case->product = $productID;
|
|
$case->title = '';
|
|
$case->pri = 3;
|
|
$case->type = 'unit';
|
|
$case->stage = 'unittest';
|
|
$case->status = 'normal';
|
|
$case->openedBy = $this->app->user->account;
|
|
$case->openedDate = $now;
|
|
$case->version = 1;
|
|
$case->auto = 'unit';
|
|
$case->frame = $frame ? $frame : 'junit';
|
|
|
|
$attributes = $matchNode->attributes();
|
|
foreach($nameFields as $field)
|
|
{
|
|
if(!isset($attributes[$field])) continue;
|
|
$case->title .= (string)$attributes[$field] . ' ';
|
|
}
|
|
$case->title = trim($case->title);
|
|
if(empty($case->title))
|
|
{
|
|
foreach($aliasName as $field)
|
|
{
|
|
if(!isset($attributes[$field])) continue;
|
|
$case->title .= (string)$attributes[$field] . ' ';
|
|
}
|
|
$case->title = trim($case->title);
|
|
}
|
|
if(empty($case->title)) continue;
|
|
|
|
$result = new stdclass();
|
|
$result->case = 0;
|
|
$result->version = 1;
|
|
$result->caseResult = 'pass';
|
|
$result->lastRunner = $this->app->user->account;
|
|
$result->date = $now;
|
|
$result->duration = isset($attributes['time']) ? (float)$attributes['time'] : 0;
|
|
$result->xml = $matchNode->asXML();
|
|
$result->stepResults[0]['result'] = 'pass';
|
|
$result->stepResults[0]['real'] = '';
|
|
if(isset($matchNode->$failure))
|
|
{
|
|
$result->caseResult = 'fail';
|
|
$result->stepResults[0]['result'] = 'fail';
|
|
if(is_string($matchNode->$failure))
|
|
{
|
|
$result->stepResults[0]['real'] = (string)$matchNode->$failure;
|
|
}
|
|
elseif(isset($matchNode->{$failure}[0]))
|
|
{
|
|
$result->stepResults[0]['real'] = (string)$matchNode->{$failure}[0];
|
|
}
|
|
else
|
|
{
|
|
$failureAttrs = $matchNode->$failure->attributes();
|
|
$result->stepResults[0]['real'] = (string)$failureAttrs['message'];
|
|
}
|
|
}
|
|
elseif(isset($matchNode->$skipped))
|
|
{
|
|
$result->caseResult = 'n/a';
|
|
$result->stepResults[0]['result'] = 'n/a';
|
|
$result->stepResults[0]['real'] = '';
|
|
}
|
|
$result->stepResults = serialize($result->stepResults);
|
|
$case->lastRunner = $this->app->user->account;
|
|
$case->lastRunDate = $now;
|
|
$case->lastRunResult = $result->caseResult;
|
|
|
|
$caseTitles[$suiteIndex][] = $case->title;
|
|
$cases[$suiteIndex][$caseIndex] = $case;
|
|
$results[$suiteIndex][$caseIndex] = $result;
|
|
}
|
|
}
|
|
|
|
return array('suites' => $suites, 'cases' => $cases, 'results' => $results, 'suiteNames' => $suiteNames, 'caseTitles' => $caseTitles);
|
|
}
|
|
|
|
/**
|
|
* Parse unit result from ztf.
|
|
*
|
|
* @param array $caseResults
|
|
* @param string $frame
|
|
* @param int $productID
|
|
* @param int $jobID
|
|
* @param int $compileID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function parseZTFUnitResult($caseResults, $frame, $productID, $jobID, $compileID)
|
|
{
|
|
$now = helper::now();
|
|
$cases = array();
|
|
$results = array();
|
|
$suites = array();
|
|
$caseTitles = array();
|
|
$suiteNames = array();
|
|
$suiteIndex = 0;
|
|
foreach($caseResults as $caseIndex => $caseResult)
|
|
{
|
|
$suite = '';
|
|
if(isset($caseResult->testSuite) and !isset($suiteNames[$caseResult->testSuite]))
|
|
{
|
|
$suite = new stdclass();
|
|
$suite->product = $productID;
|
|
$suite->name = $caseResult->testSuite;
|
|
$suite->type = 'unit';
|
|
$suite->addedBy = $this->app->user->account;
|
|
$suite->addedDate = $now;
|
|
|
|
$suiteNames[$suite->name] = $suite->name;
|
|
$suiteIndex ++;
|
|
}
|
|
if(!isset($suites[$suiteIndex])) $suites[$suiteIndex] = $suite;
|
|
|
|
$case = new stdclass();
|
|
if(!empty($caseResult->id)) $case->id = $caseResult->id;
|
|
$case->product = $productID;
|
|
if(empty($caseResult->id)) $case->title = $caseResult->title;
|
|
$case->pri = 3;
|
|
$case->type = 'unit';
|
|
$case->stage = 'unittest';
|
|
$case->status = 'normal';
|
|
$case->openedBy = $this->app->user->account;
|
|
$case->openedDate = $now;
|
|
$case->version = 1;
|
|
if(empty($caseResult->id)) $case->auto = 'unit';
|
|
$case->frame = $frame;
|
|
|
|
$result = new stdclass();
|
|
$result->case = 0;
|
|
$result->version = 1;
|
|
$result->caseResult = 'pass';
|
|
$result->lastRunner = $this->app->user->account;
|
|
$result->job = $jobID;
|
|
$result->compile = $compileID;
|
|
$result->date = $now;
|
|
$result->duration = zget($caseResult, 'duration', 0);
|
|
$result->stepResults[0]['result'] = 'pass';
|
|
$result->stepResults[0]['real'] = '';
|
|
if(!empty($caseResult->failure))
|
|
{
|
|
$result->caseResult = 'fail';
|
|
$result->stepResults[0]['result'] = 'fail';
|
|
$result->stepResults[0]['real'] = zget($caseResult->failure, 'desc', '');
|
|
}
|
|
$result->stepResults = serialize($result->stepResults);
|
|
$case->lastRunner = $this->app->user->account;
|
|
$case->lastRunDate = $now;
|
|
$case->lastRunResult = $result->caseResult;
|
|
|
|
$caseTitles[$suiteIndex][] = $case->title;
|
|
$cases[$suiteIndex][$caseIndex] = $case;
|
|
$results[$suiteIndex][$caseIndex] = $result;
|
|
}
|
|
|
|
return array('suites' => $suites, 'cases' => $cases, 'results' => $results, 'suiteNames' => $suiteNames, 'caseTitles' => $caseTitles);
|
|
}
|
|
|
|
/**
|
|
* Parse function result from ztf.
|
|
*
|
|
* @param array $caseResults
|
|
* @param string $frame
|
|
* @param int $productID
|
|
* @param int $jobID
|
|
* @param int $compileID
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function parseZTFFuncResult($caseResults, $frame, $productID, $jobID, $compileID)
|
|
{
|
|
$now = helper::now();
|
|
$cases = array();
|
|
$results = array();
|
|
$suites = array();
|
|
$caseTitles = array();
|
|
$suiteNames = array();
|
|
$suiteIndex = 0;
|
|
foreach($caseResults as $caseIndex => $caseResult)
|
|
{
|
|
$suite = '';
|
|
if(!isset($suites[$suiteIndex])) $suites[$suiteIndex] = $suite;
|
|
|
|
$case = new stdclass();
|
|
if(isset($caseResult->id)) $case->id = $caseResult->id;
|
|
if(!isset($caseResult->id)) $case->product = $productID;
|
|
$case->title = $caseResult->title;
|
|
$case->pri = 3;
|
|
$case->type = 'feature';
|
|
$case->stage = 'feature';
|
|
$case->status = 'normal';
|
|
$case->openedBy = $this->app->user->account;
|
|
$case->openedDate = $now;
|
|
$case->version = 1;
|
|
$case->auto = 'func';
|
|
$case->frame = $frame;
|
|
$case->steps = array();
|
|
|
|
$result = new stdclass();
|
|
$result->case = 0;
|
|
$result->version = 1;
|
|
$result->caseResult = 'pass';
|
|
$result->lastRunner = $this->app->user->account;
|
|
$result->job = $jobID;
|
|
$result->compile = $compileID;
|
|
$result->date = $now;
|
|
$result->stepResults[0]['result'] = 'pass';
|
|
$result->stepResults[0]['real'] = '';
|
|
if(!empty($caseResult->steps))
|
|
{
|
|
$result->stepResults = array();
|
|
$stepStatus = 'pass';
|
|
foreach($caseResult->steps as $i => $step)
|
|
{
|
|
if(!$step->status) $step->status = 'fail';
|
|
|
|
$result->stepResults[$i]['result'] = $step->status;
|
|
$result->stepResults[$i]['real'] = $step->checkPoints[0]->actual;
|
|
if($step->status == 'fail') $stepStatus = 'fail';
|
|
|
|
$caseStep = new stdclass();
|
|
$caseStep->type = 'step';
|
|
$caseStep->desc = $step->name;
|
|
$caseStep->expect = $step->checkPoints[0]->expect;
|
|
|
|
$case->steps[] = $caseStep;
|
|
}
|
|
$result->caseResult = $stepStatus;
|
|
}
|
|
$result->stepResults = serialize($result->stepResults);
|
|
$case->lastRunner = $this->app->user->account;
|
|
$case->lastRunDate = $now;
|
|
$case->lastRunResult = $result->caseResult;
|
|
|
|
$caseTitles[$suiteIndex][] = $case->title;
|
|
$cases[$suiteIndex][$caseIndex] = $case;
|
|
$results[$suiteIndex][$caseIndex] = $result;
|
|
}
|
|
|
|
return array('suites' => $suites, 'cases' => $cases, 'results' => $results, 'suiteNames' => $suiteNames, 'caseTitles' => $caseTitles);
|
|
}
|
|
}
|