From bc3dd94e6e332a66241076dd3f58d51e1784d98a Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 1 Dec 2023 16:06:14 +0800 Subject: [PATCH] * Refactor doc::updateLib unit test. --- module/doc/test/doc.class.php | 22 +++++----- module/doc/test/model/updatelib.php | 66 +++++++++++++---------------- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/module/doc/test/doc.class.php b/module/doc/test/doc.class.php index f323d38010..c44aca198e 100644 --- a/module/doc/test/doc.class.php +++ b/module/doc/test/doc.class.php @@ -5,7 +5,7 @@ class docTest { global $tester, $app; $this->objectModel = $tester->loadModel('doc'); - $this->objectModel->config->global->syncProduct = ''; + $this->objectModel->config->global->syncProduct = ''; $app->rawModule = 'doc'; $app->rawMethod = 'index'; @@ -89,24 +89,22 @@ class docTest } /** - * Function updateLib test by doc + * 编辑一个文档库。 + * Update a lib. * - * @param int $libID - * @param array $param + * @param int $libID + * @param array $param * @access public * @return array */ - public function updateLibTest($libID, $param) + public function updateLibTest($libID, $param): array { - global $tester; - $tester->app->loadConfig('doc'); - - foreach($param as $key => $value) $_POST[$key] = $value; - $objects = $this->objectModel->updateLib($libID); + $libData = new stdclass(); + foreach($param as $key => $value) $libData->{$key} = $value; + $changes = $this->objectModel->updateLib($libID, $libData); if(dao::isError()) return dao::getError(); - - return $objects; + return $changes; } /** diff --git a/module/doc/test/model/updatelib.php b/module/doc/test/model/updatelib.php index f5f61c5cc2..d5862cb004 100755 --- a/module/doc/test/model/updatelib.php +++ b/module/doc/test/model/updatelib.php @@ -1,56 +1,48 @@ #!/usr/bin/env php updateLib(); +timeout=0 cid=1 -pid=1 - -正常修改产品文档库 >> type,product,project -正常修改项目文档库 >> project,27,11 -正常修改执行文档库 >> product,0,1 -正常修改自定义文档库 >> product,17,1 -正常修改无type >> type,custom, -正常修改无产品 >> 『产品库』应当是数字。 -正常修改无项目 >> 『project』应当是数字。』 -正常修改无迭代 >> 『迭代库』应当是数字。 -正常修改无文档库名 >> 『文档库名称』不能为空。 */ -$docLibIds = array('17', '117', '217'); -$type = array('product', 'project', 'execution', 'custom', ''); -$product = array('', '1'); -$project = array('', '11'); -$execution = array('', '101'); -$name = array('', '新建文档库'); -$acl = array('', 'default', 'custom'); -$groups = array('1', '2', '3'); -$users = array('admin', 'dev1', 'dev10'); +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/doc.class.php'; + +zdTable('project')->config('execution')->gen(6); +zdTable('project')->config('project')->gen(2); +zdTable('doclib')->config('doclib')->gen(30); +zdTable('user')->gen(5); +su('admin'); + +$docLibIds = array(26, 18, 20, 6, 11); +$type = array('product', 'project', 'execution', 'custom', 'mine'); +$product = array('', '2'); +$project = array('', '60'); +$execution = array('', '102'); +$name = array('', '编辑文档库'); +$acl = array('', 'default', 'custom', 'private'); +$groups = '1,2,3'; +$users = 'admin,dev1,dev10'; $updateProduct = array('type' => $type[0], 'product' => $product[1], 'name' => $name[1], 'acl' => $acl[1]); $updateProject = array('type' => $type[1], 'project' => $project[1], 'name' => $name[1], 'acl' => $acl[1]); $updateExecution = array('type' => $type[2], 'execution' => $execution[1], 'name' => $name[1], 'acl' => $acl[1]); $updateCustom = array('type' => $type[3], 'name' => $name[1], 'acl' => $acl[1]); +$updateMine = array('type' => $type[4], 'name' => $name[1], 'acl' => $acl[3]); $customLib = array('type' => $type[0], 'product' => $product[1], 'name' => $name[1], 'acl' => $acl[2], 'groups' => $groups, 'users' => $users); -$noType = array('type' => $type[4], 'product' => $product[1], 'name' => $name[1], 'acl' => $acl[1]); $noProduct = array('type' => $type[0], 'product' => $product[0], 'name' => $name[1], 'acl' => $acl[1]); $noProject = array('type' => $type[1], 'project' => $project[0], 'name' => $name[1], 'acl' => $acl[1]); $noExecution = array('type' => $type[2], 'execution' => $execution[0], 'name' => $name[1], 'acl' => $acl[1]); $noName = array('type' => $type[0], 'product' => $product[1], 'name' => $name[0], 'acl' => $acl[0]); -$doc = new docTest(); - -r($doc->updateLibTest($docLibIds[0],$updateProject)) && p('0:field,old,new') && e('type,product,project'); //正常修改产品文档库 -r($doc->updateLibTest($docLibIds[1],$updateProduct)) && p('1:field,old,new') && e('project,27,11'); //正常修改项目文档库 -r($doc->updateLibTest($docLibIds[2],$updateExecution)) && p('2:field,old,new') && e('product,0,1'); //正常修改执行文档库 -r($doc->updateLibTest($docLibIds[0],$updateCustom)) && p('1:field,old,new') && e('product,17,1'); //正常修改自定义文档库 -r($doc->updateLibTest($docLibIds[0],$noType)) && p('0:field,old,new') && e('type,custom,'); //正常修改无type -r($doc->updateLibTest($docLibIds[0],$noProduct)) && p('product:0') && e('『产品库』应当是数字。'); //正常修改无产品 -r($doc->updateLibTest($docLibIds[0],$noProject)) && p('project:0') && e('『project』应当是数字。』');//正常修改无项目 -r($doc->updateLibTest($docLibIds[0],$noExecution)) && p('execution:0') && e('『迭代库』应当是数字。'); //正常修改无迭代 -r($doc->updateLibTest($docLibIds[0],$noName)) && p('name:0') && e('『文档库名称』不能为空。'); //正常修改无文档库名 - +$docTester = new docTest(); +r($docTester->updateLibTest($docLibIds[0], $updateProduct)) && p('0:field,old,new') && e('name,产品文档主库26,编辑文档库'); // 正常修改产品文档库 +r($docTester->updateLibTest($docLibIds[1], $updateProject)) && p('0:field,old,new') && e('name,项目文档主库18,编辑文档库'); // 正常修改项目文档库 +r($docTester->updateLibTest($docLibIds[2], $updateExecution)) && p('0:field,old,new') && e('name,执行文档主库20,编辑文档库'); // 正常修改执行文档库 +r($docTester->updateLibTest($docLibIds[3], $updateCustom)) && p('0:field,old,new') && e('name,自定义文档库6,编辑文档库'); // 正常修改自定义文档库 +r($docTester->updateLibTest($docLibIds[0], $noProduct)) && p('product:0') && e('『产品库』应当是数字。'); // 正常修改无产品 +r($docTester->updateLibTest($docLibIds[0], $noProject)) && p('project:0') && e('『project』应当是数字。'); // 正常修改无项目 +r($docTester->updateLibTest($docLibIds[0], $noExecution)) && p('execution:0') && e('『迭代库』应当是数字。'); // 正常修改无迭代 +r($docTester->updateLibTest($docLibIds[0], $noName)) && p('name:0') && e('『库名称』不能为空。'); // 正常修改无文档库名