PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/leave/LeaveRequestsTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 546 lines | 343 code | 137 blank | 66 comment | 10 complexity | ea7cef2acef37cea9feace99698607f9 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, AGPL-3.0, BSD-3-Clause, AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. *
  19. */
  20. // Call LeaveRequestTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "LeaveRequestTest::main");
  23. }
  24. require_once "PHPUnit/Framework/TestCase.php";
  25. require_once "PHPUnit/Framework/TestSuite.php";
  26. require_once "testConf.php";
  27. $_SESSION['WPATH'] = WPATH;
  28. require_once 'LeaveRequests.php';
  29. require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';
  30. /**
  31. * Test class for LeaveRequest.
  32. * Generated by PHPUnit_Util_Skeleton on 2006-12-28 at 05:15:40.
  33. */
  34. class LeaveRequestsTest extends PHPUnit_Framework_TestCase {
  35. public $classLeaveRequest = null;
  36. public $connection = null;
  37. /**
  38. * Runs the test methods of this class.
  39. *
  40. * @access public
  41. * @static
  42. */
  43. public static function main() {
  44. require_once "PHPUnit/TextUI/TestRunner.php";
  45. $suite = new PHPUnit_Framework_TestSuite("LeaveRequestsTest");
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. /**
  49. * Sets up the fixture, for example, open a network connection.
  50. * This method is called before a test is executed.
  51. *
  52. * @access protected
  53. */
  54. protected function setUp() {
  55. $this->classLeaveRequest = new LeaveRequests();
  56. $conf = new Conf();
  57. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  58. mysql_select_db($conf->dbname);
  59. $this->_deleteTestData();
  60. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_nick_name, coun_code) " .
  61. "VALUES ('011', 'Arnold', 'Subasinghe', 'Arnold', 'AF')");
  62. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  63. "VALUES ('012', 'Mohanjith', 'Sudirikku', 'Hannadige', 'MOHA')");
  64. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  65. "VALUES ('013', 'Mohanjithx', 'Sudirikkux', 'Hannadigex', 'MOHAx')");
  66. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  67. "VALUES ('014', 'Mohanjith1', 'Sudirikku1', 'Hannadige1', 'MOHA1')");
  68. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  69. "VALUES ('015', 'Jack', 'Bauer', '', 'John')");
  70. mysql_query("INSERT INTO `hs_hr_emp_reportto` VALUES ('012', '011', 1);");
  71. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");
  72. mysql_query("TRUNCATE TABLE `hs_hr_weekends`;");
  73. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (1, 0);"), mysql_error());
  74. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (2, 0);"), mysql_error());
  75. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (3, 0);"), mysql_error());
  76. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (4, 0);"), mysql_error());
  77. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (5, 0);"), mysql_error());
  78. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (6, 0);"), mysql_error());
  79. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_weekends` (day, length) VALUES (7, 0);"), mysql_error());
  80. //Leave 1
  81. 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)."', '011')");
  82. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (10, 10, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 0.12, 1, 1, 'Leave 1')");
  83. //Leave 2
  84. 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')");
  85. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (11, 11, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 0.12, 1, 1, 'Leave 2-1')");
  86. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (11, 13, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*2)."', 0.12, 1, 1, 'Leave 2-2')");
  87. //Leave 3
  88. 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*3)."', '011')");
  89. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (13, 14, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*3)."', 0.12, 1, 2, 'Leave 3 Approved')");
  90. // Leave 4
  91. 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*3)."', '011')");
  92. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (14, 15, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*3)."', 0.12, 1, 0, 'Leave 4 Cancelled')");
  93. // Leave 5
  94. 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*4)."', '011')");
  95. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (15, 16, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*4)."', 0.12, 1, -1, 'Leave 5 Rejected')");
  96. // Leave 6
  97. 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*5)."', '011')");
  98. mysql_query("INSERT INTO `hs_hr_leave` (`leave_request_id`, `leave_id`, `employee_id`, `leave_type_id`, `leave_date`, `leave_length_days`, `leave_length_hours`, `leave_status`, `leave_comments`) VALUES (16, 17, '011', 'LTY010', '".date('Y-m-d', time()+3600*24*5)."', 0.12, 1, 3, 'Leave 6 Taken')");
  99. 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)."', '015')");
  100. UniqueIDGenerator::getInstance()->initTable();
  101. }
  102. /**
  103. * Tears down the fixture, for example, close a network connection.
  104. * This method is called after a test is executed.
  105. *
  106. * @access protected
  107. */
  108. protected function tearDown() {
  109. $this->_deleteTestData();
  110. }
  111. /**
  112. * Deletes test data created during test
  113. */
  114. private function _deleteTestData() {
  115. mysql_query("DELETE FROM `hs_hr_emp_reportto` WHERE `erep_sup_emp_number` = '012' AND `erep_sub_emp_number` = '011'", $this->connection);
  116. mysql_query("TRUNCATE TABLE `hs_hr_leave`");
  117. mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`");
  118. mysql_query("TRUNCATE TABLE `hs_hr_weekends`;");
  119. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY010'");
  120. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '011'");
  121. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '012'");
  122. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '013'");
  123. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '014'");
  124. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '015'");
  125. }
  126. /**
  127. * Run given sql query
  128. */
  129. private function _runQuery($sql) {
  130. $this->assertTrue(mysql_query($sql), mysql_error());
  131. }
  132. public function testRetriveLeaveRequestsEmployee1() {
  133. $leaveObj = $this->classLeaveRequest;
  134. $res = $leaveObj->retriveLeaveRequestsEmployee('051');
  135. $this->assertNull($res, 'Non exsistent record found');
  136. }
  137. public function testRetriveLeaveRequestsEmployee2() {
  138. $leaveObj = $this->classLeaveRequest;
  139. $employeeId = '011';
  140. $res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);
  141. $this->assertNotNull($res, 'Record not found');
  142. $this->assertSame(6, count($res), 'Wrong number of records found');
  143. $expected[0] = array('10', 'Medical', date('Y-m-d', time()+3600*24), null);
  144. $expected[1] = array('11', 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2));
  145. $expected[2] = array('13', 'Medical', date('Y-m-d', time()+3600*24*3), null);
  146. $expected[3] = array('14', 'Medical', date('Y-m-d', time()+3600*24*3), null);
  147. $expected[4] = array('15', 'Medical', date('Y-m-d', time()+3600*24*4), null);
  148. $expected[5] = array('16', 'Medical', date('Y-m-d', time()+3600*24*5), null);
  149. for ($i=0; $i<count($res); $i++) {
  150. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  151. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  152. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  153. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
  154. }
  155. }
  156. public function testRetriveLeaveRequestsSupervisor1() {
  157. $leaveObj = $this->classLeaveRequest;
  158. $statusPendingApproval = array(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL);
  159. $res = $leaveObj->retriveLeaveRequestsSupervisor('051',$statusPendingApproval,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  160. $this->assertNull($res, 'Non exsistent record found');
  161. }
  162. public function testRetriveLeaveRequestsSupervisor2() {
  163. $leaveObj = $this->classLeaveRequest;
  164. $employeeId = '012';
  165. $statusPendingApproval = array(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL);
  166. $res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId,$statusPendingApproval,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  167. $this->assertNotNull($res, 'Record not found');
  168. $this->assertSame(3, count($res), 'Wrong number of records found');
  169. $expected[0] = array('10', 'Medical', date('Y-m-d', time()+3600*24), null);
  170. $expected[1] = array('11', 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2));
  171. $expected[2] = array('11', 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2)); // TODO: This need to be checked.
  172. for ($i=0; $i<count($res); $i++) {
  173. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  174. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  175. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  176. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
  177. }
  178. $statusApproved = array(Leave::LEAVE_STATUS_LEAVE_APPROVED);
  179. $res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId,$statusApproved,date('Y-m-d', time()+3600*24*3),date('Y-m-d', time()+3600*24*3), '0,50');
  180. $this->assertNotNull($res, 'Record not found');
  181. $this->assertSame(1, count($res), 'Wrong number of records found');
  182. $expected = array('13', 'Medical', date('Y-m-d', time()+3600*24*3), null);
  183. $this->assertSame($expected[0], $res[0]->getLeaveRequestId(), 'Wrong Leave Request Id');
  184. $this->assertSame($expected[1], $res[0]->getLeaveTypeName(), 'Wrong Leave Type Name');
  185. $this->assertSame($expected[2], $res[0]->getLeaveFromDate(), 'Wrong From Date');
  186. $this->assertSame($expected[3], $res[0]->getLeaveToDate(), 'Wrong To Date');
  187. $statusCancelled = array(Leave::LEAVE_STATUS_LEAVE_CANCELLED);
  188. $res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId,$statusCancelled,date('Y-m-d', time()+3600*24*3),date('Y-m-d', time()+3600*24*3), '0,50');
  189. $this->assertNotNull($res, 'Record not found');
  190. $this->assertSame(1, count($res), 'Wrong number of records found');
  191. $expected = array('14', 'Medical', date('Y-m-d', time()+3600*24*3), null);
  192. $this->assertSame($expected[0], $res[0]->getLeaveRequestId(), 'Wrong Leave Request Id');
  193. $this->assertSame($expected[1], $res[0]->getLeaveTypeName(), 'Wrong Leave Type Name');
  194. $this->assertSame($expected[2], $res[0]->getLeaveFromDate(), 'Wrong From Date');
  195. $this->assertSame($expected[3], $res[0]->getLeaveToDate(), 'Wrong To Date');
  196. $statusRejected = array(Leave::LEAVE_STATUS_LEAVE_REJECTED);
  197. $res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId,$statusRejected,date('Y-m-d', time()+3600*24*4),date('Y-m-d', time()+3600*24*4), '0,50');
  198. $this->assertNotNull($res, 'Record not found');
  199. $this->assertSame(1, count($res), 'Wrong number of records found');
  200. $expected = array('15', 'Medical', date('Y-m-d', time()+3600*24*4), null);
  201. $this->assertSame($expected[0], $res[0]->getLeaveRequestId(), 'Wrong Leave Request Id');
  202. $this->assertSame($expected[1], $res[0]->getLeaveTypeName(), 'Wrong Leave Type Name');
  203. $this->assertSame($expected[2], $res[0]->getLeaveFromDate(), 'Wrong From Date');
  204. $this->assertSame($expected[3], $res[0]->getLeaveToDate(), 'Wrong To Date');
  205. $statusTaken = array(Leave::LEAVE_STATUS_LEAVE_TAKEN);
  206. $res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId,$statusTaken,date('Y-m-d', time()+3600*24*5),date('Y-m-d', time()+3600*24*5), '0,50');
  207. $this->assertNotNull($res, 'Record not found');
  208. $this->assertSame(1, count($res), 'Wrong number of records found');
  209. $expected = array('16', 'Medical', date('Y-m-d', time()+3600*24*5), null);
  210. $this->assertSame($expected[0], $res[0]->getLeaveRequestId(), 'Wrong Leave Request Id');
  211. $this->assertSame($expected[1], $res[0]->getLeaveTypeName(), 'Wrong Leave Type Name');
  212. $this->assertSame($expected[2], $res[0]->getLeaveFromDate(), 'Wrong From Date');
  213. $this->assertSame($expected[3], $res[0]->getLeaveToDate(), 'Wrong To Date');
  214. $statuses = array(Leave::LEAVE_STATUS_LEAVE_CANCELLED,Leave::LEAVE_STATUS_LEAVE_REJECTED,Leave::LEAVE_STATUS_LEAVE_TAKEN);
  215. $res = $leaveObj->retriveLeaveRequestsSupervisor($employeeId,$statuses,date('Y-m-d', time()+3600*24*3),date('Y-m-d', time()+3600*24*5), '0,50');
  216. $this->assertNotNull($res, 'Record not found');
  217. $this->assertSame(3, count($res), 'Wrong number of records found');
  218. }
  219. /**
  220. * Tests that retrieveLeaveRequestsSupervisor only retrieves leave requests with the
  221. * statuses: Pending approval, approved and rejected
  222. */
  223. public function testRetriveLeaveRequestsSupervisorStatuses() {
  224. $leaveObj = $this->classLeaveRequest;
  225. $supervisorId = '012';
  226. // Change status to Pending approval
  227. $statusPendingApproval = array(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL);
  228. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL." WHERE leave_request_id = 10"), mysql_error());
  229. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL." WHERE leave_request_id = 11"), mysql_error());
  230. $res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId,$statusPendingApproval,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  231. $this->assertNotNull($res, 'Record not found');
  232. $this->assertSame(3, count($res), 'Wrong number of records found');
  233. // Change status to Rejected
  234. $statusRejected = array(Leave::LEAVE_STATUS_LEAVE_REJECTED);
  235. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_REJECTED." WHERE leave_request_id = 10"), mysql_error());
  236. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_REJECTED." WHERE leave_request_id = 11"), mysql_error());
  237. $res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId,$statusRejected,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  238. $this->assertNotNull($res, 'Record not found');
  239. $this->assertSame(3, count($res), 'Wrong number of records found');
  240. // Change status to Approved
  241. $statusApproved = array(Leave::LEAVE_STATUS_LEAVE_APPROVED);
  242. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_APPROVED." WHERE leave_request_id = 10"), mysql_error());
  243. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_APPROVED." WHERE leave_request_id = 11"), mysql_error());
  244. $res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId,$statusApproved,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  245. $this->assertNotNull($res, 'Record not found');
  246. $this->assertSame(3, count($res), 'Wrong number of records found');
  247. // Change one leave request's status to 'Partly Approved'11, 13
  248. $statusPartlyApproved = array(Leave::LEAVE_STATUS_LEAVE_APPROVED,Leave::LEAVE_STATUS_LEAVE_REJECTED);
  249. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_APPROVED." WHERE leave_id = 11"), mysql_error());
  250. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_REJECTED." WHERE leave_id = 13"), mysql_error());
  251. $res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId,$statusPartlyApproved,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  252. $this->assertNotNull($res, 'Record not found');
  253. $this->assertSame(3, count($res), 'Wrong number of records found');
  254. $statusCancelled = array(Leave::LEAVE_STATUS_LEAVE_CANCELLED);
  255. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_CANCELLED." WHERE leave_request_id = 10"), mysql_error());
  256. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_CANCELLED." WHERE leave_request_id = 11"), mysql_error());
  257. $res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId,$statusCancelled,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  258. $this->assertNotNull($res, 'Should not return any results');
  259. $statusTaken = array(Leave::LEAVE_STATUS_LEAVE_TAKEN);
  260. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_TAKEN." WHERE leave_request_id = 10"), mysql_error());
  261. $this->assertTrue(mysql_query("UPDATE `hs_hr_leave` SET `leave_status`=". Leave::LEAVE_STATUS_LEAVE_TAKEN." WHERE leave_request_id = 11"), mysql_error());
  262. $res = $leaveObj->retriveLeaveRequestsSupervisor($supervisorId,$statusTaken,date('Y-m-d', time()+3600*24),date('Y-m-d', time()+3600*24*2), '0,50');
  263. $this->assertNotNull($res, 'Should not return any results');
  264. }
  265. public function testApplyLeave1() {
  266. $employeeId = '012';
  267. $this->classLeaveRequest->setEmployeeId($employeeId);
  268. $this->classLeaveRequest->setLeaveTypeId("LTY010");
  269. $this->classLeaveRequest->setLeaveFromDate(date('Y-m-d', time()+3600*24));
  270. $this->classLeaveRequest->setLeaveToDate(date('Y-m-d', time()+3600*24));
  271. $this->classLeaveRequest->setLeaveLengthHours($this->classLeaveRequest->lengthFullDay);
  272. $this->classLeaveRequest->setLeaveStatus("1");
  273. $this->classLeaveRequest->setLeaveComments("New Leave 1");
  274. $this->classLeaveRequest->applyLeaveRequest();
  275. $newId = $this->classLeaveRequest->getLeaveRequestId();
  276. $leaveObj = $this->classLeaveRequest;
  277. $res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);
  278. $this->assertNotNull($res, 'Record not found');
  279. $this->assertSame(1, count($res), 'Wrong number of records found');
  280. $expected[0] = array($newId, 'Medical', date('Y-m-d', time()+3600*24), null, '8.00', '1.00');
  281. for ($i=0; $i<count($res); $i++) {
  282. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  283. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  284. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  285. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
  286. $this->assertSame($expected[$i][4], $res[$i]->getLeaveLengthHours(), "Wrong length(hours)");
  287. $this->assertEquals($expected[$i][5], $res[$i]->getNoDays(), "Wrong length(days)");
  288. }
  289. }
  290. public function testApplyLeave2() {
  291. $employeeId = '012';
  292. $this->classLeaveRequest->setEmployeeId($employeeId);
  293. $this->classLeaveRequest->setLeaveTypeId("LTY010");
  294. $this->classLeaveRequest->setLeaveFromDate(date('Y-m-d', time()+3600*24));
  295. $this->classLeaveRequest->setLeaveToDate(date('Y-m-d', time()+3600*24*3));
  296. $this->classLeaveRequest->setLeaveLengthHours($this->classLeaveRequest->lengthFullDay);
  297. $this->classLeaveRequest->setLeaveStatus("1");
  298. $this->classLeaveRequest->setLeaveComments("New Leave 1");
  299. $this->classLeaveRequest->applyLeaveRequest();
  300. $newId = $this->classLeaveRequest->getLeaveRequestId();
  301. $leaveObj = $this->classLeaveRequest;
  302. $res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);
  303. $this->assertNotNull($res, 'Record not found');
  304. $this->assertSame(1, count($res), 'Wrong number of records found');
  305. $expected[0] = array($newId, 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*3), '24.00', '3.00');
  306. for ($i=0; $i<count($res); $i++) {
  307. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  308. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  309. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  310. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
  311. $this->assertSame($expected[$i][4], $res[$i]->getLeaveLengthHours(), "Wrong length(hours)");
  312. $this->assertSame($expected[$i][5], $res[$i]->getNoDays(), "Wrong length(days)");
  313. }
  314. }
  315. public function testApplyLeave3() {
  316. // Mark Sunday as weekend
  317. $this->assertTrue(mysql_query("UPDATE `hs_hr_weekends` SET length=8 WHERE day=7"), mysql_error());
  318. $employeeId = '012';
  319. $this->classLeaveRequest = null;
  320. $this->classLeaveRequest = new LeaveRequests();
  321. $this->classLeaveRequest->setEmployeeId($employeeId);
  322. $this->classLeaveRequest->setLeaveTypeId("LTY010");
  323. $this->classLeaveRequest->setLeaveFromDate(date('Y-m-d', time()+3600*24));
  324. $this->classLeaveRequest->setLeaveToDate(date('Y-m-d', time()+3600*24*7));
  325. $this->classLeaveRequest->setLeaveLengthHours($this->classLeaveRequest->lengthFullDay);
  326. $this->classLeaveRequest->setLeaveStatus("1");
  327. $this->classLeaveRequest->setLeaveComments("New Leave 1");
  328. $this->classLeaveRequest->applyLeaveRequest();
  329. $newId = $this->classLeaveRequest->getLeaveRequestId();
  330. $leaveObj = $this->classLeaveRequest;
  331. $res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);
  332. $this->assertNotNull($res, 'Record not found');
  333. $this->assertSame(1, count($res), 'Wrong number of records found');
  334. $expected[0] = array($newId, 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*7), '48.00', '6.00');
  335. for ($i=0; $i<count($res); $i++) {
  336. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  337. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  338. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  339. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), "Wrong To Date");
  340. $this->assertSame($expected[$i][4], $res[$i]->getLeaveLengthHours(), "Wrong length(hours) {$expected[$i][4]} {$res[$i]->getLeaveLengthHours()}");
  341. $this->assertSame($expected[$i][5], $res[$i]->getNoDays(), "Wrong length(days)");
  342. }
  343. }
  344. public function testApplyLeave4() {
  345. // Mark Saturday and Sunday as weekend
  346. $this->assertTrue(mysql_query("UPDATE `hs_hr_weekends` SET length=8 WHERE day=7 OR day=6"), mysql_error());
  347. $employeeId = '012';
  348. $this->classLeaveRequest = null;
  349. $this->classLeaveRequest = new LeaveRequests();
  350. $this->classLeaveRequest->setEmployeeId($employeeId);
  351. $this->classLeaveRequest->setLeaveTypeId("LTY010");
  352. $this->classLeaveRequest->setLeaveFromDate(date('Y-m-d', time()+3600*24));
  353. $this->classLeaveRequest->setLeaveToDate(date('Y-m-d', time()+3600*24*7));
  354. $this->classLeaveRequest->setLeaveLengthHours($this->classLeaveRequest->lengthFullDay);
  355. $this->classLeaveRequest->setLeaveStatus("1");
  356. $this->classLeaveRequest->setLeaveComments("New Leave 1");
  357. $this->classLeaveRequest->applyLeaveRequest();
  358. $newId = $this->classLeaveRequest->getLeaveRequestId();
  359. $leaveObj = $this->classLeaveRequest;
  360. $res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);
  361. $this->assertNotNull($res, 'Record not found');
  362. $this->assertSame(1, count($res), 'Wrong number of records found');
  363. $expected[0] = array($newId, 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*7), '40.00', '5.00');
  364. for ($i=0; $i<count($res); $i++) {
  365. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  366. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  367. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  368. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
  369. $this->assertSame($expected[$i][4], $res[$i]->getLeaveLengthHours(), "Wrong length(hours) {$expected[$i][4]} {$res[$i]->getLeaveLengthHours()}");
  370. $this->assertSame($expected[$i][5], $res[$i]->getNoDays(), "Wrong length(days)");
  371. }
  372. }
  373. public function testApplyLeave5() {
  374. // Mark Saturday as half day
  375. $this->assertTrue(mysql_query("UPDATE `hs_hr_weekends` SET length=4 WHERE day=6"), mysql_error());
  376. // Mark Sunday as weekend
  377. $this->assertTrue(mysql_query("UPDATE `hs_hr_weekends` SET length=8 WHERE day=7"), mysql_error());
  378. $employeeId = '012';
  379. $this->classLeaveRequest = null;
  380. $this->classLeaveRequest = new LeaveRequests();
  381. $this->classLeaveRequest->setEmployeeId($employeeId);
  382. $this->classLeaveRequest->setLeaveTypeId("LTY010");
  383. $this->classLeaveRequest->setLeaveFromDate(date('Y-m-d', time()+3600*24));
  384. $this->classLeaveRequest->setLeaveToDate(date('Y-m-d', time()+3600*24*7));
  385. $this->classLeaveRequest->setLeaveLengthHours($this->classLeaveRequest->lengthFullDay);
  386. $this->classLeaveRequest->setLeaveStatus("1");
  387. $this->classLeaveRequest->setLeaveComments("New Leave 1");
  388. $this->classLeaveRequest->applyLeaveRequest();
  389. $newId = $this->classLeaveRequest->getLeaveRequestId();
  390. $leaveObj = $this->classLeaveRequest;
  391. $res = $leaveObj->retriveLeaveRequestsEmployee($employeeId);
  392. $this->assertNotNull($res, 'Record not found');
  393. $this->assertSame(1, count($res), 'Wrong number of records found');
  394. $expected[0] = array($newId, 'Medical', date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*7), '44.00', '5.50');
  395. for ($i=0; $i<count($res); $i++) {
  396. $this->assertSame($expected[$i][0], $res[$i]->getLeaveRequestId(), 'Wrong Leave Request Id');
  397. $this->assertSame($expected[$i][1], $res[$i]->getLeaveTypeName(), 'Wrong Leave Type Name');
  398. $this->assertSame($expected[$i][2], $res[$i]->getLeaveFromDate(), 'Wrong From Date');
  399. $this->assertSame($expected[$i][3], $res[$i]->getLeaveToDate(), 'Wrong To Date');
  400. $this->assertSame($expected[$i][4], $res[$i]->getLeaveLengthHours(), "Wrong length(hours) {$expected[$i][4]} {$res[$i]->getLeaveLengthHours()}");
  401. $this->assertSame($expected[$i][5], $res[$i]->getNoDays(), "Wrong length(days)");
  402. }
  403. }
  404. }
  405. // Call LeaveRequestTest::main() if this source file is executed directly.
  406. if (PHPUnit_MAIN_METHOD == "LeaveRequestsTest::main") {
  407. LeaveRequestsTest::main();
  408. }
  409. ?>