* Refactor testsuite::create.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
global $app;
|
||||
|
||||
$config->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());
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/testsuite.class.php';
|
||||
su('admin');
|
||||
zdTable('testsuite')->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为空
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The create view file of testsuite module of ZenTaoPMS.
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Mengyi Liu <liumengyi@easycorp.ltd>
|
||||
* @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();
|
||||
|
||||
Reference in New Issue
Block a user