* Finish host unit test script.
This commit is contained in:
@@ -92,8 +92,10 @@ class hostModel extends model
|
||||
*/
|
||||
public function update(object $formData): bool
|
||||
{
|
||||
if(empty($formData->id)) return false;
|
||||
|
||||
$oldHost = $this->fetchByID($formData->id);
|
||||
$this->dao->update(TABLE_HOST)->data($formData)->batchCheck($this->config->host->create->requiredFields, 'notempty')->autoCheck()->where('id')->eq($formData->id)->exec();
|
||||
$this->dao->update(TABLE_HOST)->data($formData)->batchCheck($this->config->host->edit->requiredFields, 'notempty')->autoCheck()->where('id')->eq($formData->id)->exec();
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$changes = common::createChanges($oldHost, $formData);
|
||||
@@ -116,6 +118,8 @@ class hostModel extends model
|
||||
*/
|
||||
public function updateStatus(object $formData): bool
|
||||
{
|
||||
if(empty($formData->id) || empty($formData->status) || empty($formData->reason)) return false;
|
||||
|
||||
$this->dao->update(TABLE_HOST)->data($formData, 'reason')->where('id')->eq($formData->id)->exec();
|
||||
if(dao::isError()) return false;
|
||||
|
||||
@@ -136,7 +140,7 @@ class hostModel extends model
|
||||
$this->app->loadLang('serverroom');
|
||||
|
||||
/* Get host list. */
|
||||
$stmt = $this->dao->select('t1.id,t1.name,t2.id as roomID,t2.city,t2.name as roomName,t1.extranet')->from(TABLE_HOST)->alias('t1')
|
||||
$stmt = $this->dao->select('t1.id,t1.id as hostID,t1.name,t2.id as roomID,t2.city,t2.name as roomName,t1.extranet')->from(TABLE_HOST)->alias('t1')
|
||||
->leftJoin(TABLE_SERVERROOM)->alias('t2')->on('t1.serverRoom=t2.id')
|
||||
->where('t1.deleted')->eq(0)
|
||||
->andWhere('t1.type')->eq('normal')
|
||||
@@ -165,7 +169,7 @@ class hostModel extends model
|
||||
$this->app->loadLang('serverroom');
|
||||
|
||||
/* Get host list by group. */
|
||||
$hosts = $this->dao->select('id,name,`group`,extranet')->from(TABLE_HOST)->where('deleted')->eq(0)->andWhere('type')->eq('normal')->fetchGroup('group', 'id');
|
||||
$hosts = $this->dao->select('id,id as hostID,name,`group`,extranet')->from(TABLE_HOST)->where('deleted')->eq(0)->andWhere('type')->eq('normal')->fetchGroup('group', 'id');
|
||||
$modules = $this->getTreeModules(0, $hosts);
|
||||
|
||||
$treemap = array();
|
||||
@@ -227,9 +231,9 @@ class hostModel extends model
|
||||
$children['collapsed'] = false;
|
||||
$children['children'] = $this->processTreemap($data->children);
|
||||
}
|
||||
else
|
||||
elseif(!empty($data->hostID))
|
||||
{
|
||||
$children['hostid'] = $data->id;
|
||||
$children['hostid'] = $data->hostID;
|
||||
}
|
||||
|
||||
$treeMap[] = $children;
|
||||
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->create();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试正确的创建主机时的返回结果。 @1
|
||||
- 测试正确的创建主机时有无报错信息。 @0
|
||||
- 测试创建主机时必填项的校验。
|
||||
- 第name条的0属性 @『名称』不能为空。
|
||||
- 第intranet条的0属性 @『内网IP』不能为空。
|
||||
- 第extranet条的0属性 @『外网IP』不能为空。
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('module')->config('module')->gen(100)->fixPath();
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
zdTable('lang')->gen(0);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
|
||||
$host = new stdclass();
|
||||
$host->type = 'normal';
|
||||
r($tester->host->create($host)) && p() && e('1'); // 测试正确的创建主机时的返回结果。
|
||||
r(dao::getError()) && p() && e('0'); // 测试正确的创建主机时有无报错信息。
|
||||
|
||||
$host->name = '';
|
||||
$host->intranet = '';
|
||||
$host->extranet = '';
|
||||
$tester->host->create($host);
|
||||
r(dao::getError()) && p('name:0;intranet:0;extranet:0') && e('『名称』不能为空。,『内网IP』不能为空。,『外网IP』不能为空。'); // 测试创建主机时必填项的校验。
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->getGroupTreemap();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试获取的分组拓扑图数据是否正确。
|
||||
- 第0条的text属性 @这是一个模块1
|
||||
- 第1条的text属性 @这是一个模块51
|
||||
- 第2条的text属性 @这是一个模块61
|
||||
- 测试获取的分组拓扑图数据是否正确。
|
||||
- 第0条的text属性 @这是一个模块11
|
||||
- 第1条的text属性 @这是一个模块12
|
||||
- 第2条的text属性 @主机1
|
||||
- 测试获取的分组拓扑图数据是否正确。
|
||||
- 第0条的text属性 @这是一个模块31
|
||||
- 第1条的text属性 @主机11
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('account')->gen(100);
|
||||
zdTable('serverroom')->gen(100);
|
||||
zdTable('module')->config('module')->gen(100)->fixPath();
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
zdTable('lang')->gen(0);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
|
||||
r($tester->host->getGroupTreemap()['children']) && p('0:text;1:text;2:text') && e('这是一个模块1,这是一个模块51,这是一个模块61'); // 测试获取的分组拓扑图数据是否正确。
|
||||
r($tester->host->getGroupTreemap()['children'][0]['children']) && p('0:text;1:text;2:text') && e('这是一个模块11,这是一个模块12,主机1'); // 测试获取的分组拓扑图数据是否正确。
|
||||
r($tester->host->getGroupTreemap()['children'][0]['children'][0]['children']) && p('0:text;1:text') && e('这是一个模块31,主机11'); // 测试获取的分组拓扑图数据是否正确。
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->getList();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试默认参数是否为获取全部主机。 @30
|
||||
- 测试获取全部主机的数量。 @30
|
||||
- 测试根据模块获取主机的数量。 @3
|
||||
- 测试根据查询条件获取主机的数量。 @15
|
||||
- 测试查询结果中主机数据是否正确。
|
||||
- 第0条的id属性 @30
|
||||
- 第0条的name属性 @主机30
|
||||
- 第0条的type属性 @normal
|
||||
- 第0条的hostType属性 @virtual
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('account')->gen(100);
|
||||
zdTable('serverroom')->gen(100);
|
||||
zdTable('module')->config('module')->gen(100)->fixPath();
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
zdTable('lang')->gen(0);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
$_SESSION['hostQuery'] = "hostType='physical'";
|
||||
|
||||
r(count($tester->host->getList())) && p() && e(30); // 测试默认参数是否为获取全部主机。
|
||||
r(count($tester->host->getList('all'))) && p() && e(30); // 测试获取全部主机的数量。
|
||||
r(count($tester->host->getList('bymodule', '1'))) && p() && e(3); // 测试根据模块获取主机的数量。
|
||||
r(count($tester->host->getList('bysearch'))) && p() && e(15); // 测试根据查询条件获取主机的数量。
|
||||
|
||||
r($tester->host->getList('all')) && p('0:id,name,type,hostType') && e('30,主机30,normal,virtual'); // 测试查询结果中主机数据是否正确。
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->getServerroomTreemap();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试获取的物理拓扑图数据是否正确。
|
||||
- 第0条的text属性 @北京
|
||||
- 第1条的text属性 @广东
|
||||
- 第2条的text属性 @杭州
|
||||
- 测试获取的物理拓扑图数据是否正确。
|
||||
- 第0条的text属性 @这是机房名称1
|
||||
- 第1条的text属性 @这是机房名称4
|
||||
- 第2条的text属性 @这是机房名称7
|
||||
- 测试获取的物理拓扑图数据是否正确。
|
||||
- 第0条的text属性 @这是机房名称3
|
||||
- 第1条的text属性 @这是机房名称6
|
||||
- 第2条的text属性 @这是机房名称9
|
||||
- 测试获取的物理拓扑图数据是否正确。
|
||||
- 第0条的text属性 @主机1
|
||||
- 第0条的hostid属性 @1
|
||||
- 测试获取的物理拓扑图数据是否正确。
|
||||
- 第0条的text属性 @主机4
|
||||
- 第0条的hostid属性 @4
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('account')->gen(100);
|
||||
zdTable('serverroom')->gen(100);
|
||||
zdTable('module')->config('module')->gen(100)->fixPath();
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
zdTable('lang')->gen(0);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
|
||||
r($tester->host->getServerroomTreemap()) && p('0:text;1:text;2:text') && e('北京,广东,杭州'); // 测试获取的物理拓扑图数据是否正确。
|
||||
r($tester->host->getServerroomTreemap()[0]['children']) && p('0:text;1:text;2:text') && e('这是机房名称1,这是机房名称4,这是机房名称7'); // 测试获取的物理拓扑图数据是否正确。
|
||||
r($tester->host->getServerroomTreemap()[1]['children']) && p('0:text;1:text;2:text') && e('这是机房名称3,这是机房名称6,这是机房名称9'); // 测试获取的物理拓扑图数据是否正确。
|
||||
r($tester->host->getServerroomTreemap()[0]['children'][0]['children']) && p('0:text,hostid') && e('主机1,1'); // 测试获取的物理拓扑图数据是否正确。
|
||||
r($tester->host->getServerroomTreemap()[0]['children'][1]['children']) && p('0:text,hostid') && e('主机4,4'); // 测试获取的物理拓扑图数据是否正确。
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->isClickable();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试ID为1的主机操作按钮权限。 @0
|
||||
- 测试ID为1的主机操作按钮权限。 @1
|
||||
- 测试ID为1的主机操作按钮权限。 @1
|
||||
- 测试ID为1的主机操作按钮权限。 @1
|
||||
- 测试ID为1的主机操作按钮权限。 @1
|
||||
- 测试ID为2的主机操作按钮权限。 @1
|
||||
- 测试ID为2的主机操作按钮权限。 @0
|
||||
- 测试ID为2的主机操作按钮权限。 @1
|
||||
- 测试ID为2的主机操作按钮权限。 @1
|
||||
- 测试ID为2的主机操作按钮权限。 @1
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
|
||||
$host = $tester->host->fetchByID(1);
|
||||
r($tester->host->isClickable($host, 'online')) && p() && e(0); // 测试ID为1的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'offline')) && p() && e(1); // 测试ID为1的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'delete')) && p() && e(1); // 测试ID为1的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'edit')) && p() && e(1); // 测试ID为1的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'create')) && p() && e(1); // 测试ID为1的主机操作按钮权限。
|
||||
|
||||
$host = $tester->host->fetchByID(2);
|
||||
r($tester->host->isClickable($host, 'online')) && p() && e(1); // 测试ID为2的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'offline')) && p() && e(0); // 测试ID为2的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'delete')) && p() && e(1); // 测试ID为2的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'edit')) && p() && e(1); // 测试ID为2的主机操作按钮权限。
|
||||
r($tester->host->isClickable($host, 'create')) && p() && e(1); // 测试ID为2的主机操作按钮权限。
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->update();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试对象没有ID时候能否成功更新主机 @0
|
||||
- 测试对象有ID时能否成功更新主机 @1
|
||||
- 测试更新主机时必填项的校验。
|
||||
- 第name条的0属性 @『名称』不能为空。
|
||||
- 第intranet条的0属性 @『内网IP』不能为空。
|
||||
- 第extranet条的0属性 @『外网IP』不能为空。
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('module')->config('module')->gen(100)->fixPath();
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
zdTable('lang')->gen(0);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
|
||||
$host = new stdclass();
|
||||
$host->name = '主机222';
|
||||
r($tester->host->update($host)) && p() && e('0'); // 测试对象没有ID时候能否成功更新主机
|
||||
|
||||
$host->id = '22';
|
||||
r($tester->host->update($host)) && p() && e('1'); // 测试对象有ID时能否成功更新主机
|
||||
|
||||
$host->name = '';
|
||||
$host->intranet = '';
|
||||
$host->extranet = '';
|
||||
$tester->host->update($host);
|
||||
r(dao::getError()) && p('name:0;intranet:0;extranet:0') && e('『名称』不能为空。,『内网IP』不能为空。,『外网IP』不能为空。'); // 测试更新主机时必填项的校验。
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 hostModel->updatestatus();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试对象没有ID时候能否成功上架主机 @0
|
||||
- 测试对象有ID时能否成功上架主机 @1
|
||||
- 执行host模块的fetchByID方法,参数是'22'
|
||||
- 属性id @22
|
||||
- 属性status @online
|
||||
- 测试对象有ID时能否成功上架主机 @1
|
||||
- 执行host模块的fetchByID方法,参数是'22'
|
||||
- 属性id @22
|
||||
- 属性status @offline
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zdTable('module')->config('module')->gen(100)->fixPath();
|
||||
zdTable('host')->config('host')->gen(30);
|
||||
zdTable('lang')->gen(0);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('host');
|
||||
|
||||
$host = new stdclass();
|
||||
$host->status = 'online';
|
||||
r($tester->host->updatestatus($host)) && p() && e('0'); // 测试对象没有ID时候能否成功上架主机
|
||||
|
||||
$host->id = '22';
|
||||
$host->reason = '上架原因';
|
||||
r($tester->host->updatestatus($host)) && p() && e('1'); // 测试对象有ID时能否成功上架主机
|
||||
r($tester->host->fetchByID('22')) && p('id,status') && e('22,online');
|
||||
|
||||
$host->status = 'offline';
|
||||
$host->reason = '下架原因';
|
||||
r($tester->host->updatestatus($host)) && p() && e('1'); // 测试对象有ID时能否成功上架主机
|
||||
r($tester->host->fetchByID('22')) && p('id,status') && e('22,offline');
|
||||
@@ -0,0 +1,44 @@
|
||||
title: zt_host
|
||||
author: Wang yuting
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
range: 1-1000
|
||||
- field: name
|
||||
fields:
|
||||
- field: name1
|
||||
range: 主机
|
||||
- field: name2
|
||||
range: 1-1000
|
||||
- field: admin
|
||||
range: 1-1000
|
||||
- field: group
|
||||
range: 1-1000
|
||||
- field: serverRoom
|
||||
range: 1-1000
|
||||
- field: type
|
||||
range: normal
|
||||
- field: hostType
|
||||
range: physical,virtual
|
||||
- field: cpuBrand
|
||||
range: intel,amd
|
||||
- field: cpuModel
|
||||
range: 1-100
|
||||
- field: cpuNumber
|
||||
range: 1-100
|
||||
- field: cpuCores
|
||||
range: 1-100
|
||||
- field: memory
|
||||
range: 1-100
|
||||
- field: diskSize
|
||||
range: 1-100
|
||||
- field: status
|
||||
range: online,offline
|
||||
- field: intranet
|
||||
range: 127.0.0.1
|
||||
- field: extranet
|
||||
range: 127.0.0.1
|
||||
- field: osName
|
||||
range: linux,windows,solaris,netware,esx,other
|
||||
- field: hardwareType
|
||||
range: server
|
||||
@@ -0,0 +1,24 @@
|
||||
title: table zt_module
|
||||
desc: "模块"
|
||||
author: Wang yuting
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
note: "ID"
|
||||
range: 1-10000
|
||||
- field: root
|
||||
note: "根目录"
|
||||
range: 0
|
||||
- field: branch
|
||||
note: "分支"
|
||||
range: 0
|
||||
- field: name
|
||||
note: "模块名称"
|
||||
range: 1-10000
|
||||
prefix: "这是一个模块"
|
||||
- field: parent
|
||||
note: "父ID"
|
||||
range: 0{10},1-10{2},11-30,0{10000}
|
||||
- field: type
|
||||
note: "对象类型"
|
||||
range: host
|
||||
Reference in New Issue
Block a user