diff --git a/module/product/tao.php b/module/product/tao.php index 83a00a1316..d6cfcc22aa 100644 --- a/module/product/tao.php +++ b/module/product/tao.php @@ -524,8 +524,10 @@ class productTao extends productModel * @access private * @return string */ - private function getBranchSelect4Mobile(object $product, string|int $branch, string $currentModule, string $currentMethod, string $extra = ''): string + protected function getBranchSelect4Mobile(object $product, string|int $branch, string $currentModule, string $currentMethod, string $extra = ''): string { + if(!isset($product->type) or $product->type == 'normal') return ''; + /* 修正分支显示语言项。 */ $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); $this->lang->product->menu->settings['subMenu']->branch['link'] = str_replace('@branch@', $this->lang->product->branch, $this->lang->product->menu->settings['subMenu']->branch['link']); @@ -533,7 +535,7 @@ class productTao extends productModel /* 生成分支HTML代码。*/ $output = ''; $branches = $this->loadModel('branch')->getPairs($product->id, 'all'); - $branchName = zget($branches, $branch, ''); + $branchName = zget($branches, $branch, reset($branches)); if($branchName) $output .= "id}', '$currentModule', '$currentMethod', '$extra')\">{$branchName}
"; return $output; @@ -743,8 +745,8 @@ class productTao extends productModel if(!isset($products[$productID])) $productID = (int)key($products); /* 检测当前页面是否在项目或执行的测试二级导航中。*/ - $isQaModule = (strpos(',project,execution,', ",{$this->app->tab},") !== false and strpos(',bug,testcase,testtask,ajaxselectstory,', ",{$this->app->rawMethod},") !== false) ? true : false; - if($this->app->tab == 'project' and strpos(',zeroCase,browseUnits,groupCase,', ",$currentMethod,") !== false) $isQaModule = true; + $isQaModule = (strpos(',project,execution,', ",{$this->app->tab},") !== false and stripos(',bug,testcase,testtask,ajaxselectstory,', ",{$this->app->rawMethod},") !== false) ? true : false; + if($this->app->tab == 'project' and stripos(',zeroCase,browseUnits,groupCase,', ",$currentMethod,") !== false) $isQaModule = true; if($isQaModule) { if($this->app->tab == 'project') $extra = strpos(',testcase,groupCase,zeroCase,', ",$currentMethod,") !== false ? $extra : $this->session->project; @@ -753,7 +755,6 @@ class productTao extends productModel /* 查询产品数据。*/ $currentProduct = $this->getById($productID); - if(empty($currentProduct)) return ''; $this->session->set('currentProductType', $currentProduct->type); /* 生成异步获取下拉菜单的链接。*/ diff --git a/module/product/test/product.class.php b/module/product/test/product.class.php index 7f597934b1..98875227fd 100644 --- a/module/product/test/product.class.php +++ b/module/product/test/product.class.php @@ -1139,4 +1139,34 @@ class productTest return array('hasProduct' => $hasProduct, 'hasBranch' => $hasBranch); } + + /** + * 测试 buildSelect4Mobile 方法。 + * Test buildSelect4Mobile + * + * @param array $products + * @param int $productID + * @param string $currentModule + * @param string $currentMethod + * @param string $extra + * @param string|int $branch + * @param bool $withBranch + * @access public + * @return array + */ + public function buildSelect4MobileTest(array $products, int $productID, string $currentModule, string $currentMethod, string $extra = '', string|int $branch = '', bool $withBranch = true): array + { + $this->objectModel->lang->product->menu->settings['subMenu']->branch = array('link' => "@branch@|branch|manage|product=%s", 'subModule' => 'branch'); + + $select = $this->objectModel->buildSelect4Mobile($products, $productID, $currentModule, $currentMethod, $extra, $branch, $withBranch); + + $productName = zget($products, $productID, reset($products)); + $branchName = '所有'; + if(is_numeric($branch)) $branchName = $this->objectModel->dao->select('*')->from(TABLE_BRANCH)->where('id')->eq($branch)->fetch('name'); + + $hasProduct = (int)(strpos($select, 'currentItem') !== false and strpos($select, $productName) !== false); + $hasBranch = (int)(strpos($select, 'currentBranch') !== false and strpos($select, $branchName) !== false); + + return array('hasProduct' => $hasProduct, 'hasBranch' => $hasBranch); + } } diff --git a/module/product/test/tao/buildselect4mobile.php b/module/product/test/tao/buildselect4mobile.php new file mode 100755 index 0000000000..d8bdc27fac --- /dev/null +++ b/module/product/test/tao/buildselect4mobile.php @@ -0,0 +1,52 @@ +#!/usr/bin/env php +gen(50); +$branch = zdTable('branch'); +$branch->product->range('41'); +$branch->gen(5); + +/** + +title=测试productModel->buildSelect4Mobile(); +timeout=0 +cid=1 + +*/ + +$productTest = new productTest('admin'); +$productTest->objectModel->dao->update(TABLE_PRODUCT)->set('deleted')->eq(1)->where('id')->eq(49)->exec(); +$products = $productTest->objectModel->dao->select('*')->from(TABLE_PRODUCT)->where('deleted')->eq(0)->fetchPairs('id', 'name'); + +$moduleName = 'product'; +$methodName = 'browse'; +r($productTest->buildSelect4MobileTest(array(), 0, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('0,0'); +r($productTest->buildSelect4MobileTest($products, 0, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,0'); +r($productTest->buildSelect4MobileTest($products, 1, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,0'); +r($productTest->buildSelect4MobileTest($products, 49, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,0'); +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,1'); +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName, '', 1)) && p('hasProduct,hasBranch') && e('1,1'); +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName, '', '', false)) && p('hasProduct,hasBranch') && e('1,0'); +r($productTest->buildSelect4MobileTest($products, 70, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,0'); + +$productTest->objectModel->app->tab = 'project'; +$moduleName = 'project'; +$methodName = 'testcase'; +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,1'); +$moduleName = 'testcase'; +$methodName = 'groupCase'; +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,1'); + +$productTest->objectModel->app->tab = 'execution'; +$moduleName = 'execution'; +$methodName = 'bug'; +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,1'); +$methodName = 'task'; +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,1'); + +$productTest->objectModel->app->tab = 'feedback'; +$moduleName = 'bug'; +$methodName = 'view'; +r($productTest->buildSelect4MobileTest($products, 41, $moduleName, $methodName)) && p('hasProduct,hasBranch') && e('1,1'); diff --git a/module/product/test/tao/getbranchselect4mobile.php b/module/product/test/tao/getbranchselect4mobile.php new file mode 100755 index 0000000000..ca283b12f1 --- /dev/null +++ b/module/product/test/tao/getbranchselect4mobile.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +gen(50); +$branch = zdTable('branch'); +$branch->product->range('41'); +$branch->gen(5); + +/** + +title=测试productModel->getBranchSelect4Mobile(); +timeout=0 +cid=1 + +*/ + +global $tester; +$productTest = $tester->loadModel('product'); +$product = $productTest->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq(1)->fetch(); + +$moduleName = 'product'; +$methodName = 'browse'; +r($productTest->getBranchSelect4Mobile(new stdclass(), '', $moduleName, $methodName)) && p() && e('0'); +r($productTest->getBranchSelect4Mobile($product, '', $moduleName, $methodName)) && p() && e('0'); + +$product = $productTest->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq(41)->fetch(); +$result = $productTest->getBranchSelect4Mobile($product, 'all', $moduleName, $methodName); +r((strpos($result, 'currentBranch') !== false and strpos($result, '所有') !== false)) && p() && e('1'); + +$result = $productTest->getBranchSelect4Mobile($product, 1, $moduleName, $methodName); +r((strpos($result, 'currentBranch') !== false and strpos($result, '分支1') !== false)) && p() && e('1'); diff --git a/module/product/test/tao/getbranchselect4pc.php b/module/product/test/tao/getbranchselect4pc.php new file mode 100755 index 0000000000..693fe8dfc5 --- /dev/null +++ b/module/product/test/tao/getbranchselect4pc.php @@ -0,0 +1,44 @@ +#!/usr/bin/env php +gen(50); +$branch = zdTable('branch'); +$branch->product->range('41'); +$branch->gen(5); + +/** + +title=测试productModel->getBranchSelect4PC(); +timeout=0 +cid=1 + +*/ + +global $tester; +$productTest = $tester->loadModel('product'); +$product = $productTest->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq(1)->fetch(); + +$moduleName = 'product'; +$methodName = 'browse'; +r($productTest->getBranchSelect4PC(new stdclass(), '', $moduleName, $methodName)) && p() && e('0'); +r($productTest->getBranchSelect4PC($product, '', $moduleName, $methodName)) && p() && e('0'); + +$product = $productTest->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq(41)->fetch(); +$result = $productTest->getBranchSelect4PC($product, '', $moduleName, $methodName); +r((strpos($result, 'currentBranch') !== false and strpos($result, '所有') !== false)) && p() && e('1'); + +$result = $productTest->getBranchSelect4PC($product, 1, $moduleName, $methodName); +r((strpos($result, 'currentBranch') !== false and strpos($result, '分支1') !== false)) && p() && e('1'); + +r((strpos($productTest->getBranchSelect4PC($product, 1, 'testcase', 'showimport'), 'currentBranch') !== false)) && p() && e('0'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'tree', 'browse'), 'currentBranch') !== false)) && p() && e('1'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'product', 'view'), 'currentBranch') !== false)) && p() && e('0'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'release', 'create'), 'currentBranch') !== false)) && p() && e('1'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'release', 'view'), 'currentBranch') !== false)) && p() && e('0'); + +$productTest->app->tab = 'qa'; +r((strpos($productTest->getBranchSelect4PC($product, 1, 'bug', 'view'), 'currentBranch') !== false)) && p() && e('1'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'testcase', 'view'), 'currentBranch') !== false)) && p() && e('1'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'testtask', 'view'), 'currentBranch') !== false)) && p() && e('1'); +r((strpos($productTest->getBranchSelect4PC($product, 1, 'testtask', 'create'), 'currentBranch') !== false)) && p() && e('0'); diff --git a/test/data/branch.yaml b/test/data/branch.yaml index 6617f10ca2..6c61444ab9 100644 --- a/test/data/branch.yaml +++ b/test/data/branch.yaml @@ -16,6 +16,8 @@ fields: range: 分支 - field: name2 range: 1-10000 + - field: desc + range: "" - field: status range: active,closed - field: order @@ -25,6 +27,10 @@ fields: postfix: "" loop: 0 format: "" + - field: createdDate + range: "(-3M)-(+M):1D" + type: timestamp + format: "YY/MM/DD" - field: deleted note: "是否删除" range: 0