From 094cea1dc2dc30e4b91b61e056fc020fb43bfd88 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 26 Dec 2023 14:48:07 +0800 Subject: [PATCH] * Refactor zanodeModel::setAutomationSetting, and add its unit test. --- module/testcase/config/form.php | 6 ++ module/testcase/control.php | 7 +- module/zanode/model.php | 19 ++-- .../test/model/setautomationsetting.php | 90 +++++++++++++++++++ module/zanode/test/zanode.class.php | 17 ++++ 5 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 module/zanode/test/model/setautomationsetting.php diff --git a/module/testcase/config/form.php b/module/testcase/config/form.php index 2793d05353..72498d1d38 100644 --- a/module/testcase/config/form.php +++ b/module/testcase/config/form.php @@ -122,3 +122,9 @@ $config->testcase->form->showImport['stage'] = array('required' => false, $config->testcase->form->showImport['desc'] = array('required' => false, 'type' => 'array', 'default' => array()); $config->testcase->form->showImport['expect'] = array('required' => false, 'type' => 'array', 'default' => array()); $config->testcase->form->showImport['stepType'] = array('required' => false, 'type' => 'array', 'default' => array()); + +$config->testcase->form->automation = common::formConfig('testcase', 'automation'); +$config->testcase->form->automation['product'] = array('required' => false, 'type' => 'int', 'default' => 0); +$config->testcase->form->automation['node'] = array('required' => false, 'type' => 'int', 'default' => 0); +$config->testcase->form->automation['scriptPath'] = array('required' => true, 'type' => 'string', 'default' => ''); +$config->testcase->form->automation['shell'] = array('required' => true, 'type' => 'string', 'default' => '', 'control' => 'editor'); diff --git a/module/testcase/control.php b/module/testcase/control.php index 1502313f36..d98de89080 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1301,7 +1301,12 @@ class testcase extends control if($_POST) { - $this->zanode->setAutomationSetting(); + $automation = form::data($this->config->testcase->form->automation) + ->setIF($this->post->id, 'id', $this->post->id) + ->setDefault('createdBy', $this->app->user->account) + ->setdefault('createddate', helper::now()) + ->get(); + $this->zanode->setAutomationSetting($automation); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); diff --git a/module/zanode/model.php b/module/zanode/model.php index 3b77d2bb21..df8c17d9e1 100644 --- a/module/zanode/model.php +++ b/module/zanode/model.php @@ -921,25 +921,18 @@ class zanodemodel extends model } /** + * 自动化设置。 * Set automation setting. * + * @param object $object * @access public - * @return int|bool + * @return int|false */ - public function setAutomationSetting() + public function setAutomationSetting(object $object): int|bool { - $now = helper::now(); - $data = fixer::input('post') - ->remove('syncToZentao') - ->setDefault('createdBy', $this->app->user->account) - ->setDefault('createdDate', $now) - ->setDefault('node', 0) - ->remove('uid') - ->get(); - $this->dao->replace(TABLE_AUTOMATION) - ->data($data) - ->batchcheck('node,scriptPath', 'notempty') + ->data($object) + ->batchCheck('node,scriptPath', 'notempty') ->autoCheck() ->exec(); diff --git a/module/zanode/test/model/setautomationsetting.php b/module/zanode/test/model/setautomationsetting.php new file mode 100644 index 0000000000..514f95d878 --- /dev/null +++ b/module/zanode/test/model/setautomationsetting.php @@ -0,0 +1,90 @@ +#!/usr/bin/env php +isClickable(). +cid=1 + +- 测试自动化设置 node1 新增 + - 属性id @2 + - 属性product @1 + - 属性node @1 + - 属性scriptPath @scriptPath + - 属性shell @shell +- 测试自动化设置 node2 更新 id 1 + - 属性id @1 + - 属性product @1 + - 属性node @1 + - 属性scriptPath @scriptPath + - 属性shell @shell +- 测试自动化设置 node3 新增 + - 属性id @3 + - 属性product @1 + - 属性node @1 + - 属性scriptPath @scriptPath + - 属性shell @shell +- 测试自动化设置 emptyNode 新增第node条的0属性 @『执行节点』不能为空。 +- 测试自动化设置 emptyScriptPath 新增第scriptPath条的0属性 @『脚本目录』不能为空。 +- 测试自动化设置 allEmpty 新增 + - 第node条的0属性 @『执行节点』不能为空。 + - 第scriptPath条的0属性 @『脚本目录』不能为空。 + + */ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/zanode.class.php'; + +zdTable('user')->gen(10); +zdTable('automation')->gen(1); + +su('admin'); + +$zanode = new zanodeTest(); + +$node1 = new stdclass(); +$node1->product = 1; +$node1->node = 1; +$node1->scriptPath = 'scriptPath'; +$node1->shell = 'shell'; + +$node2 = new stdclass(); +$node2->id = 1; +$node2->product = 1; +$node2->node = 1; +$node2->scriptPath = 'scriptPath'; +$node2->shell = 'shell'; + +$node3 = new stdclass(); +$node3->id = 3; +$node3->product = 1; +$node3->node = 1; +$node3->scriptPath = 'scriptPath'; +$node3->shell = 'shell'; + +$emptyNode = new stdclass(); +$emptyNode->product = 1; +$emptyNode->node = 0; +$emptyNode->scriptPath = 'scriptPath'; +$emptyNode->shell = 'shell'; + +$emptyScriptPath = new stdclass(); +$emptyScriptPath->product = 1; +$emptyScriptPath->node = 1; +$emptyScriptPath->scriptPath = ''; +$emptyScriptPath->shell = 'shell'; + +$allEmpty = new stdclass(); +$allEmpty->product = 0; +$allEmpty->id = 0; +$allEmpty->node = 0; +$allEmpty->scriptPath = ''; +$allEmpty->shell = ''; + +r($zanode->setAutomationSettingTest($node1)) && p('id,product,node,scriptPath,shell') && e('2,1,1,scriptPath,shell'); // 测试自动化设置 node1 新增 +r($zanode->setAutomationSettingTest($node2)) && p('id,product,node,scriptPath,shell') && e('1,1,1,scriptPath,shell'); // 测试自动化设置 node2 更新 id 1 +r($zanode->setAutomationSettingTest($node3)) && p('id,product,node,scriptPath,shell') && e('3,1,1,scriptPath,shell'); // 测试自动化设置 node3 新增 +r($zanode->setAutomationSettingTest($emptyNode)) && p('node:0') && e('『执行节点』不能为空。'); // 测试自动化设置 emptyNode 新增 +r($zanode->setAutomationSettingTest($emptyScriptPath)) && p('scriptPath:0') && e('『脚本目录』不能为空。'); // 测试自动化设置 emptyScriptPath 新增 +r($zanode->setAutomationSettingTest($allEmpty)) && p('node:0;scriptPath:0') && e('『执行节点』不能为空。;『脚本目录』不能为空。'); // 测试自动化设置 allEmpty 新增 diff --git a/module/zanode/test/zanode.class.php b/module/zanode/test/zanode.class.php index dc968ffbd6..9760670dee 100644 --- a/module/zanode/test/zanode.class.php +++ b/module/zanode/test/zanode.class.php @@ -24,6 +24,23 @@ class zanodeTest return $this->objectModel->$name(...$arguments); } + /** + * 测试自动化设置。 + * Test set automation setting. + * + * @param object $object + * @access public + * @return object|array + */ + public function setAutomationSettingTest(object $object): object|array + { + $resultID = $this->setAutomationSetting($object); + if(dao::isError()) return dao::getError(); + $return = $this->objectModel->getScriptByID($resultID); + return $return; + return $this->objectModel->getScriptByID($resultID); + } + /** * 测试判断按钮是否可点击。 * Test judge an action is clickable or not.