+ [misc] Add unit tests for bugZen::assignProductRelatedVars() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -111,4 +111,51 @@ class bugZenTest extends baseTest
|
||||
'lanePairs' => !empty($instance->view->lanePairs) ? count($instance->view->lanePairs) : 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test assignProductRelatedVars method.
|
||||
*
|
||||
* @param array $bugs
|
||||
* @param array $products
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function assignProductRelatedVarsTest(array $bugs, array $products): array
|
||||
{
|
||||
$instance = $this->getInstance($this->moduleName, $this->className);
|
||||
|
||||
try
|
||||
{
|
||||
$branchTagOption = $this->invokeArgs('assignProductRelatedVars', [$bugs, $products]);
|
||||
}
|
||||
catch(Throwable $e)
|
||||
{
|
||||
return array(
|
||||
'error' => $e->getMessage(),
|
||||
'branchProduct' => false,
|
||||
'modulesCount' => 0,
|
||||
'productBugOptions' => 0,
|
||||
'branchTagOption' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
if(dao::isError()) return array('error' => dao::getError());
|
||||
|
||||
$branchCount = 0;
|
||||
if(!empty($branchTagOption))
|
||||
{
|
||||
foreach($branchTagOption as $productID => $branches)
|
||||
{
|
||||
$branchCount += count($branches);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'branchProduct' => !empty($instance->view->branchProduct) ? 1 : 0,
|
||||
'modulesCount' => !empty($instance->view->modules) ? count($instance->view->modules) : 0,
|
||||
'productBugOptions' => !empty($instance->view->productBugOptions) ? count($instance->view->productBugOptions) : 0,
|
||||
'branchTagOptionView' => !empty($instance->view->branchTagOption) ? count($instance->view->branchTagOption) : 0,
|
||||
'returnValue' => $branchCount,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 bugZen::assignProductRelatedVars();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:空数据
|
||||
- 属性branchProduct @0
|
||||
- 属性modulesCount @0
|
||||
- 步骤2:正常产品类型无bugs
|
||||
- 属性branchProduct @0
|
||||
- 属性modulesCount @3
|
||||
- 步骤3:分支产品类型
|
||||
- 属性branchProduct @1
|
||||
- 属性modulesCount @2
|
||||
- 步骤4:混合产品类型
|
||||
- 属性branchProduct @1
|
||||
- 属性modulesCount @2
|
||||
- 步骤5:多个分支产品
|
||||
- 属性branchProduct @1
|
||||
- 属性modulesCount @3
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zen.class.php';
|
||||
|
||||
zenData('product')->loadYaml('product_assignproductrelatedvars', false, 2)->gen(10);
|
||||
zenData('bug')->loadYaml('bug_assignproductrelatedvars', false, 2)->gen(20);
|
||||
zenData('branch')->loadYaml('branch_assignproductrelatedvars', false, 2)->gen(10);
|
||||
zenData('module')->gen(20);
|
||||
zenData('productplan')->gen(10);
|
||||
|
||||
su('admin');
|
||||
|
||||
$bugTest = new bugZenTest();
|
||||
|
||||
$emptyBugs = array();
|
||||
$emptyProducts = array();
|
||||
|
||||
$normalProducts = array(
|
||||
(object)array('id' => 1, 'name' => '产品1', 'type' => 'normal'),
|
||||
(object)array('id' => 2, 'name' => '产品2', 'type' => 'normal'),
|
||||
(object)array('id' => 3, 'name' => '产品3', 'type' => 'normal')
|
||||
);
|
||||
|
||||
$branchProducts = array(
|
||||
(object)array('id' => 6, 'name' => 'Product6', 'type' => 'branch'),
|
||||
(object)array('id' => 7, 'name' => 'Product7', 'type' => 'branch')
|
||||
);
|
||||
|
||||
$mixedProducts = array(
|
||||
(object)array('id' => 1, 'name' => '产品1', 'type' => 'normal'),
|
||||
(object)array('id' => 6, 'name' => 'Product6', 'type' => 'branch')
|
||||
);
|
||||
|
||||
$singleNormalProduct = array(
|
||||
(object)array('id' => 1, 'name' => '产品1', 'type' => 'normal')
|
||||
);
|
||||
|
||||
$multipleBranchProducts = array(
|
||||
(object)array('id' => 6, 'name' => 'Product6', 'type' => 'branch'),
|
||||
(object)array('id' => 7, 'name' => 'Product7', 'type' => 'branch'),
|
||||
(object)array('id' => 8, 'name' => 'Product8', 'type' => 'platform')
|
||||
);
|
||||
|
||||
r($bugTest->assignProductRelatedVarsTest($emptyBugs, $emptyProducts)) && p('branchProduct,modulesCount') && e('0,0'); // 步骤1:空数据
|
||||
r($bugTest->assignProductRelatedVarsTest($emptyBugs, $normalProducts)) && p('branchProduct,modulesCount') && e('0,3'); // 步骤2:正常产品类型无bugs
|
||||
r($bugTest->assignProductRelatedVarsTest($emptyBugs, $branchProducts)) && p('branchProduct,modulesCount') && e('1,2'); // 步骤3:分支产品类型
|
||||
r($bugTest->assignProductRelatedVarsTest($emptyBugs, $mixedProducts)) && p('branchProduct,modulesCount') && e('1,2'); // 步骤4:混合产品类型
|
||||
r($bugTest->assignProductRelatedVarsTest($emptyBugs, $multipleBranchProducts)) && p('branchProduct,modulesCount') && e('1,3'); // 步骤5:多个分支产品
|
||||
Reference in New Issue
Block a user