From 79e71873c52e0cf9a73cf3fff043b10e43d5dac6 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 4 Jul 2022 15:50:03 +0800 Subject: [PATCH 1/9] * Finish task #59477. --- module/testcase/control.php | 2 +- module/testsuite/model.php | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index fda3c10423..ec1599aa1b 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1902,7 +1902,7 @@ class testcase extends control $this->view->product = $product; $this->view->productID = $productID; $this->view->branch = $branch; - $this->view->cases = $this->loadModel('testsuite')->getNotImportedCases($productID, $libID, $orderBy, $pager, $browseType, $queryID); + $this->view->cases = $this->loadModel('testsuite')->getLibCases($productID, $libID, $orderBy, $pager, $browseType, $queryID); $this->view->modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch === 'all' ? 0 : (int)$branch); $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); $this->view->pager = $pager; diff --git a/module/testsuite/model.php b/module/testsuite/model.php index 9a905698b3..f995a6dc75 100644 --- a/module/testsuite/model.php +++ b/module/testsuite/model.php @@ -314,7 +314,7 @@ class testsuiteModel extends model } /** - * Get not imported cases. + * Get lib cases. * * @param int $productID * @param int $libID @@ -323,7 +323,7 @@ class testsuiteModel extends model * @access public * @return array */ - public function getNotImportedCases($productID, $libID, $orderBy = 'id_desc', $pager = null, $browseType = '', $queryID = 0) + public function getLibCases($productID, $libID, $orderBy = 'id_desc', $pager = null, $browseType = '', $queryID = 0, $param = '') { $importedCases = $this->dao->select('fromCaseID')->from(TABLE_CASE) ->where('product')->eq($productID) @@ -361,18 +361,17 @@ class testsuiteModel extends model ->beginIF($browseType != 'bysearch')->andWhere('lib')->eq($libID)->fi() ->beginIF($browseType == 'bysearch')->andWhere($query)->fi() ->andWhere('product')->eq(0) - ->andWhere('id')->notIN($importedCases) + ->beginIF(strpos($param, "canimport") !== false)->andWhere('id')->notIN($importedCases)->fi() ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); } - /** - * Build testsuite menu. - * - * @param object $suite - * @param string $type + * Build testsuite menu. + * + * @param object $suite + * @param string $type * @access public * @return string */ From 8fd283cec3ad5fa4027bc59a5c9ab641b5b68a0c Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 4 Jul 2022 15:56:40 +0800 Subject: [PATCH 2/9] * Finish task #59477. --- module/testsuite/model.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/module/testsuite/model.php b/module/testsuite/model.php index f995a6dc75..33e83c4421 100644 --- a/module/testsuite/model.php +++ b/module/testsuite/model.php @@ -323,15 +323,8 @@ class testsuiteModel extends model * @access public * @return array */ - public function getLibCases($productID, $libID, $orderBy = 'id_desc', $pager = null, $browseType = '', $queryID = 0, $param = '') + public function getLibCases($productID, $libID, $orderBy = 'id_desc', $pager = null, $browseType = '', $queryID = 0) { - $importedCases = $this->dao->select('fromCaseID')->from(TABLE_CASE) - ->where('product')->eq($productID) - ->andWhere('lib')->eq($libID) - ->andWhere('fromCaseID')->ne('') - ->andWhere('deleted')->eq(0) - ->fetchPairs('fromCaseID', 'fromCaseID'); - $query = ''; if($browseType == 'bysearch') { @@ -361,7 +354,6 @@ class testsuiteModel extends model ->beginIF($browseType != 'bysearch')->andWhere('lib')->eq($libID)->fi() ->beginIF($browseType == 'bysearch')->andWhere($query)->fi() ->andWhere('product')->eq(0) - ->beginIF(strpos($param, "canimport") !== false)->andWhere('id')->notIN($importedCases)->fi() ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); From d1f25755f1abefbf5cd6fed5a9c8df06203095c3 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 5 Jul 2022 09:39:55 +0800 Subject: [PATCH 3/9] * Finish task #59477. --- module/testcase/control.php | 43 +++++++++++---------- module/testcase/model.php | 9 +++-- module/testcase/view/importfromlib.html.php | 3 +- module/testsuite/model.php | 23 +++++++++++ 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index ec1599aa1b..8ccdf7d6ee 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1860,14 +1860,6 @@ class testcase extends control $this->loadModel('branch'); if($product->type != 'normal') $branches = array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active', $projectID); - if($_POST) - { - $this->testcase->importFromLib($productID); - return print(js::reload('parent')); - } - - $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch); - $libraries = $this->loadModel('caselib')->getLibraries(); if(empty($libraries)) { @@ -1876,6 +1868,14 @@ class testcase extends control } if(empty($libID) or !isset($libraries[$libID])) $libID = key($libraries); + if($_POST) + { + $this->testcase->importFromLib($productID, $libID); + return print(js::reload('parent')); + } + + $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch); + /* Build the search form. */ $actionURL = $this->createLink('testcase', 'importFromLib', "productID=$productID&branch=$branch&libID=$libID&orderBy=$orderBy&browseType=bySearch&queryID=myQueryID"); $this->config->testcase->search['module'] = 'testsuite'; @@ -1897,19 +1897,20 @@ class testcase extends control $this->view->title = $this->lang->testcase->common . $this->lang->colon . $this->lang->testcase->importFromLib; $this->view->position[] = $this->lang->testcase->importFromLib; - $this->view->libraries = $libraries; - $this->view->libID = $libID; - $this->view->product = $product; - $this->view->productID = $productID; - $this->view->branch = $branch; - $this->view->cases = $this->loadModel('testsuite')->getLibCases($productID, $libID, $orderBy, $pager, $browseType, $queryID); - $this->view->modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch === 'all' ? 0 : (int)$branch); - $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); - $this->view->pager = $pager; - $this->view->orderBy = $orderBy; - $this->view->branches = $branches; - $this->view->browseType = $browseType; - $this->view->queryID = $queryID; + $this->view->libraries = $libraries; + $this->view->libID = $libID; + $this->view->product = $product; + $this->view->productID = $productID; + $this->view->branch = $branch; + $this->view->cases = $this->loadModel('testsuite')->getLibCases($productID, $libID, $orderBy, $pager, $browseType, $queryID); + $this->view->modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch === 'all' ? 0 : (int)$branch); + $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); + $this->view->pager = $pager; + $this->view->orderBy = $orderBy; + $this->view->branches = $branches; + $this->view->browseType = $browseType; + $this->view->queryID = $queryID; + $this->view->importedModules = $this->testsuite->getImportedModules($productID, $libID); $this->display(); } diff --git a/module/testcase/model.php b/module/testcase/model.php index 169ab985b3..714f46cfa4 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -1576,19 +1576,22 @@ class testcaseModel extends model * Import case from Lib. * * @param int $productID + * @param int $libID * @access public * @return void */ - public function importFromLib($productID) + public function importFromLib($productID, $libID = 0) { $data = fixer::input('post')->get(); - $prevModule = 0; - $prevBranch = 0; + $prevModule = 0; + $prevBranch = 0; + $importedModules = $this->loadModel('testsuite')->getImportedModules($productID, $libID); foreach($data->module as $i => $module) { if($module != 'ditto') $prevModule = $module; if($module == 'ditto') $data->module[$i] = $prevModule; + if(isset($importedModules[$i][$data->module[$i]])) unset($data->caseIdList[$i]); } if(isset($data->branch)) diff --git a/module/testcase/view/importfromlib.html.php b/module/testcase/view/importfromlib.html.php index f25864f2ab..8ee1c69919 100644 --- a/module/testcase/view/importfromlib.html.php +++ b/module/testcase/view/importfromlib.html.php @@ -65,7 +65,8 @@ 0) $modules['ditto'] = $lang->testcase->ditto;?> - id}]", $modules, $i == 0 ? 0 : 'ditto', "class='form-control chosen'");?> + id]) ? $importedModules[$case->id] : array();?> + id}]", array_diff_key($modules, $importedCaseModules), $i == 0 ? 0 : 'ditto', "class='form-control chosen'");?> testcase->typeList, $case->type);?> diff --git a/module/testsuite/model.php b/module/testsuite/model.php index 33e83c4421..e6f71df1bb 100644 --- a/module/testsuite/model.php +++ b/module/testsuite/model.php @@ -359,6 +359,29 @@ class testsuiteModel extends model ->fetchAll('id'); } + /** + * Get imported case modules. + * + * @param int $productID + * @param int $libID + * @param string $orderBy + * @param object $pager + * @access public + * @return array + */ + public function getImportedModules($productID, $libID) + { + $importedModules = $this->dao->select('fromCaseID,module')->from(TABLE_CASE) + ->where('product')->eq($productID) + ->andWhere('lib')->eq($libID) + ->andWhere('fromCaseID')->ne('') + ->andWhere('deleted')->eq(0) + ->fetchGroup('fromCaseID', 'module'); + foreach($importedModules as $fromCaseID => $modules) $importedModules[$fromCaseID] = array_combine(array_keys($modules), array_keys($modules)); + + return $importedModules; + } + /** * Build testsuite menu. * From 57c87e59124b283771058a07ffb5c1b274c787b6 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 5 Jul 2022 13:52:57 +0800 Subject: [PATCH 4/9] * Finish task #59477. --- module/testcase/control.php | 33 +++++++++++---------- module/testcase/js/importfromlib.js | 24 +++++++++++---- module/testcase/model.php | 23 +++++++++----- module/testcase/view/importfromlib.html.php | 6 ++-- module/testsuite/model.php | 27 +++++++++++++---- 5 files changed, 76 insertions(+), 37 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index 8ccdf7d6ee..b4fe25fa16 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1870,7 +1870,7 @@ class testcase extends control if($_POST) { - $this->testcase->importFromLib($productID, $libID); + $this->testcase->importFromLib($productID, $libID, $branch); return print(js::reload('parent')); } @@ -1890,6 +1890,9 @@ class testcase extends control unset($this->config->testcase->search['fields']['branch']); $this->loadModel('search')->setSearchParams($this->config->testcase->search); + $this->loadModel('testsuite'); + foreach($branches as $branchID => $branchName) $canImportModules[$branchID] = $this->testsuite->getCanImportModules($productID, $libID, $branchID); + /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init(0, $recPerPage, $pageID); @@ -1897,20 +1900,20 @@ class testcase extends control $this->view->title = $this->lang->testcase->common . $this->lang->colon . $this->lang->testcase->importFromLib; $this->view->position[] = $this->lang->testcase->importFromLib; - $this->view->libraries = $libraries; - $this->view->libID = $libID; - $this->view->product = $product; - $this->view->productID = $productID; - $this->view->branch = $branch; - $this->view->cases = $this->loadModel('testsuite')->getLibCases($productID, $libID, $orderBy, $pager, $browseType, $queryID); - $this->view->modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch === 'all' ? 0 : (int)$branch); - $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); - $this->view->pager = $pager; - $this->view->orderBy = $orderBy; - $this->view->branches = $branches; - $this->view->browseType = $browseType; - $this->view->queryID = $queryID; - $this->view->importedModules = $this->testsuite->getImportedModules($productID, $libID); + $this->view->libraries = $libraries; + $this->view->libID = $libID; + $this->view->product = $product; + $this->view->productID = $productID; + $this->view->branch = $branch; + $this->view->cases = $this->testsuite->getCanImportCases($productID, $libID, $branch, $orderBy, $pager, $browseType, $queryID); + $this->view->modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch === 'all' ? 0 : (int)$branch); + $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); + $this->view->pager = $pager; + $this->view->orderBy = $orderBy; + $this->view->branches = $branches; + $this->view->browseType = $browseType; + $this->view->queryID = $queryID; + $this->view->canImportModules = $canImportModules; $this->display(); } diff --git a/module/testcase/js/importfromlib.js b/module/testcase/js/importfromlib.js index c0e851db04..5a121f4703 100644 --- a/module/testcase/js/importfromlib.js +++ b/module/testcase/js/importfromlib.js @@ -52,14 +52,14 @@ function updateModules(productID, branch, caseID) var tr = $('#module' + caseID).closest('tr'); if(branch !== 'ditto') { - loadModules(tr, caseID, moduleLink); + loadModules(tr, caseID, moduleLink, undefined, branch); tr.nextAll().each(function() { var nextCaseID = $(this).attr('id'); var nextBranch = $('#branch' + nextCaseID + ' option:selected').val(); if(nextBranch !== 'ditto') return false; var nextTr = $('#module' + nextCaseID).closest('tr'); - loadModules(nextTr, nextCaseID, moduleLink, true); + loadModules(nextTr, nextCaseID, moduleLink, true, branch); }); } else @@ -76,14 +76,14 @@ function updateModules(productID, branch, caseID) } }); link = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=case&branch=' + branchID + '&rootModuleID=0&returnType=html&fieldID=&needManage=true'); - loadModules(tr, caseID, link, true); + loadModules(tr, caseID, link, true, branchID); tr.nextAll().each(function() { var nextCaseID = $(this).attr('id'); var nextBranch = $('#branch' + nextCaseID + ' option:selected').val(); if(nextBranch !== 'ditto') return false; var nextTr = $('#module' + nextCaseID).closest('tr'); - loadModules(nextTr, nextCaseID, link, true); + loadModules(nextTr, nextCaseID, link, true, branchID); }); } } @@ -95,17 +95,31 @@ function updateModules(productID, branch, caseID) * @param int $caseID * @param string $link * @param boolean $isAddDitto + * @param int $branch * @access public * @return void */ -function loadModules(tr, caseID, link, isAddDitto) +function loadModules(tr, caseID, link, isAddDitto, branch) { var isAddDitto = (typeof(isAddDitto) === 'undefined') ? false : true; $('#module' + caseID).parent('td').load(link, function(data) { + if(canImportModules[branch][caseID] != undefined && Object.keys(canImportModules[branch][caseID]).length > 0) + { + $('tr select#module').children().each(function() + { + moduleID = $(this).val(); + if(canImportModules[branch][caseID][moduleID] == undefined) + { + $(this).remove(); + } + }) + } + tr.find('#module').chosen(); tr.find('#module').attr({"id": 'module' + caseID, "name": 'module[' + caseID + ']'}); + tr.find('#module' + caseID).removeAttr('onchange'); if(isAddDitto == true) addDittoOption(caseID); }); } diff --git a/module/testcase/model.php b/module/testcase/model.php index 714f46cfa4..be90a1dd5e 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -1580,32 +1580,37 @@ class testcaseModel extends model * @access public * @return void */ - public function importFromLib($productID, $libID = 0) + public function importFromLib($productID, $libID, $branch) { $data = fixer::input('post')->get(); - $prevModule = 0; - $prevBranch = 0; - $importedModules = $this->loadModel('testsuite')->getImportedModules($productID, $libID); + $prevModule = 0; + $prevBranch = 0; foreach($data->module as $i => $module) { if($module != 'ditto') $prevModule = $module; if($module == 'ditto') $data->module[$i] = $prevModule; - if(isset($importedModules[$i][$data->module[$i]])) unset($data->caseIdList[$i]); } + $caseModules = array(); + $this->loadModel('testsuite'); if(isset($data->branch)) { foreach($data->branch as $i => $branch) { if($branch != 'ditto') $prevBranch = $branch; if($branch == 'ditto') $data->branch[$i] = $prevBranch; + if(!isset($caseModules[$data->branch[$i]])) $caseModules[$data->branch[$i]] = $this->testsuite->getCanImportModules($productID, $libID, $data->branch[$i]); } } + else + { + $caseModules[$branch] = $this->loadModel('testsuite')->getCanImportModules($productID, $libID, $branch); + } - $libCases = $this->dao->select('*')->from(TABLE_CASE)->where('deleted')->eq(0)->andWhere('id')->in($data->caseIdList)->fetchAll('id'); - $libSteps = $this->dao->select('*')->from(TABLE_CASESTEP)->where('`case`')->in($data->caseIdList)->orderBy('id')->fetchGroup('case'); - $libFiles = $this->dao->select('*')->from(TABLE_FILE)->where('objectID')->in($data->caseIdList)->andWhere('objectType')->eq('testcase')->fetchGroup('objectID', 'id'); + $libCases = $this->dao->select('*')->from(TABLE_CASE)->where('deleted')->eq(0)->andWhere('id')->in($data->caseIdList)->fetchAll('id'); + $libSteps = $this->dao->select('*')->from(TABLE_CASESTEP)->where('`case`')->in($data->caseIdList)->orderBy('id')->fetchGroup('case'); + $libFiles = $this->dao->select('*')->from(TABLE_FILE)->where('objectID')->in($data->caseIdList)->andWhere('objectType')->eq('testcase')->fetchGroup('objectID', 'id'); foreach($libCases as $libCaseID => $case) { $case->fromCaseID = $case->id; @@ -1615,6 +1620,8 @@ class testcaseModel extends model if(isset($data->branch[$case->id])) $case->branch = $data->branch[$case->id]; unset($case->id); + if(isset($caseModules[$data->branch[$i]][$case->fromCaseID]) and !isset($caseModules[$data->branch[$i]][$case->fromCaseID][$case->module])) continue; + $this->dao->insert(TABLE_CASE)->data($case)->autoCheck()->exec(); if(!dao::isError()) diff --git a/module/testcase/view/importfromlib.html.php b/module/testcase/view/importfromlib.html.php index 8ee1c69919..679f925f78 100644 --- a/module/testcase/view/importfromlib.html.php +++ b/module/testcase/view/importfromlib.html.php @@ -13,6 +13,7 @@ global->flow);?> testcase->ditto);?> +