* @package case * @version $Id: model.php 5108 2013-07-12 01:59:04Z chencongzhi520@gmail.com $ * @link http://www.zentao.net */ ?> loadModel('qa')->setMenu($products, $productID, $branch, $moduleID, 'case'); } /** * 创建一个用例。 * Create a case. * * @param object $case * @access public * @return bool|int */ public function create(object $case): bool|int { /* 插入测试用例。 */ /* Insert testcase. */ $this->testcaseTao->doCreate($case); if(dao::isError()) return false; $caseID = $this->dao->lastInsertID(); /* 记录动态。*/ /* Record log. */ $this->loadModel('action'); $this->action->create('case', $caseID, 'Opened'); if($case->status == 'wait') $this->action->create('case', $caseID, 'submitReview'); /* 存储上传的文件。 */ /* Save upload files. */ $this->config->dangers = ''; $this->loadModel('file')->saveUpload('testcase', $caseID, 'autoscript', 'script', 'scriptName'); $this->loadModel('file')->saveUpload('testcase', $caseID); $this->loadModel('score')->create('testcase', 'create', $caseID); /* 插入用例步骤。 */ /* Insert testcase steps. */ $this->testcaseTao->insertSteps($caseID, $case->steps, $case->expects, $case->stepType); if(dao::isError()) return false; return $caseID; } /** * 获取模块的用例。 * Get cases of modules. * * @param int $productID * @param int|string $branch * @param int|array $moduleIdList * @param string $browseType * @param string $auto no|unit * @param string $caseType * @param string $orderBy * @param object $pager * @access public * @return array */ public function getModuleCases(int $productID, int|string $branch = 0, int|array $moduleIdList = 0, string $browseType = '', string $auto = 'no', string $caseType = '', string $orderBy = 'id_desc', object $pager = null): array { $stmt = $this->dao->select('t1.*, t2.title as storyTitle, t2.deleted as storyDeleted')->from(TABLE_CASE)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story=t2.id'); if($this->app->tab == 'project') $stmt = $stmt->leftJoin(TABLE_PROJECTCASE)->alias('t3')->on('t1.id=t3.case'); return $stmt ->where('t1.product')->eq((int)$productID) ->beginIF($this->app->tab == 'project')->andWhere('t3.project')->eq($this->session->project)->fi() ->beginIF($branch !== 'all')->andWhere('t1.branch')->eq($branch)->fi() ->beginIF($moduleIdList)->andWhere('t1.module')->in($moduleIdList)->fi() ->beginIF($browseType == 'all')->andWhere('t1.scene')->eq(0)->fi() ->beginIF($browseType == 'wait')->andWhere('t1.status')->eq($browseType)->fi() ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi() ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->beginIF($caseType)->andWhere('t1.type')->eq($caseType)->fi() ->andWhere('t1.deleted')->eq('0') ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); } /** * Get project cases of a module. * * @param int $productID * @param int|string $branch * @param int $moduleIdList * @param string $browseType * @param string $auto no|unit * @param string $caseType * @param string $orderBy * @param object $pager * @access public * @return array */ public function getModuleProjectCases($productID, $branch = 0, $moduleIdList = 0, $browseType = '', $auto = 'no', $caseType = '', $orderBy = 'id_desc', $pager = null) { $executions = $this->loadModel('execution')->getIdList($this->session->project); array_push($executions, $this->session->project); return $this->dao->select('distinct t1.*, t2.*, t4.title as storyTitle')->from(TABLE_PROJECTCASE)->alias('t1') ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t3.story=t2.story') ->leftJoin(TABLE_STORY)->alias('t4')->on('t3.story=t4.id') ->where('t1.project')->in($executions) ->beginIF(!empty($productID))->andWhere('t2.product')->eq((int)$productID)->fi() ->beginIF(!empty($productID) and $branch !== 'all')->andWhere('t2.branch')->eq($branch)->fi() ->beginIF($moduleIdList)->andWhere('t2.module')->in($moduleIdList)->fi() ->beginIF($browseType == 'all')->andWhere('t2.scene')->eq(0)->fi() ->beginIF($browseType == 'wait')->andWhere('t2.status')->eq($browseType)->fi() ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi() ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->beginIF($caseType)->andWhere('t2.type')->eq($caseType)->fi() ->andWhere('t2.deleted')->eq('0') ->orderBy($orderBy) ->page($pager, 't1.`case`') ->fetchAll('id'); } /** * Get project cases. * * @param int $projectID * @param string $orderBy * @param object $pager * @param string $browseType * @access public * @return array */ public function getProjectCases($projectID, $orderBy = 'id_desc', $pager = null, $browseType = '') { return $this->dao->select('distinct t1.*, t2.*')->from(TABLE_PROJECTCASE)->alias('t1') ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') ->where('t1.project')->eq((int)$projectID) ->beginIF($browseType != 'all')->andWhere('t2.status')->eq($browseType)->fi() ->andWhere('t2.deleted')->eq('0') ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); } /** * Get execution cases. * * @param int $executionID * @param int $productID * @param int $branchID * @param int $moduleID * @param string $orderBy * @param object $pager * @param string $browseType all|wait|needconfirm * @access public * @return array */ public function getExecutionCases($executionID, $productID = 0, $branchID = 0, $moduleID = 0, $orderBy = 'id_desc', $pager = null, $browseType = '') { if($browseType == 'needconfirm') { return $this->dao->select('distinct t1.*, t2.*')->from(TABLE_PROJECTCASE)->alias('t1') ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') ->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id') ->leftJoin(TABLE_MODULE)->alias('t4')->on('t2.module=t4.id') ->where('t1.project')->eq((int)$executionID) ->beginIF(!empty($productID))->andWhere('t1.product')->eq($productID)->fi() ->beginIF(!empty($moduleID))->andWhere('t4.path')->like("%,$moduleID,%")->fi() ->beginIF(!empty($productID) and $branchID !== 'all')->andWhere('t2.branch')->eq($branchID)->fi() ->andWhere('t2.deleted')->eq('0') ->andWhere('t3.version > t2.storyVersion') ->andWhere("t3.status")->eq('active') ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); } return $this->dao->select('distinct t1.*, t2.*')->from(TABLE_PROJECTCASE)->alias('t1') ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') ->leftJoin(TABLE_MODULE)->alias('t3')->on('t2.module=t3.id') ->where('t1.project')->eq((int)$executionID) ->beginIF($browseType != 'all' and $browseType != 'byModule')->andWhere('t2.status')->eq($browseType)->fi() ->beginIF(!empty($productID))->andWhere('t1.product')->eq($productID)->fi() ->beginIF(!empty($moduleID))->andWhere('t3.path')->like("%,$moduleID,%")->fi() ->beginIF(!empty($productID) and $branchID !== 'all')->andWhere('t2.branch')->eq($branchID)->fi() ->andWhere('t2.deleted')->eq('0') ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); } /** * Get cases by suite. * * @param int $productID * @param int|string $branch * @param int $suiteID * @param array $moduleIdList * @param string $orderBy * @param object $pager * @param string $auto no|unit * @access public * @return array */ public function getBySuite($productID, $branch = 0, $suiteID = 0, $moduleIdList = 0, $orderBy = 'id_desc', $pager = null, $auto = 'no') { return $this->dao->select('t1.*, t2.title as storyTitle, t3.version as version')->from(TABLE_CASE)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story=t2.id') ->leftJoin(TABLE_SUITECASE)->alias('t3')->on('t1.id=t3.case') ->where('t1.product')->eq((int)$productID) ->beginIF($this->app->tab == 'project')->andWhere('t1.project')->eq($this->session->project)->fi() ->andWhere('t3.suite')->eq((int)$suiteID) ->beginIF($branch !== 'all')->andWhere('t1.branch')->eq($branch)->fi() ->beginIF($moduleIdList)->andWhere('t1.module')->in($moduleIdList)->fi() ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi() ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->andWhere('t1.deleted')->eq('0') ->orderBy($orderBy)->page($pager)->fetchAll('id'); } /** * Get cases by type. * * @param int $productID * @param int|string $branch * @param int $suiteID * @param array $moduleIdList * @param string $orderBy * @param object $pager * @param string $auto no|unit * @access public * @return array */ public function getByType($productID, $branch = 0, $type = '', $moduleIdList = 0, $orderBy = 'id_desc', $pager = null, $auto = 'no') { return $this->dao->select('t1.*, t2.title as storyTitle')->from(TABLE_CASE)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story=t2.id') ->where('t1.product')->eq((int)$productID) ->beginIF($this->app->tab == 'project')->andWhere('t1.project')->eq($this->session->project)->fi() ->beginIF($type)->andWhere('t1.type')->eq($type)->fi() ->beginIF($branch !== 'all')->andWhere('t1.branch')->eq($branch)->fi() ->beginIF($moduleIdList)->andWhere('t1.module')->in($moduleIdList)->fi() ->beginIF($auto == 'unit')->andWhere('t1.auto')->eq('unit')->fi() ->beginIF($auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->andWhere('t1.deleted')->eq('0') ->orderBy($orderBy)->page($pager) ->fetchAll('id'); } /** * Get case info by ID. * * @param int $caseID * @param int $version * @access public * @return object|bool */ public function getById(int $caseID, int $version = 0): object|bool { $case = $this->dao->findById($caseID)->from(TABLE_CASE)->fetch(); if(!$case) return false; foreach($case as $key => $value) if(strpos($key, 'Date') !== false and $value && !(int)substr($value, 0, 4)) $case->$key = ''; /* Get project and execution. */ if($this->app->tab == 'project') { $case->project = $this->session->project; } elseif($this->app->tab == 'execution') { $case->execution = $this->session->execution; $case->project = $this->dao->select('project')->from(TABLE_PROJECT)->where('id')->eq($case->execution)->fetch('project'); } else { $objects = $this->dao->select('t1.project as objectID, t2.type')->from(TABLE_PROJECTCASE)->alias('t1') ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.project=t2.id') ->where('t1.case')->eq($caseID) ->fetchPairs(); foreach($objects as $objectID => $objectType) { if($objectType == 'project') $case->project = $objectID; if(in_array($objectType, array('sprint', 'stage', 'kanban'))) $case->execution = $objectID; } } /* Set related variables. */ $toBugs = $this->dao->select('id, title, severity, openedDate')->from(TABLE_BUG)->where('`case`')->eq($caseID)->fetchAll(); $case->toBugs = array(); foreach($toBugs as $toBug) $case->toBugs[$toBug->id] = $toBug; if($case->story) { $story = $this->dao->findById($case->story)->from(TABLE_STORY)->fields('title, status, version')->fetch(); $case->storyTitle = $story->title; $case->storyStatus = $story->status; $case->latestStoryVersion = $story->version; } if($case->fromBug) $case->fromBugData = $this->dao->findById($case->fromBug)->from(TABLE_BUG)->fields('title, severity, openedDate')->fetch(); if($case->linkCase || $case->fromCaseID) $case->linkCaseTitles = $this->dao->select('id,title')->from(TABLE_CASE)->where('id')->in($case->linkCase)->orWhere('id')->eq($case->fromCaseID)->fetchPairs(); $case->currentVersion = $version ? $version : $case->version; $case->files = $this->loadModel('file')->getByObject('testcase', $caseID); $case->steps = $this->testcaseTao->getSteps($caseID, $case->currentVersion); return $case; } /** * Get cases by id list and query string. * * @param array $caseIdList * @param string $query * @access public * @return array */ public function getByList(array $caseIdList, string $query = ''): array { if(!$caseIdList) return array(); return $this->dao->select('*')->from(TABLE_CASE) ->where('deleted')->eq(0) ->andWhere('id')->in($caseIdList) ->beginIF($query)->andWhere($query)->fi() ->fetchAll('id'); } /** * Get test cases. * * @param int $productID * @param int|string $branch * @param string $browseType * @param int $queryID * @param int $moduleID * @param string $caseType * @param string $sort * @param object $pager * @param string $auto no|unit * @access public * @return array */ public function getTestCases($productID, $branch, $browseType, $queryID, $moduleID, $caseType = '', $sort = 'id_desc', $pager = null, $auto = 'no') { /* Set modules and browse type. */ $modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0'; $browseType = ($browseType == 'bymodule' and $this->session->caseBrowseType and $this->session->caseBrowseType != 'bysearch') ? $this->session->caseBrowseType : $browseType; $group = $this->lang->navGroup->testcase; $auto = $this->cookie->onlyAutoCase ? 'auto' : $auto; /* By module or all cases. */ $cases = array(); if($browseType == 'bymodule' or $browseType == 'all' or $browseType == 'wait') { if($this->app->tab == 'project') { $cases = $this->getModuleProjectCases($productID, $branch, $modules, $browseType, $auto, $caseType, $sort, $pager); } else { $cases = $this->getModuleCases($productID, $branch, $modules, $browseType, $auto, $caseType, $sort, $pager); } } /* Cases need confirmed. */ elseif($browseType == 'needconfirm') { $cases = $this->dao->select('distinct t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') ->leftJoin(TABLE_PROJECTCASE)->alias('t3')->on('t1.id = t3.case') ->where("t2.status = 'active'") ->andWhere('t1.deleted')->eq(0) ->andWhere('t2.version > t1.storyVersion') ->beginIF(!empty($productID))->andWhere('t1.product')->eq($productID)->fi() ->beginIF($this->app->tab == 'project')->andWhere('t3.project')->eq($this->session->project)->fi() ->beginIF($branch !== 'all' and !empty($productID))->andWhere('t1.branch')->eq($branch)->fi() ->beginIF($modules)->andWhere('t1.module')->in($modules)->fi() ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi() ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->beginIF($caseType)->andWhere('t1.type')->eq($caseType)->fi() ->orderBy($sort) ->page($pager, 't1.id') ->fetchAll(); } elseif($browseType == 'bysuite') { $cases = $this->getBySuite($productID, $branch, $queryID, $modules, $sort, $pager, $auto); } /* By search. */ elseif($browseType == 'bysearch') { $cases = $this->getBySearch($productID, $queryID, $sort, $pager, $branch, $auto); } return $cases; } /** * Get cases by search. * * @param int $productID * @param int $queryID * @param string $orderBy * @param object $pager * @param int|string $branch * @param string $auto no|unit * @access public * @return array */ public function getBySearch($productID, $queryID, $orderBy, $pager = null, $branch = 0, $auto = 'no') { if($queryID) { $query = $this->loadModel('search')->getQuery($queryID); if($query) { $this->session->set('testcaseQuery', $query->sql); $this->session->set('testcaseForm', $query->form); } else { $this->session->set('testcaseQuery', ' 1 = 1'); } } else { if($this->session->testcaseQuery == false) $this->session->set('testcaseQuery', ' 1 = 1'); } $queryProductID = $productID; $allProduct = "`product` = 'all'"; $caseQuery = '(' . $this->session->testcaseQuery; if(strpos($this->session->testcaseQuery, $allProduct) !== false) { $products = $this->app->user->view->products; $caseQuery = str_replace($allProduct, '1', $caseQuery); $caseQuery = $caseQuery . ' AND `product` ' . helper::dbIN($products); $queryProductID = 'all'; } $allBranch = "`branch` = 'all'"; if($branch !== 'all' and strpos($caseQuery, '`branch` =') === false) $caseQuery .= " AND `branch` in('$branch')"; if(strpos($caseQuery, $allBranch) !== false) $caseQuery = str_replace($allBranch, '1', $caseQuery); $caseQuery .= ')'; $caseQuery = str_replace('`version`', 't1.`version`', $caseQuery); if($this->app->tab == 'project') $caseQuery = str_replace('`product`', 't2.`product`', $caseQuery); /* Search criteria under compatible project. */ $sql = $this->dao->select('*')->from(TABLE_CASE)->alias('t1'); if($this->app->tab == 'project') $sql->leftJoin(TABLE_PROJECTCASE)->alias('t2')->on('t1.id=t2.case'); $cases = $sql ->where($caseQuery) ->beginIF($this->app->tab == 'project' and $this->config->systemMode == 'new')->andWhere('t2.project')->eq($this->session->project)->fi() ->beginIF($this->app->tab == 'project' and !empty($productID) and $queryProductID != 'all')->andWhere('t2.product')->eq($productID)->fi() ->beginIF($this->app->tab != 'project' and !empty($productID) and $queryProductID != 'all')->andWhere('t1.product')->eq($productID)->fi() ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi() ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->andWhere('t1.deleted')->eq(0) ->orderBy($orderBy)->page($pager)->fetchAll('id'); return $cases; } /** * Get cases by assignedTo. * * @param string $account * @param string $orderBy * @param object $pager * @param string $auto no|unit|skip * @access public * @return array */ public function getByAssignedTo($account, $orderBy = 'id_desc', $pager = null, $auto = 'no') { return $this->dao->select('t1.id as run, t1.task,t1.case,t1.version,t1.assignedTo,t1.lastRunner,t1.lastRunDate,t1.lastRunResult,t1.status as lastRunStatus,t2.id as id,t2.project,t2.pri,t2.title,t2.type,t2.openedBy,t2.color,t2.product,t2.branch,t2.module,t2.status,t2.story,t2.storyVersion,t3.name as taskName')->from(TABLE_TESTRUN)->alias('t1') ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id') ->leftJoin(TABLE_TESTTASK)->alias('t3')->on('t1.task = t3.id') ->where('t1.assignedTo')->eq($account) ->andWhere('t3.deleted')->eq(0) ->andWhere('t2.deleted')->eq(0) ->andWhere('t3.status')->ne('done') ->beginIF(strpos($auto, 'skip') === false and $auto != 'unit')->andWhere('t2.auto')->ne('unit')->fi() ->beginIF($auto == 'unit')->andWhere('t2.auto')->eq('unit')->fi() ->orderBy($orderBy) ->page($pager) ->fetchAll(strpos($auto, 'run') !== false? 'run' : 'id'); } /** * Get cases by openedBy * * @param string $account * @param string $orderBy * @param object $pager * @param string $auto no|unit|skip * @access public * @return array */ public function getByOpenedBy($account, $orderBy = 'id_desc', $pager = null, $auto = 'no') { return $this->dao->findByOpenedBy($account)->from(TABLE_CASE) ->beginIF($auto != 'skip')->andWhere('product')->ne(0)->fi() ->andWhere('deleted')->eq(0) ->beginIF($auto != 'skip' and $auto != 'unit')->andWhere('auto')->ne('unit')->fi() ->beginIF($auto == 'unit')->andWhere('auto')->eq('unit')->fi() ->orderBy($orderBy)->page($pager) ->fetchAll('id'); } /** * Get cases by type * * @param int $productID * @param int $branch * @param string $type all|needconfirm * @param string $status all|normal|blocked|investigate * @param int $moduleID * @param string $orderBy * @param object $pager * @param string $auto no|unit|skip * @access public * @return array */ public function getByStatus($productID = 0, $branch = 0, $type = 'all', $status = 'all', $moduleID = 0, $orderBy = 'id_desc', $pager = null, $auto = 'no') { $modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0'; $cases = $this->dao->select('t1.*, t2.title as storyTitle')->from(TABLE_CASE)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') ->beginIF($productID)->where('t1.product')->eq((int) $productID)->fi() ->beginIF($productID == 0)->where('t1.product')->in($this->app->user->view->products)->fi() ->beginIF($branch)->andWhere('t1.branch')->eq($branch)->fi() ->beginIF($modules)->andWhere('t1.module')->in($modules)->fi() ->beginIF($type == 'needconfirm')->andWhere("t2.status = 'active'")->andWhere('t2.version > t1.storyVersion')->fi() ->beginIF($status != 'all')->andWhere('t1.status')->eq($status)->fi() ->beginIF($auto == 'unit')->andWhere('t1.auto')->eq('unit')->fi() ->beginIF($auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() ->andWhere('t1.deleted')->eq('0') ->orderBy($orderBy)->page($pager) ->fetchAll('id'); return $this->appendData($cases); } /** * Get cases by product id. * * @param int $productID * @access public * @return array */ public function getByProduct($productID) { return $this->dao->select('*')->from(TABLE_CASE) ->where('deleted')->eq(0) ->andWhere('product')->eq($productID) ->fetchAll('id'); } /** * Get case pairs by product id and branch. * * @param int $productID * @param int|string $branch * @access public * @return void */ public function getPairsByProduct($productID, $branch = 0) { return $this->dao->select("id, concat_ws(':', id, title) as title")->from(TABLE_CASE) ->where('deleted')->eq(0) ->andWhere('product')->eq($productID) ->beginIF($branch)->andWhere('branch')->in($branch)->fi() ->orderBy('id_desc') ->fetchPairs(); } /** * Get cases of a story. * * @param int $storyID * @access public * @return array */ public function getStoryCases($storyID) { return $this->dao->select('id, project, title, pri, type, status, lastRunner, lastRunDate, lastRunResult') ->from(TABLE_CASE) ->where('story')->eq((int)$storyID) ->andWhere('deleted')->eq(0) ->fetchAll('id'); } /** * Get counts of some stories' cases. * * @param array $stories * @access public * @return int */ public function getStoryCaseCounts($stories) { if(empty($stories)) return array(); $caseCounts = $this->dao->select('story, COUNT(*) AS cases') ->from(TABLE_CASE) ->where('story')->in($stories) ->andWhere('deleted')->eq(0) ->groupBy('story') ->fetchPairs(); foreach($stories as $storyID) if(!isset($caseCounts[$storyID])) $caseCounts[$storyID] = 0; return $caseCounts; } /** * 获取导出的用例。 * Get cases to export. * * @param string $exportType * @param int $taskID * @param string $orderBy * @param int|bool $limit * @access public * @return array */ public function getCasesToExport(string $exportType, int $taskID, string $orderBy, int|bool $limit): array { if(strpos($orderBy, 'case') !== false) { list($field, $sort) = explode('_', $orderBy); $orderBy = '`' . $field . '`_' . $sort; } if($this->session->testcaseOnlyCondition) { $caseIdList = array(); if($taskID) $caseIdList = $this->dao->select('`case`')->from(TABLE_TESTRUN)->where('task')->eq($taskID)->fetchPairs(); return $this->dao->select('*')->from(TABLE_CASE)->where($this->session->testcaseQueryCondition) ->beginIF($taskID)->andWhere('id')->in($caseIdList)->fi() ->beginIF($exportType == 'selected')->andWhere('id')->in($this->cookie->checkedItem)->fi() ->orderBy($orderBy) ->beginIF($limit)->limit($limit)->fi() ->fetchAll('id'); } $cases = array(); $orderBy = " ORDER BY " . str_replace(array('|', '^A', '_'), ' ', $orderBy); $stmt = $this->dao->query($this->session->testcaseQueryCondition . $orderBy . ($limit ? ' LIMIT ' . $limit : '')); while($row = $stmt->fetch()) { $caseID = isset($row->case) ? $row->case : $row->id; if($exportType == 'selected' && strpos(",{$this->cookie->checkedItem},", ",$caseID,") === false) continue; $row->id = $caseID; $cases[$caseID] = $row; } return $cases; } /** * 获取导出的用例的结果。 * Get case results for export. * * @param array $caseIdList * @param int $taskID * @access public * @return array */ public function getCaseResultsForExport(array $caseIdList, int $taskID = 0): array { $stmt = $this->dao->select('t1.*')->from(TABLE_TESTRESULT)->alias('t1') ->leftJoin(TABLE_TESTRUN)->alias('t2')->on('t1.run = t2.id') ->where('t1.`case`')->in($caseIdList) ->beginIF($taskID)->andWhere('t2.task')->eq($taskID)->fi() ->orderBy('id_desc') ->query(); $results = array(); while($result = $stmt->fetch()) { if(!isset($results[$result->case])) $results[$result->case] = unserialize($result->stepResults); } return $results; } /** * 更新用例。 * Update a case. * * @param object $case * @param object $oldCase * @param array $testtasks * @access public * @return bool|array */ public function update(object $case, object $oldCase, array $testtasks = array()): bool|array { $this->testcaseTao->doUpdate($case); if(dao::isError()) return false; $this->testcaseTao->updateCase2Project($oldCase, $case); if($case->stepChanged) $this->testcaseTao->updateStep($case, $oldCase); if($oldCase->lib && empty($oldCase->product)) { $fromcaseVersion = $this->dao->select('fromCaseVersion')->from(TABLE_CASE)->where('fromCaseID')->eq($case->id)->fetch('fromCaseVersion'); $fromcaseVersion = (int)$fromcaseVersion + 1; $this->dao->update(TABLE_CASE)->set('`fromCaseVersion`')->eq($fromcaseVersion)->where('`fromCaseID`')->eq($case->id)->exec(); } if(isset($oldCase->toBugs) && isset($case->linkBug)) $this->testcaseTao->linkBugs($oldCase->id, array_keys($oldCase->toBugs), $case); if($case->branch && !empty($testtasks)) $this->testcaseTao->unlinkCaseFromTesttask($oldCase->id, $testtasks); $this->loadModel('file')->processFile4Object('testcase', $oldCase, $case); /* Join the steps to diff. */ if($case->stepChanged && $case->steps) { $oldCase->steps = $this->joinStep($oldCase->steps); $case->steps = $this->joinStep($this->getByID($oldCase->id, $case->version)->steps); } else { unset($oldCase->steps); unset($case->steps); } return common::createChanges($oldCase, $case); } /** * 评审用例。 * Review case. * * @param object $case * @param object $oldCase * @access public * @return bool */ public function review(object $case, object $oldCase): bool { $this->dao->update(TABLE_CASE)->data($case, 'result,comment')->autoCheck()->checkFlow()->where('id')->eq($oldCase->id)->exec(); if(dao::isError()) return false; $changes = common::createChanges($oldCase, $case); if(!empty($changes)) { $actionID = $this->loadModel('action')->create('case', $caseID, 'Reviewed', $case->comment, ucfirst($case->result)); $this->action->logHistory($actionID, $changes); } return true; } /** * Batch review cases. * * @param array $caseIdList * @param string $result * @access public * @return bool */ public function batchReview(array $caseIdList, string $result): bool { $caseIdList = array_filter($caseIdList); if(!$caseIdList) return false; $oldCases = $this->getByList($caseIdList, "status = 'wait'"); if(!$oldCases) return false; $now = helper::now(); $case = new stdClass(); $case->reviewedBy = $this->app->user->account; $case->reviewedDate = substr($now, 0, 10); $case->lastEditedBy = $this->app->user->account; $case->lastEditedDate = $now; if($result == 'pass') $case->status = 'normal'; $this->dao->update(TABLE_CASE)->data($case)->autoCheck()->where('id')->in(array_keys($oldCases))->exec(); if(dao::isError()) return false; $this->loadModel('action'); foreach($oldCases as $oldCase) { $changes = common::createChanges($oldCase, $case); if($changes) { $actionID = $this->action->create('case', $oldCase->id, 'Reviewed', '', ucfirst($result)); $this->action->logHistory($actionID, $changes); } } return !dao::isError(); } /** * 获取可关联的用例。 * Get cases to link. * * @param int $caseID * @param string $browseType * @param int $queryID * @access public * @return array */ public function getCases2Link(int $caseID, string $browseType = 'bySearch', int $queryID = 0): array { if($browseType != 'bySearch') return array(); $case = $this->getByID($caseID); $cases2Link = $this->getBySearch($case->product, $queryID, 'id', null, $case->branch); foreach($cases2Link as $key => $case2Link) { if($case2Link->id == $caseID) unset($cases2Link[$key]); if(in_array($case2Link->id, explode(',', $case->linkCase))) unset($cases2Link[$key]); } return $cases2Link; } /** * 获取可关联的 bug。 * Get bugs to link. * * @param int $caseID * @param string $browseType * @param int $queryID * @access public * @return array */ public function getBugs2Link(int $caseID, string $browseType = 'bySearch', int $queryID = 0): array { if($browseType != 'bySearch') return array(); $case = $this->getByID($caseID); $bugs2Link = $this->loadModel('bug')->getBySearch('bug', $case->product, (string)$case->branch, 0, 0, $queryID, '', 'id'); foreach($bugs2Link as $key => $bug2Link) { if($bug2Link->case != 0) unset($bugs2Link[$key]); } return $bugs2Link; } /** * Batch delete cases and scenes. * * @param array $caseIdList * @param array $sceneIdList * @access public * @return bool */ public function batchDelete(array $caseIdList, array $sceneIdList): bool { $caseIdList = array_filter($caseIdList); $sceneIdList = array_filter($sceneIdList); if(!$caseIdList && !$sceneIdList) return false; $this->loadModel('action'); if($caseIdList) { $this->dao->update(TABLE_CASE)->set('deleted')->eq('1')->where('id')->in($caseIdList)->exec(); foreach($caseIdList as $caseID) $this->action->create('case', $caseID, 'deleted', '', actionModel::CAN_UNDELETED); } if($sceneIdList) { $this->dao->update(TABLE_SCENE)->set('deleted')->eq('1')->where('id')->in($sceneIdList)->exec(); foreach($sceneIdList as $sceneID) $this->action->create('scene', $sceneID, 'deleted', '', actionModel::CAN_UNDELETED); } return !dao::isError(); } /** * Batch change branch of cases and scenes. * * @param array $caseIdList * @param array $sceneIdList * @param int $branchID * @access public * @return bool */ public function batchChangeBranch(array $caseIdList, array $sceneIdList, int $branchID): bool { if($branchID < 0 || $branchID > 16777215) return false; // The branch column's data type is mediumint unsigned and its range is 0-16777215. $caseIdList = array_filter($caseIdList); $sceneIdList = array_filter($sceneIdList); if(!$caseIdList && !$sceneIdList) return false; if($caseIdList) $this->batchChangeCaseBranch($caseIdList, $branchID); if($sceneIdList) $this->batchChangeSceneBranch($sceneIdList, $branchID); return !dao::isError(); } /** * Batch change branch of cases. * * @param array $caseIdList * @param int $branchID * @access public * @return bool */ public function batchChangeCaseBranch(array $caseIdList, int $branchID): bool { if(!$caseIdList) return false; if($branchID < 0 || $branchID > 16777215) return false; // The branch column's data type is mediumint unsigned and its range is 0-16777215. $oldCases = $this->getByList($caseIdList, "branch != '{$branchID}'"); if(!$oldCases) return false; $case = new stdclass(); $case->branch = $branchID; $case->lastEditedBy = $this->app->user->account; $case->lastEditedDate = helper::now(); $this->dao->update(TABLE_CASE)->data($case)->where('id')->in(array_keys($oldCases))->exec(); if(dao::isError()) return false; $this->loadModel('action'); foreach($oldCases as $oldCase) { $changes = common::createChanges($oldCase, $case); if($changes) { $actionID = $this->action->create('case', $oldCase->id, 'edited'); $this->action->logHistory($actionID, $changes); } } return !dao::isError(); } /** * Batch change branch of scenes. * * @param array $sceneIdList * @param int $branchID * @access public * @return bool */ public function batchChangeSceneBranch(array $sceneIdList, int $branchID): bool { if(!$sceneIdList) return false; if($branchID < 0 || $branchID > 16777215) return false; // The branch column's data type is mediumint unsigned and its range is 0-16777215. $oldScenes = $this->getScenesByList($sceneIdList, "branch != '{$branchID}'"); if(!$oldScenes) return false; $scene = new stdclass(); $scene->branch = $branchID; $scene->lastEditedBy = $this->app->user->account; $scene->lastEditedDate = helper::now(); $this->dao->update(TABLE_SCENE)->data($scene)->where('id')->in(array_keys($oldScenes))->exec(); if(dao::isError()) return false; $this->loadModel('action'); foreach($oldScenes as $oldScene) { $changes = common::createChanges($oldScene, $scene); if($changes) { $actionID = $this->action->create('scene', $oldScene->id, 'edited'); $this->action->logHistory($actionID, $changes); } } return !dao::isError(); } /** * Batch change module of cases and scenes. * * @param array $caseIdList * @param array $sceneIdList * @param int $moduleID * @access public * @return bool */ public function batchChangeModule(array $caseIdList, array $sceneIdList, int $moduleID): bool { if($moduleID < 0 || $moduleID > 16777215) return false; // The module column's data type is mediumint unsigned and its range is 0-16777215. $caseIdList = array_filter($caseIdList); $sceneIdList = array_filter($sceneIdList); if(!$caseIdList && !$sceneIdList) return false; if($caseIdList) $this->batchChangeCaseModule($caseIdList, $moduleID); if($sceneIdList) $this->batchChangeSceneModule($sceneIdList, $moduleID); return !dao::isError(); } /** * Batch change module of cases. * * @param array $caseIdList * @param int $moduleID * @access public * @return bool */ public function batchChangeCaseModule(array $caseIdList, int $moduleID): bool { if(!$caseIdList) return false; if($moduleID < 0 || $moduleID > 16777215) return false; // The module column's data type is mediumint unsigned and its range is 0-16777215. $oldCases = $this->getByList($caseIdList, "module != '{$moduleID}'"); if(!$oldCases) return false; $case = new stdclass(); $case->module = $moduleID; $case->lastEditedBy = $this->app->user->account; $case->lastEditedDate = helper::now(); $this->dao->update(TABLE_CASE)->data($case)->where('id')->in(array_keys($oldCases))->exec(); if(dao::isError()) return false; $this->loadModel('action'); foreach($oldCases as $oldCase) { $changes = common::createChanges($oldCase, $case); if($changes) { $actionID = $this->action->create('case', $oldCase->id, 'edited'); $this->action->logHistory($actionID, $changes); } } return !dao::isError(); } /** * Batch change module of scenes. * * @param array $sceneIdList * @param int $moduleID * @access public * @return bool */ public function batchChangeSceneModule(array $sceneIdList, int $moduleID): bool { if(!$sceneIdList) return false; if($moduleID < 0 || $moduleID > 16777215) return false; // The module column's data type is mediumint unsigned and its range is 0-16777215. $oldScenes = $this->getScenesByList($sceneIdList, "module != '{$moduleID}'"); if(!$oldScenes) return false; $scene = new stdclass(); $scene->module = $moduleID; $scene->lastEditedBy = $this->app->user->account; $scene->lastEditedDate = helper::now(); $this->dao->update(TABLE_SCENE)->data($scene)->where('id')->in(array_keys($oldScenes))->exec(); if(dao::isError()) return false; $this->loadModel('action'); foreach($oldScenes as $oldScene) { $changes = common::createChanges($oldScene, $scene); if($changes) { $actionID = $this->action->create('scene', $oldScene->id, 'edited'); $this->action->logHistory($actionID, $changes); } } return !dao::isError(); } /** * Batch change type of cases. * * @param array $caseIdList * @param string $type * @access public * @return bool */ public function batchChangeType(array $caseIdList, string $type): bool { if(!$type) return false; $caseIdList = array_filter($caseIdList); if(!$caseIdList) return false; $oldCases = $this->getByList($caseIdList, "type != '{$type}'"); if(!$oldCases) return false; $case = new stdClass(); $case->type = $type; $case->lastEditedBy = $this->app->user->account; $case->lastEditedDate = helper::now(); $this->dao->update(TABLE_CASE)->data($case)->autoCheck()->where('id')->in(array_keys($oldCases))->exec(); if(dao::isError()) return false; $this->loadModel('action'); foreach($oldCases as $oldCase) { $changes = common::createChanges($oldCase, $case); if($changes) { $actionID = $this->action->create('case', $oldCase->id, 'Edited', '', ucfirst($type)); $this->action->logHistory($actionID, $changes); } } return !dao::isError(); } /** * Batch confirm story change of cases. * * @param array $caseIdList * @access public * @return bool */ public function batchConfirmStoryChange(array $caseIdList): bool { $caseIdList = array_filter($caseIdList); if(!$caseIdList) return false; $cases = $this->getByList($caseIdList); if(!$cases) return false; $storyIdList = array_unique(array_filter(array_map(function($case){return $case->story;}, $cases))); if(!$storyIdList) return false; $stories = $this->dao->select('id, version')->from(TABLE_STORY)->where('id')->in($storyIdList)->fetchPairs(); $this->loadModel('action'); foreach($cases as $case) { $storyVersion = zget($stories, $case->story, 0); if(!$storyVersion) continue; $this->dao->update(TABLE_CASE)->set('storyVersion')->eq($storyVersion)->where('id')->eq($case->id)->exec(); $this->action->create('case', $case->id, 'confirmed', '', $storyVersion); } return !dao::isError(); } /** * Join steps to a string, thus can diff them. * * @param array $steps * @access public * @return string */ public function joinStep($steps) { $return = ''; if(empty($steps)) return $return; foreach($steps as $step) $return .= $step->desc . ' EXPECT:' . $step->expect . "\n"; return $return; } /** * Create case steps from a bug's step. * * @param string $steps * @access public * @return array */ function createStepsFromBug($steps) { $steps = strip_tags($steps); $caseSteps = array((object)array('desc' => $steps, 'expect' => '')); // the default steps before parse. $lblStep = strip_tags($this->lang->bug->tplStep); $lblResult = strip_tags($this->lang->bug->tplResult); $lblExpect = strip_tags($this->lang->bug->tplExpect); $lblStepPos = strpos($steps, $lblStep); $lblResultPos = strpos($steps, $lblResult); $lblExpectPos = strpos($steps, $lblExpect); if($lblStepPos === false or $lblResultPos === false or $lblExpectPos === false) return $caseSteps; $caseSteps = substr($steps, $lblStepPos + strlen($lblStep), $lblResultPos - strlen($lblStep) - $lblStepPos); $caseExpect = substr($steps, $lblExpectPos + strlen($lblExpect)); $caseSteps = trim($caseSteps); $caseExpect = trim($caseExpect); $caseSteps = explode("\n", trim($caseSteps)); $stepCount = count($caseSteps); foreach($caseSteps as $key => $caseStep) { $expect = $key + 1 == $stepCount ? $caseExpect : ''; $caseSteps[$key] = (object)array('desc' => trim($caseStep), 'expect' => $expect, 'type' => 'item'); } return $caseSteps; } /** * Adjust the action is clickable. * * @param object $case * @param string $action * @access public * @return bool */ public static function isClickable(object $case, string $action): bool { $canBeChanged = common::canBeChanged('case', $case); if(!$canBeChanged) return false; global $config; $action = strtolower($action); if($action == 'confirmchange') return $case->caseStatus != 'wait' && $case->version < $case->caseVersion; if($action == 'confirmstorychange') return $case->needconfirm || (isset($case->browseType) && $case->browseType == 'needconfirm'); if($action == 'createbug') return !empty($case->caseFails) && $case->caseFails > 0; if($action == 'review') return ($config->testcase->needReview || !empty($config->testcase->forceReview)) && (isset($case->caseStatus) ? $case->caseStatus == 'wait' : $case->status == 'wait'); if($action == 'showscript') return $case->auto == 'auto'; return true; } /** * Get fields for import. * * @access public * @return array */ public function getImportFields($productID = 0) { $product = $this->loadModel('product')->getById($productID); if($product && $product->type != 'normal') $this->lang->testcase->branch = $this->lang->product->branchName[$product->type]; $caseLang = $this->lang->testcase; $caseConfig = $this->config->testcase; $fields = explode(',', $caseConfig->exportFields); foreach($fields as $key => $fieldName) { $fieldName = trim($fieldName); $fields[$fieldName] = isset($caseLang->$fieldName) ? $caseLang->$fieldName : $fieldName; unset($fields[$key]); } return $fields; } /** * 导入测试用例到用例库。 * Import cases to lib. * * @param array $cases * @param array $steps * @param array $files * @access public * @return bool */ public function importToLib(array $cases, array $steps, array $files): bool { $this->loadModel('action'); foreach($cases as $case) { /* 如果用例没有 ID,插入用例。 */ /* If case id is not exist, insert it. */ if(!isset($case->id)) { $this->testcaseTao->doCreate($case); if(!dao::isError()) { $caseID = $this->dao->lastInsertID(); $this->action->create('case', $caseID, 'tolib', '', $case->fromCaseID); } } /* 如果用例有 ID,更新用例。 */ /* If case id is exist, update it. */ else { $caseID = $case->id; $this->testcaseTao->doUpdate($case); $this->action->create('case', $caseID, 'updatetolib', '', $case->fromCaseID); $this->dao->delete()->from(TABLE_CASESTEP)->where('`case`')->eq($caseID)->exec(); $removeFiles = $this->dao->select('*')->from(TABLE_FILE)->where('`objectID`')->eq($caseID)->andWhere('objectType')->eq('testcase')->fetchAll('id'); $this->dao->delete()->from(TABLE_FILE)->where('`objectID`')->eq($caseID)->andWhere('objectType')->eq('testcase')->exec(); foreach($removeFiles as $fileID => $file) { if(empty($file->pathname)) continue; $filePath = pathinfo($file->pathname, PATHINFO_BASENAME); $datePath = substr($file->pathname, 0, 6); $filePath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . "{$datePath}/" . $filePath; unlink($filePath); } } $this->testcaseTao->importSteps($caseID, zget($steps, $case->fromCaseID, array())); $this->testcaseTao->importFiles($caseID, zget($files, $case->fromCaseID, array())); } return !dao::isError(); } /** * Import case related modules. * * @param int $libID * @param int $oldModuleID * @param int $maxOrder * @access public * @return void */ public function importCaseRelatedModules($libID, $oldModuleID = 0, $maxOrder = 0) { $moduleID = $this->checkModuleImported($libID, $oldModuleID); if($moduleID) return $moduleID; $oldModule = $this->dao->select('name, parent, grade, `order`, short')->from(TABLE_MODULE)->where('id')->eq($oldModuleID)->fetch(); $oldModule->root = $libID; $oldModule->from = $oldModuleID; $oldModule->type = 'caselib'; if(!empty($maxOrder)) $oldModule->order = $maxOrder + $oldModule->order; $this->dao->insert(TABLE_MODULE)->data($oldModule)->autoCheck()->exec(); if(!dao::isError()) { $newModuleID = $this->dao->lastInsertID(); if($oldModule->parent) { $parentModuleID = $this->importCaseRelatedModules($libID, $oldModule->parent, !empty($maxOrder) ? $maxOrder : 0); $parentModule = $this->dao->select('id, path')->from(TABLE_MODULE)->where('id')->eq($parentModuleID)->fetch(); $parent = $parentModule->id; $path = $parentModule->path . "$newModuleID,"; } else { $path = ",$newModuleID,"; $parent = 0; } $this->dao->update(TABLE_MODULE)->set('parent')->eq($parent)->set('path')->eq($path)->where('id')->eq($newModuleID)->exec(); return $newModuleID; } } /** * Adjust module is can import. * * @param int $libID * @param int $oldModule * @access public * @return int */ public function checkModuleImported($libID, $oldModule = 0) { $module = $this->dao->select('id')->from(TABLE_MODULE) ->where('root')->eq($libID) ->andWhere('`from`')->eq($oldModule) ->andWhere('type')->eq('caselib') ->andWhere('deleted')->eq(0) ->fetch(); if(!$module) return ''; return $module->id; } /** * Build search form. * * @param int $productID * @param array $products * @param int $queryID * @param string $actionURL * @param string $projectID * @access public * @return void */ public function buildSearchForm($productID, $products, $queryID, $actionURL, $projectID = 0, $moduleID = 0, $branch = 0) { $productList = array(); if($this->app->tab == 'project' and empty($productID)) { $productList = $products; } else { $productList = array('all' => $this->lang->all); if(isset($products[$productID])) $productList = array($productID => $products[$productID]) + $productList; } $this->config->testcase->search['params']['product']['values'] = array('') + $productList; $module = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch); $scene = $this->getSceneMenu($productID, $moduleID, $viewType = 'case', $startSceneID = 0, $branch, 0, true); if(!$productID) { $module = array(); foreach($products as $id => $name) $module += $this->loadModel('tree')->getOptionMenu($id, 'case', 0); } $this->config->testcase->search['params']['module']['values'] = $module; $this->config->testcase->search['params']['scene']['values'] = $scene; $this->config->testcase->search['params']['lib']['values'] = $this->loadModel('caselib')->getLibraries(); if($this->session->currentProductType == 'normal') { unset($this->config->testcase->search['fields']['branch']); unset($this->config->testcase->search['params']['branch']); } else { $this->app->loadLang('branch'); $product = $this->loadModel('product')->getByID($productID); $this->config->testcase->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); $this->config->testcase->search['params']['branch']['values'] = array('' => '', '0' => $this->lang->branch->main) + $this->loadModel('branch')->getPairs($productID, '', $projectID) + array('all' => $this->lang->branch->all); } if(!$this->config->testcase->needReview) unset($this->config->testcase->search['params']['status']['values']['wait']); $this->config->testcase->search['actionURL'] = $actionURL; $this->config->testcase->search['queryID'] = $queryID; $this->config->testcase->search['module'] = $this->app->rawModule; $this->loadModel('search')->setSearchParams($this->config->testcase->search); } /** * Print cell data * * @param object $col * @param object $case * @param array $users * @param array $branches * @access public * @return void */ public function printCell($col, $case, $users, $branches, $modulePairs = array(), $browseType = '', $mode = 'datatable', $isCase = 1) { /* Check the product is closed. */ $canBeChanged = common::canBeChanged('case', $case); $canBatchRun = common::hasPriv('testtask', 'batchRun'); $canBatchEdit = common::hasPriv('testcase', 'batchEdit'); $canBatchDelete = common::hasPriv('testcase', 'batchDelete'); $canBatchChangeType = common::hasPriv('testcase', 'batchChangeType'); $canBatchConfirmStoryChange = common::hasPriv('testcase', 'batchConfirmStoryChange'); $canBatchChangeModule = common::hasPriv('testcase', 'batchChangeModule'); $canBatchAction = ($canBatchRun or $canBatchEdit or $canBatchDelete or $canBatchChangeType or $canBatchConfirmStoryChange or $canBatchChangeModule); $canView = common::hasPriv('testcase', 'view'); $caseLink = helper::createLink('testcase', 'view', "caseID=$case->id&version=$case->version"); $account = $this->app->user->account; $fromCaseID = $case->fromCaseID; $id = $col->id; if($col->show) { $class = $id == 'title' ? 'c-name' : 'c-' . $id; $title = ''; if($id == 'title') { $class .= ' text-left'; $title = "title='{$case->title}'"; } if($id == 'status') { $class .= $case->status; $title = "title='" . $this->processStatus('testcase', $case) . "'"; } if(strpos(',bugs,results,stepNumber,', ",$id,") !== false) $title = "title='{$case->$id}'"; if($id == 'actions') $class .= ' c-actions'; if($id == 'lastRunResult') $class .= " {$case->lastRunResult}"; if(strpos(',stage,precondition,keywords,story,', ",{$id},") !== false) $class .= ' text-ellipsis'; if($id == 'title') { if($isCase == 2) { echo "