diff --git a/module/holiday/model.php b/module/holiday/model.php index 943110a11e..f106024f6f 100644 --- a/module/holiday/model.php +++ b/module/holiday/model.php @@ -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; } /** diff --git a/test/class/holiday.class.php b/test/class/holiday.class.php new file mode 100644 index 0000000000..d3c59768ae --- /dev/null +++ b/test/class/holiday.class.php @@ -0,0 +1,280 @@ +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; + } +} diff --git a/test/model/holiday/create.php b/test/model/holiday/create.php new file mode 100755 index 0000000000..39ad938808 --- /dev/null +++ b/test/model/holiday/create.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +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"); diff --git a/test/model/holiday/getactualworkingdays.php b/test/model/holiday/getactualworkingdays.php new file mode 100755 index 0000000000..755c053a9a --- /dev/null +++ b/test/model/holiday/getactualworkingdays.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +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的情况 diff --git a/test/model/holiday/getbyid.php b/test/model/holiday/getbyid.php new file mode 100755 index 0000000000..3ede973c12 --- /dev/null +++ b/test/model/holiday/getbyid.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +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 diff --git a/test/model/holiday/getdaysbetween.php b/test/model/holiday/getdaysbetween.php new file mode 100755 index 0000000000..ceda79bf95 --- /dev/null +++ b/test/model/holiday/getdaysbetween.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +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'); //测试传入同一天的情况 diff --git a/test/model/holiday/getyearpairs.php b/test/model/holiday/getyearpairs.php new file mode 100755 index 0000000000..b0cbc20495 --- /dev/null +++ b/test/model/holiday/getyearpairs.php @@ -0,0 +1,17 @@ +#!/usr/bin/env php +getYearPairs(); +cid=1 +pid=1 + +*/ + +$holiday = new holidayTest(); + +r($holiday->getYearPairsTest()) && p() && e('1'); //测试getYearPairsTest方法 diff --git a/test/model/holiday/isholiday.php b/test/model/holiday/isholiday.php new file mode 100755 index 0000000000..43245ca9eb --- /dev/null +++ b/test/model/holiday/isholiday.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +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日 diff --git a/test/model/holiday/update.php b/test/model/holiday/update.php new file mode 100755 index 0000000000..6279b05d14 --- /dev/null +++ b/test/model/holiday/update.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php +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");