From bb0fc070ab0d364da8f54a6fd383aad04e50fe1c Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 12 Jun 2023 15:21:16 +0800 Subject: [PATCH] * Refactor testsuite::create. --- module/testsuite/config/form.php | 12 +++++ module/testsuite/control.php | 23 ++++++--- module/testsuite/model.php | 17 ++----- module/testsuite/test/model/create.php | 39 +++++---------- module/testsuite/test/testsuite.class.php | 16 +++--- module/testsuite/ui/create.html.php | 59 +++++++++++++++++++++++ 6 files changed, 111 insertions(+), 55 deletions(-) create mode 100644 module/testsuite/config/form.php create mode 100644 module/testsuite/ui/create.html.php diff --git a/module/testsuite/config/form.php b/module/testsuite/config/form.php new file mode 100644 index 0000000000..3e906d631f --- /dev/null +++ b/module/testsuite/config/form.php @@ -0,0 +1,12 @@ +testsuite->form = new stdclass(); + +$config->testsuite->form->create = array(); +$config->testsuite->form->create['name'] = array('required' => true, 'type' => 'string', 'filter' => 'trim'); +$config->testsuite->form->create['desc'] = array('required' => false, 'type' => 'string', 'default' => '', 'control' => 'editor'); +$config->testsuite->form->create['type'] = array('required' => false, 'type' => 'string', 'default' => 'private'); +$config->testsuite->form->create['addedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); +$config->testsuite->form->create['addedDate'] = array('required' => false, 'type' => 'datetime', 'default' => helper::now()); diff --git a/module/testsuite/control.php b/module/testsuite/control.php index 7edb7e1ccc..fe2aaa54b8 100644 --- a/module/testsuite/control.php +++ b/module/testsuite/control.php @@ -109,27 +109,35 @@ class testsuite extends control } /** + * 创建一个测试套件。 * Create a test suite. * * @param int $productID * @access public * @return void */ - public function create($productID) + public function create(int $productID) { if(!empty($_POST)) { - $response['result'] = 'success'; - $response['message'] = $this->lang->testsuite->successSaved; - $suiteID = $this->testsuite->create($productID); + $suite = form::data($this->config->testsuite->form->create) + ->setIF($this->lang->navGroup->testsuite != 'qa', 'project', $this->session->project) + ->add('product', (int)$productID) + ->get(); + $suite = $this->loadModel('file')->processImgURL($suite, $this->config->testsuite->editor->create['id'], $this->post->uid); + + $suiteID = $this->testsuite->create($suite); if(dao::isError()) { $response['result'] = 'fail'; $response['message'] = dao::getError(); return $this->send($response); } - $actionID = $this->loadModel('action')->create('testsuite', $suiteID, 'opened'); + $response['result'] = 'success'; + $response['message'] = $this->lang->testsuite->successSaved; + + $this->file->updateObjectID($this->post->uid, $suiteID, 'testsuite'); $message = $this->executeHooks($suiteID); if($message) $response['message'] = $message; @@ -143,9 +151,8 @@ class testsuite extends control $productID = $this->product->saveVisitState($productID, $this->products); $this->loadModel('qa')->setMenu($this->products, $productID); - $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testsuite->create; - - $this->view->productID = $productID; + $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testsuite->create; + $this->view->productID = $productID; $this->display(); } diff --git a/module/testsuite/model.php b/module/testsuite/model.php index 344a2323f7..9823104815 100644 --- a/module/testsuite/model.php +++ b/module/testsuite/model.php @@ -51,24 +51,15 @@ class testsuiteModel extends model } /** + * 创建一个测试套件。 * Create a test suite. * - * @param int $productID + * @param object $suite * @access public * @return bool|int */ - public function create($productID) + public function create(object $suite): int|false { - $suite = fixer::input('post') - ->trim('name') - ->stripTags($this->config->testsuite->editor->create['id'], $this->config->allowedTags) - ->setIF($this->lang->navGroup->testsuite != 'qa', 'project', $this->session->project) - ->add('product', (int)$productID) - ->add('addedBy', $this->app->user->account) - ->add('addedDate', helper::now()) - ->remove('uid') - ->get(); - $suite = $this->loadModel('file')->processImgURL($suite, $this->config->testsuite->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TESTSUITE)->data($suite) ->batchcheck($this->config->testsuite->create->requiredFields, 'notempty') ->checkFlow() @@ -76,7 +67,7 @@ class testsuiteModel extends model if(!dao::isError()) { $suiteID = $this->dao->lastInsertID(); - $this->file->updateObjectID($this->post->uid, $suiteID, 'testsuite'); + $actionID = $this->loadModel('action')->create('testsuite', $suiteID, 'opened'); return $suiteID; } return false; diff --git a/module/testsuite/test/model/create.php b/module/testsuite/test/model/create.php index 72f0fe53b6..213f467f55 100755 --- a/module/testsuite/test/model/create.php +++ b/module/testsuite/test/model/create.php @@ -2,7 +2,7 @@ gen(1); /** @@ -10,19 +10,6 @@ title=测试 testsuiteModel->create(); cid=1 pid=1 -测试productID为1,name正常存在,type为private >> 202 -测试productID为1,name为空,type为private >> 『名称』不能为空。 -测试productID为1,name正常存在,type为public >> 203 -测试productID为1,name为空,type为public >> 『名称』不能为空。 -测试productID为1,name正常存在,type为空 >> 204 -测试productID为1,name为空,type为空 >> 『名称』不能为空。 -测试productID为0,name正常存在,type为private >> 205 -测试productID为0,name为空,type为private >> 『名称』不能为空。 -测试productID为0,name正常存在,type为public >> 206 -测试productID为0,name为空,type为public >> 『名称』不能为空。 -测试productID为0,name正常存在,type为空 >> 207 -测试productID为0,name为空,type为空 >> 『名称』不能为空。 - */ $productID = array(1, 0); $name = array('这是测试套件名称1000', ''); @@ -30,15 +17,15 @@ $type = array('private', 'public', ''); $testsuite = new testsuiteTest(); -r($testsuite->createTest($productID[0], $name[0], $type[0])) && p() && e('202'); //测试productID为1,name正常存在,type为private -r($testsuite->createTest($productID[0], $name[1], $type[0])) && p('name:0') && e('『名称』不能为空。'); //测试productID为1,name为空,type为private -r($testsuite->createTest($productID[0], $name[0], $type[1])) && p() && e('203'); //测试productID为1,name正常存在,type为public -r($testsuite->createTest($productID[0], $name[1], $type[1])) && p('name:0') && e('『名称』不能为空。'); //测试productID为1,name为空,type为public -r($testsuite->createTest($productID[0], $name[0], $type[2])) && p() && e('204'); //测试productID为1,name正常存在,type为空 -r($testsuite->createTest($productID[0], $name[1], $type[2])) && p('name:0') && e('『名称』不能为空。'); //测试productID为1,name为空,type为空 -r($testsuite->createTest($productID[1], $name[0], $type[0])) && p() && e('205'); //测试productID为0,name正常存在,type为private -r($testsuite->createTest($productID[1], $name[1], $type[0])) && p('name:0') && e('『名称』不能为空。'); //测试productID为0,name为空,type为private -r($testsuite->createTest($productID[1], $name[0], $type[1])) && p() && e('206'); //测试productID为0,name正常存在,type为public -r($testsuite->createTest($productID[1], $name[1], $type[1])) && p('name:0') && e('『名称』不能为空。'); //测试productID为0,name为空,type为public -r($testsuite->createTest($productID[1], $name[0], $type[2])) && p() && e('207'); //测试productID为0,name正常存在,type为空 -r($testsuite->createTest($productID[1], $name[1], $type[2])) && p('name:0') && e('『名称』不能为空。'); //测试productID为0,name为空,type为空 +r($testsuite->createTest($productID[0], $name[0], $type[0])) && p() && e('1'); //测试productID为1,name正常存在,type为private +r($testsuite->createTest($productID[0], $name[1], $type[0])) && p('name:0') && e('『套件名称』不能为空。'); //测试productID为1,name为空,type为private +r($testsuite->createTest($productID[0], $name[0], $type[1])) && p() && e('2'); //测试productID为1,name正常存在,type为public +r($testsuite->createTest($productID[0], $name[1], $type[1])) && p('name:0') && e('『套件名称』不能为空。'); //测试productID为1,name为空,type为public +r($testsuite->createTest($productID[0], $name[0], $type[2])) && p() && e('3'); //测试productID为1,name正常存在,type为空 +r($testsuite->createTest($productID[0], $name[1], $type[2])) && p('name:0') && e('『套件名称』不能为空。'); //测试productID为1,name为空,type为空 +r($testsuite->createTest($productID[1], $name[0], $type[0])) && p() && e('4'); //测试productID为0,name正常存在,type为private +r($testsuite->createTest($productID[1], $name[1], $type[0])) && p('name:0') && e('『套件名称』不能为空。'); //测试productID为0,name为空,type为private +r($testsuite->createTest($productID[1], $name[0], $type[1])) && p() && e('5'); //测试productID为0,name正常存在,type为public +r($testsuite->createTest($productID[1], $name[1], $type[1])) && p('name:0') && e('『套件名称』不能为空。'); //测试productID为0,name为空,type为public +r($testsuite->createTest($productID[1], $name[0], $type[2])) && p() && e('6'); //测试productID为0,name正常存在,type为空 +r($testsuite->createTest($productID[1], $name[1], $type[2])) && p('name:0') && e('『套件名称』不能为空。'); //测试productID为0,name为空,type为空 diff --git a/module/testsuite/test/testsuite.class.php b/module/testsuite/test/testsuite.class.php index c7b30a2e8c..a44fa514de 100644 --- a/module/testsuite/test/testsuite.class.php +++ b/module/testsuite/test/testsuite.class.php @@ -17,6 +17,7 @@ class testsuiteTest } /** + * 测试创建一个测试套件。 * Test create a test suite. * * @param int $productID @@ -25,19 +26,18 @@ class testsuiteTest * @access public * @return array|int */ - public function createTest($productID, $name, $type) + public function createTest(int $productID, string $name, string $type): array|int { - $_POST['name'] = $name; - $_POST['desc'] = ''; - $_POST['type'] = $type; - $_POST['uid'] = '62538b850bb9d'; + $suite = new stdclass(); + $suite->name = $name; + $suite->desc = ''; + $suite->type = $type; - $objects = $this->objectModel->create($productID); - unset($_POST); + $suiteID = $this->objectModel->create($suite); if(dao::isError()) return dao::getError(); - return $objects; + return $suiteID; } /** diff --git a/module/testsuite/ui/create.html.php b/module/testsuite/ui/create.html.php new file mode 100644 index 0000000000..a0be8f0bb3 --- /dev/null +++ b/module/testsuite/ui/create.html.php @@ -0,0 +1,59 @@ + + * @package testsuite + * @link https://www.zentao.net + */ +namespace zin; + + +formPanel +( + set::id('testsuiteCreateForm'), + set::title($lang->testsuite->create), + formRow + ( + formGroup + ( + set::width('1/2'), + set::name('name'), + set::label($lang->testsuite->name), + set::value(''), + ) + ), + formRow + ( + formGroup + ( + set::label($lang->testsuite->desc), + editor + ( + set::name('desc'), + set::rows('5'), + ), + ) + ), + formRow + ( + formGroup + ( + set::width('1/2'), + set::label($lang->testsuite->author), + radioList + ( + set::name('type'), + set::value('private'), + set::items($lang->testsuite->authorList), + set::inline(true), + ) + ) + ), +); + + +render(); +