📄 leavetest.php
字号:
<?php
/**
* OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
* all the essential functionalities required for any enterprise.
* Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
*
* OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA
*
*/
// Call LeaveTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
define("PHPUnit_MAIN_METHOD", "LeaveTest::main");
}
require_once "PHPUnit/Framework/TestCase.php";
require_once "PHPUnit/Framework/TestSuite.php";
require_once "testConf.php";
$_SESSION['WPATH'] = WPATH;
require_once "Leave.php";
require_once ROOT_PATH."/lib/confs/Conf.php";
/**
* Test class for Leave.
* Generated by PHPUnit_Util_Skeleton on 2006-10-12 at 08:36:24.
*/
class LeaveTest extends PHPUnit_Framework_TestCase {
public $classLeave = null;
public $connection = null;
/**
* Runs the test methods of this class.
*
* @access public
* @static
*/
public static function main() {
require_once "PHPUnit/TextUI/TestRunner.php";
$suite = new PHPUnit_Framework_TestSuite("LeaveTest");
$result = PHPUnit_TextUI_TestRunner::run($suite);
}
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp() {
$this->classLeave = new Leave();
$conf = new Conf();
$this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
mysql_select_db($conf->dbname);
mysql_query("INSERT INTO `hs_hr_employee` VALUES (11, '011', 'Arnold', 'Subasinghe', '', 'Arnold', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', '', NULL, '0000-00-00', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
mysql_query("INSERT INTO `hs_hr_employee` VALUES (12, '012', 'Mohanjith', 'Sudirikku', 'Hannadige', 'MOHA', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
mysql_query("INSERT INTO `hs_hr_employee` VALUES (13, '013', 'MohanjithX', 'SudirikkuX', 'HannadigeX', 'MOHAX', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
mysql_query("INSERT INTO `hs_hr_employee` VALUES (14, '014', 'Mohanjith1', 'Sudirikku1', 'Hannadige1', 'MOHA1', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
mysql_query("INSERT INTO `hs_hr_employee` VALUES (15, '015', 'Mohanjith1', 'Sudirikku1', 'Hannadige1', 'MOHA1', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
// For testStoreLeaveTaken
mysql_query("INSERT INTO `hs_hr_employee` VALUES ('018', NULL, 'Gayanath', 'Wageeshwara', 'Jayarathne', 'GAYA', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
mysql_query("INSERT INTO `hs_hr_employee` VALUES (19, 'A19', 'Gamalath', 'Kamalra', 'JKD', 'ABC', 0, NULL, '0000-00-00 00:00:00', NULL, NULL, NULL, '', '', '', '', '0000-00-00', '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00', NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)");
mysql_query("INSERT INTO `hs_hr_emp_reportto` VALUES ('012', '011', 1);");
mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");
// For testStoreLeaveTaken
mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY012', 'Personal', 1)");
mysql_query("INSERT INTO `hs_hr_workshift` (`workshift_id`, `name`, `hours_per_day`) VALUES (10, 'Test', 6);");
mysql_query("INSERT INTO `hs_hr_employee_workshift` (`workshift_id`, `emp_number`) VALUES (10, 15)");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (10, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '012')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (11, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '011')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (12, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '013')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (13, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '014')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (14, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '013')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (15, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '015')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (16, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '019')");
mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (17, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '019')");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`) VALUES (10, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 1, 0.12, 1, 'Leave 1', 11)");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`) VALUES (11, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*2)."', 1, 0.12, 1, 'Leave 2', 11)");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`) VALUES (12, '013', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 8, 1, 3, 'Leave 4', 12)");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`) VALUES (13, '013', 'LTY010', '".date('Y-m-d', time()+3600*24*2)."', 8, 1, 3, 'Leave 5', 12)");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`, `start_time`, `end_time`) VALUES (15, '014', 'LTY010', '".date('Y-m-d', time())."', 8, 1, 2, 'Leave 6', 13, '10:00', '18:00')");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`, `start_time`, `end_time`) VALUES (16, '013', 'LTY010', '".date('Y-m-d', time())."', 8, 1, 3, 'Leave 7', 14, '10:00', '18:00')");
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`, `start_time`, `end_time`) VALUES (17, '015', 'LTY010', '".date('Y-m-d', time()+3600*24*2)."', 1, 0.17, 1, 'Leave 2', 15, '10:00', '11:00')");
$this->assertTrue(mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`, `start_time`, `end_time`) VALUES (18, '019', 'LTY010', '".date('Y-m-d', time()+3600*24*3)."', 1, 0.17, 0, 'Leave 2', 16, '10:00', '11:00')"), mysql_error());
mysql_query("INSERT INTO `hs_hr_leave` (`leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_hours`, `leave_length_days`, `leave_status`, `leave_comments`, `leave_request_id`, `start_time`, `end_time`) VALUES (19, '019', 'LTY010', '".date('Y-m-d', time()+3600*24*4)."', 1, 0.17, -1, 'Leave 2', 17, '10:00', '11:00')");
// For testStoreLeaveTaken
mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted) VALUES ('2007', 'LTY012', '018', '10')");
}
/**
* Test the retrieveDuplicateLeave method
*/
public function testRetrieveDuplicateLeave() {
$leaveObj = $this->classLeave;
// unknown employee id -> return empty array
$result = $leaveObj->retrieveDuplicateLeave(16, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*4));
$this->assertNull($result);
// no duplicate leave -> return empty array
$result = $leaveObj->retrieveDuplicateLeave(15, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*1));
$this->assertNull($result);
// Only cancelled duplicate leave -> return empty array
$result = $leaveObj->retrieveDuplicateLeave(19, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*3));
$this->assertNull($result);
// Return rejected duplicate leave
$result = $leaveObj->retrieveDuplicateLeave(19, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*4));
$this->assertTrue(is_array($result));
$this->assertEquals(1, count($result));
$this->assertEquals($result[0]->getLeaveId(), 19);
// Return duplicate leave
$result = $leaveObj->retrieveDuplicateLeave(13, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*4));
$this->assertTrue(is_array($result));
$this->assertEquals(3, count($result));
$expected = array(12, 13, 16);
foreach ($result as $leave) {
$key = array_search($leave->getLeaveId(), $expected);
$this->assertTrue($key !== false);
unset($expected[$key]);
}
$this->assertEquals(count($expected), 0);
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown() {
mysql_query("DELETE FROM `hs_hr_emp_reportto` WHERE `erep_sup_emp_number` = '012' AND `erep_sub_emp_number` = '011'", $this->connection);
mysql_query("TRUNCATE TABLE `hs_hr_leave`", $this->connection);
mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`", $this->connection);
mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY010'", $this->connection);
mysql_query("DELETE FROM `hs_hr_employee_workshift` WHERE `workshift_id` = '10'");
mysql_query("DELETE FROM `hs_hr_workshift` WHERE `workshift_id` = '10'");
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '011'", $this->connection);
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '012'", $this->connection);
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '013'", $this->connection);
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '014'", $this->connection);
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '015'", $this->connection);
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '019'", $this->connection);
// For testStoreLeaveTaken
mysql_query("DELETE FROM `hs_hr_employee_leave_quota` WHERE employee_id = '018'");
mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '018'", $this->connection);
}
public function testRetrieveTakenLeaveAccuracy1() {
$leveObj = $this->classLeave;
$res = $leveObj->retrieveTakenLeave(date('Y', time()+3600*24*367), '013');
$this->assertEquals($res, false, "Returned future record");
}
public function testRetrieveTakenLeaveAccuracy2() {
$leveObj = $this->classLeave;
$res = $leveObj->retrieveTakenLeave(date('Y', time()+3600*24), '010');
$this->assertEquals($res, false, "Returned non exsiting record");
}
public function testRetrieveTakenLeaveAccuracy3() {
$leveObj = $this->classLeave;
$res = $leveObj->retrieveTakenLeave(date('Y', time()+3600*24), '013');
$expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 3, 8, 'Leave 4', null, null);
$expected[1] = array(date('Y-m-d', time()+3600*24*2), 'Medical', 3, 8, 'Leave 5', null, null);
$expected[2] = array(date('Y-m-d', time()), 'Medical', 3, 8, 'Leave 7', '10:00', '18:00');
$this->assertNotNull($res, "Returned nothing");
$this->assertEquals(count($res), count($expected), "Didn't return the expected number of records");
for ($i=0; $i < count($res); $i++) {
$this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Didn't return expected result");
$this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result");
$this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result");
$this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][4], "Didn't return expected result");
$this->assertEquals($res[$i]->getStartTime(), $expected[$i][5], "Didn't return expected result");
$this->assertEquals($res[$i]->getEndTime(), $expected[$i][6], "Didn't return expected result");
}
}
public function testRetrieveIndividualLeaveAccuracy1() {
$leveObj = $this->classLeave;
$res = $leveObj->retrieveIndividualLeave('12');
$expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 3, 8, 'Leave 4', null, null);
$this->assertNotNull($res, "Returned nothing");
$this->assertEquals(count($res), count($expected), "Didn't return the expected number of records");
for ($i=0; $i < count($res); $i++) {
$this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Didn't return expected result");
$this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result");
$this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result");
$this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][4], "Didn't return expected result");
$this->assertEquals($res[$i]->getStartTime(), $expected[$i][5], "Didn't return expected result");
$this->assertEquals($res[$i]->getEndTime(), $expected[$i][6], "Didn't return expected result");
}
}
public function testRetriveLeaveEmployeeAccuracy() {
$res = $this->classLeave->retrieveLeaveEmployee("011");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -