diff --git a/module/product/test/lib/zen.class.php b/module/product/test/lib/zen.class.php index 8695328282..df7fe34059 100644 --- a/module/product/test/lib/zen.class.php +++ b/module/product/test/lib/zen.class.php @@ -800,4 +800,27 @@ class productZenTest extends baseTest if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test getUnauthProgramsOfProducts method. + * + * @param array $products + * @param array $authPrograms + * @access public + * @return array + */ + public function getUnauthProgramsOfProductsTest(array $products = array(), array $authPrograms = array()) + { + global $tester; + + /* Ensure program model is loaded. */ + if(!isset($this->instance->program)) + { + $this->instance->program = $tester->loadModel('program'); + } + + $result = $this->invokeArgs('getUnauthProgramsOfProducts', array($products, $authPrograms)); + if(dao::isError()) return dao::getError(); + return $result; + } } diff --git a/module/product/test/zen/getunauthprogramsofproducts.php b/module/product/test/zen/getunauthprogramsofproducts.php new file mode 100755 index 0000000000..c5ff2795e9 --- /dev/null +++ b/module/product/test/zen/getunauthprogramsofproducts.php @@ -0,0 +1,76 @@ +#!/usr/bin/env php +loadYaml('getunauthprogramsofproducts', false, 2)->gen(30); + +su('admin'); + +$productTest = new productZenTest(); + +// 准备测试数据 +// 测试步骤1: 产品关联未授权项目集 +$products1 = array(); +$product1 = new stdclass(); +$product1->id = 1; +$product1->name = 'Product 1'; +$product1->program = 10; +$products1[] = $product1; + +$authPrograms1 = array(1 => 'Authorized Program 1', 2 => 'Authorized Program 2'); + +// 测试步骤2: 产品无关联项目集(program=0) +$products2 = array(); +$product2 = new stdclass(); +$product2->id = 2; +$product2->name = 'Product 2'; +$product2->program = 0; +$products2[] = $product2; + +$authPrograms2 = array(1 => 'Authorized Program 1'); + +// 测试步骤3: 产品关联的项目集都已授权 +$products3 = array(); +$product3 = new stdclass(); +$product3->id = 3; +$product3->name = 'Product 3'; +$product3->program = 5; +$products3[] = $product3; + +$authPrograms3 = array(5 => 'Authorized Program 5', 6 => 'Authorized Program 6'); + +// 测试步骤4: 空产品列表 +$products4 = array(); +$authPrograms4 = array(1 => 'Authorized Program 1'); + +// 测试步骤5: 单个产品关联未授权项目集(使用生成的项目集ID:10) +$products5 = array(); +$product5 = new stdclass(); +$product5->id = 15; +$product5->name = 'Product 15'; +$product5->program = 10; +$products5[] = $product5; + +$authPrograms5 = array(5 => 'Authorized Program 5', 11 => 'Authorized Program 11'); + +r(count($productTest->getUnauthProgramsOfProductsTest($products1, $authPrograms1))) && p() && e('1'); +r(count($productTest->getUnauthProgramsOfProductsTest($products2, $authPrograms2))) && p() && e('0'); +r(count($productTest->getUnauthProgramsOfProductsTest($products3, $authPrograms3))) && p() && e('0'); +r(count($productTest->getUnauthProgramsOfProductsTest($products4, $authPrograms4))) && p() && e('0'); +r(count($productTest->getUnauthProgramsOfProductsTest($products5, $authPrograms5))) && p() && e('1'); \ No newline at end of file diff --git a/module/product/test/zen/yaml/getunauthprogramsofproducts/zt_project.yaml b/module/product/test/zen/yaml/getunauthprogramsofproducts/zt_project.yaml new file mode 100644 index 0000000000..eb76555a7d --- /dev/null +++ b/module/product/test/zen/yaml/getunauthprogramsofproducts/zt_project.yaml @@ -0,0 +1,61 @@ +--- +title: 项目集测试数据 +desc: 为getUnauthProgramsOfProducts方法提供项目集测试数据 + +fields: +- field: id + note: 项目集ID + range: 1-30 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 项目集名称 + range: Unauthorized Program {1-30} + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: type + note: 类型 + range: program + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: grade + note: 等级 + range: 1 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: parent + note: 父项目集 + range: 0 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: status + note: 状态 + range: doing + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: acl + note: 访问控制 + range: open + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: deleted + note: 是否删除 + range: 0 + prefix: "" + postfix: "" + loop: 0 + format: ""