* Add tsetcase for holiday.
This commit is contained in:
@@ -74,6 +74,8 @@ class holidayModel extends model
|
||||
->batchCheck($this->config->holiday->require->create, 'notempty')
|
||||
->check('end', 'ge', $holiday->begin)
|
||||
->exec();
|
||||
$lastInsertID = $this->dao->lastInsertID();
|
||||
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$beginDate = $this->post->begin;
|
||||
@@ -87,7 +89,7 @@ class holidayModel extends model
|
||||
$this->updateTaskPlanDuration($beginDate, $endDate);
|
||||
$this->updateTaskRealDuration($beginDate, $endDate);
|
||||
|
||||
return $this->dao->lastInsertID();
|
||||
return $lastInsertID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
class holidayTest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $tester;
|
||||
$this->objectModel = $tester->loadModel('holiday');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getById method.
|
||||
*
|
||||
* @param string $id
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByIdTest($id)
|
||||
{
|
||||
$objects = $this->objectModel->getById($id);
|
||||
|
||||
if($objects === false) return 'Object not found';
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getList method.
|
||||
*
|
||||
* @param string $year
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getListTest($year = '', $type = 'all')
|
||||
{
|
||||
$objects = $this->objectModel->getList($year = '', $type = 'all');
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getYearPairs method.
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getYearPairsTest()
|
||||
{
|
||||
$objects = $this->objectModel->getYearPairs();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create method.
|
||||
*
|
||||
* @param array $param
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function createTest($param = array())
|
||||
{
|
||||
$defaultParam['type'] = 'holiday';
|
||||
$defaultParam['begin'] = '2022-01-01';
|
||||
$defaultParam['end'] = '2022-02-01';
|
||||
$defaultParam['name'] = '测试创建holiday';
|
||||
$defaultParam['desc'] = '默认的holiday';
|
||||
|
||||
foreach($defaultParam as $field => $defaultValue) $_POST[$field] = $defaultValue;
|
||||
|
||||
foreach($param as $key => $value) $_POST[$key] = $value;
|
||||
$lastInsertID = $this->objectModel->create();
|
||||
unset($_POST);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = $this->objectModel->getByID($lastInsertID);
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update method.
|
||||
*
|
||||
* @param int $holidayID
|
||||
* @param array $param
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function updateTest($holidayID, $param = array())
|
||||
{
|
||||
global $tester;
|
||||
$object = $tester->dbh->query("SELECT * FROM " . TABLE_HOLIDAY ." WHERE id = $holidayID")->fetch();
|
||||
|
||||
foreach($object as $field => $value)
|
||||
{
|
||||
if(in_array($field, array_keys($param)))
|
||||
{
|
||||
$_POST[$field] = $param[$field];
|
||||
}
|
||||
else
|
||||
{
|
||||
$_POST[$field] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$noError = $this->objectModel->update($bugID);
|
||||
unset($_POST);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'true';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getHolidays method.
|
||||
*
|
||||
* @param string $begin
|
||||
* @param string $end
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getHolidaysTest($begin, $end)
|
||||
{
|
||||
$objects = $this->objectModel->getHolidays($begin, $end);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function getWorkingDaysTest($begin, $end)
|
||||
{
|
||||
$objects = $this->objectModel->getWorkingDays($begin, $end);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
public function getActualWorkingDaysTest($begin, $end)
|
||||
{
|
||||
$objects = $this->objectModel->getActualWorkingDays($begin, $end);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getDaysBetweenTest method.
|
||||
*
|
||||
* @param string $begin
|
||||
* @param string $end
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getDaysBetweenTest($begin, $end)
|
||||
{
|
||||
$objects = $this->objectModel->getDaysBetween($begin, $end);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isHoliday method.
|
||||
*
|
||||
* @param string $date
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function isHolidayTest($date)
|
||||
{
|
||||
$objects = $this->objectModel->isHoliday($date);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects === true ? "It is a holiday" : "It is not a holiday";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isWorkingDay method.
|
||||
*
|
||||
* @param string $date
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function isWorkingDayTest($date)
|
||||
{
|
||||
$objects = $this->objectModel->isWorkingDay($date);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateProgramPlanDuration method.
|
||||
*
|
||||
* @param string $beginDate
|
||||
* @param string $endDate
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function updateProgramPlanDurationTest($beginDate, $endDate)
|
||||
{
|
||||
$objects = $this->objectModel->updateProgramPlanDuration($beginDate, $endDate);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateProjectRealDuration method.
|
||||
*
|
||||
* @param string $beginDate
|
||||
* @param string $endDate
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function updateProjectRealDurationTest($beginDate, $endDate)
|
||||
{
|
||||
$objects = $this->objectModel->updateProjectRealDuration($beginDate, $endDate);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateTaskPlanDuration method.
|
||||
*
|
||||
* @param string $beginDate
|
||||
* @param string $endDate
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function updateTaskPlanDurationTest($beginDate, $endDate)
|
||||
{
|
||||
$objects = $this->objectModel->updateTaskPlanDuration($beginDate, $endDate);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateTaskRealDuration method.
|
||||
*
|
||||
* @param string $beginDate
|
||||
* @param string $endDate
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function updateTaskRealDurationTest($beginDate, $endDate)
|
||||
{
|
||||
$objects = $this->objectModel->updateTaskRealDuration($beginDate, $endDate);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->create();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
$createHoliday = array('name' => '测试创建holiday', 'type' => 'holiday');
|
||||
$createWorking = array('name' => '测试创建working', 'type' => 'working');
|
||||
$createNoBegin = array('name' => '不传入开始日期', 'type' => 'holiday', 'begin' => '');
|
||||
$createNoEnd = array('name' => '不传入结束日期', 'type' => 'holiday', 'end' => '' );
|
||||
$createNoName = array('name' => '', 'type' => 'holiday');
|
||||
$createErrorDate = array('begin' => '2022-01-10', 'end' => '2022-01-01');
|
||||
|
||||
r($holiday->createTest($createHoliday)) && p('id,name,type') && e('101,测试创建holiday,holiday'); //测试创建holiday
|
||||
r($holiday->createTest($createWorking)) && p('id,name,type') && e('102,测试创建working,working'); //测试创建working
|
||||
r($holiday->createTest($createNoBegin)) && p('begin:0') && e('『开始日期』不能为空。'); //测试不传入必填项开始日期
|
||||
r($holiday->createTest($createNoEnd)) && p('end:0') && e('『结束日期』不能为空。'); //测试不传入必填项结束日期
|
||||
r($holiday->createTest($createNoName)) && p('name:0') && e('『名称』不能为空。'); //测试不传入必填项名称
|
||||
r($holiday->createTest($createErrorDate)) && p('end:0') && e('『结束日期』应当不小于『2022-01-10』。'); //测试传入小于开始日期的结束日期
|
||||
|
||||
system("./ztest init");
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->getActualWorkingDays();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
r($holiday->getActualWorkingDaysTest('2022-04-01', '2022-04-10')) && p() && e('8'); //查询2022-04-01到2022-04-10的实际工作日
|
||||
r($holiday->getActualWorkingDaysTest('2022-04-06', '2022-04-12')) && p() && e('7'); //查询2022-04-06到2022-04-12的实际工作日
|
||||
r($holiday->getActualWorkingDaysTest('2022-05-10', '2022-05-20')) && p() && e('9'); //查询2022-05-10到2022-05-10的实际工作日
|
||||
r($holiday->getActualWorkingDaysTest('2022-04-06', '2022-04-06')) && p() && e('1'); //查询2022-05-10到2022-05-10的实际工作日
|
||||
r($holiday->getActualWorkingDaysTest('2022-05-13', '2022-05-13')) && p() && e('1'); //查询2022-05-13到2022-05-13的实际工作日
|
||||
r($holiday->getActualWorkingDaysTest('2022-05-14', '2022-05-14')) && p() && e('0'); //查询2022-05-14到2022-05-14的实际工作日
|
||||
r($holiday->getActualWorkingDaysTest('0000-00-00', '0000-00-00')) && p() && e('0'); //测试传入0000-00-00的情况
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->getById();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$holidayIDList = array('1', '5', '10', '1001');
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
r($holiday->getByIdTest($holidayIDList[0])) && p('name,type,desc') && e('这是一个节假日1,holiday,这个是节假日的描述1'); //查询id为1的holiday
|
||||
r($holiday->getByIdTest($holidayIDList[1])) && p('name,type,desc') && e('这是一个节假日5,holiday,这个是节假日的描述5'); //查询id为5的holiday
|
||||
r($holiday->getByIdTest($holidayIDList[2])) && p('name,type,desc') && e('这是一个节假日10,working,这个是节假日的描述10'); //查询id为10的holiday
|
||||
r($holiday->getByIdTest($holidayIDList[3])) && p() && e('Object not found'); //查询不存在的holiday
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->getDaysBetween();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
r($holiday->getDaysBetweenTest('2022-04-01', '2022-04-21')) && p() && e('21'); //返回2022-04-01到2022-04-21之间的天数
|
||||
r($holiday->getDaysBetweenTest('2022-05-23', '2022-05-30')) && p() && e('8'); //返回2022-05-23到2022-05-30之间的天数
|
||||
r($holiday->getDaysBetweenTest('2021-01-01', '2022-01-01')) && p() && e('366'); //测试传入一间隔一整年的两天
|
||||
r($holiday->getDaysBetweenTest('2022-05-07', '2022-05-08')) && p() && e('2'); //返回2022-05-07到2022-05-08之间的天数
|
||||
r($holiday->getDaysBetweenTest('2022-05-07', '2022-05-07')) && p() && e('1'); //测试传入同一天的情况
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->getYearPairs();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
r($holiday->getYearPairsTest()) && p() && e('1'); //测试getYearPairsTest方法
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->isHoliday();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$holidays = array('2022-04-10', '2022-04-16');
|
||||
$workingDays = array('2022-05-07', '2022-05-13');
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
r($holiday->isHolidayTest($holidays[0])) && p() && e('It is a holiday'); // 测试节假日2022年4月10日
|
||||
r($holiday->isHolidayTest($holidays[1])) && p() && e('It is a holiday'); // 测试节假日2022年4月16日
|
||||
r($holiday->isHolidayTest($workingDays[0])) && p() && e('It is not a holiday'); // 测试补班2022年5月7日
|
||||
r($holiday->isHolidayTest($workingDays[1])) && p() && e('It is not a holiday'); // 测试补班2022年5月13日
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/holiday.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 holidayModel->create();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$holidayIDList = array('1', '2');
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
$updateType = array('type' => 'working');
|
||||
$updateName = array('name' => '修改holiday的名字');
|
||||
$updateDesc = array('desc' => '一些描述');
|
||||
$noName = array('name' => '');
|
||||
$noBegin = array('begin' => '');
|
||||
$noEnd = array('end' => '');
|
||||
$endltBegin = array('begin' => '2022-05-08', 'end' => '2022-05-01');
|
||||
|
||||
r($holiday->updateTest($holidayIDList[0], $updateType)) && p() && e('true'); //测试修改类型
|
||||
r($holiday->updateTest($holidayIDList[0], $updateName)) && p() && e('true'); //测试修改名称
|
||||
r($holiday->updateTest($holidayIDList[0], $updateDesc)) && p() && e('true'); //测试修改描述
|
||||
r($holiday->updateTest($holidayIDList[0], $noName)) && p('name:0') && e('『名称』不能为空。'); //测试将必填项名称置空
|
||||
r($holiday->updateTest($holidayIDList[0], $noBegin)) && p('begin:0') && e('『开始日期』应当为合法的日期。'); //测试将必填项开始日期置空
|
||||
r($holiday->updateTest($holidayIDList[0], $noEnd)) && p('end:0') && e('『结束日期』应当为合法的日期。'); //测试将必填项结束日期置空
|
||||
r($holiday->updateTest($holidayIDList[0], $endltBegin)) && p('end:0') && e('『结束日期』应当不小于'); //测试输入大于开始日期的结束日期
|
||||
|
||||
system("./ztest init");
|
||||
Reference in New Issue
Block a user