PageRenderTime 26ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/leave/LeaveTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 551 lines | 419 code | 73 blank | 59 comment | 5 complexity | 417d0c1b26bc9531c340a57d717fe29c 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 LeaveTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "LeaveTest::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 "Leave.php";
  29. require_once ROOT_PATH."/lib/confs/Conf.php";
  30. /**
  31. * Test class for Leave.
  32. * Generated by PHPUnit_Util_Skeleton on 2006-10-12 at 08:36:24.
  33. */
  34. class LeaveTest extends PHPUnit_Framework_TestCase {
  35. public $classLeave = 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("LeaveTest");
  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->classLeave = new Leave();
  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, employee_id, emp_lastname, emp_firstname, emp_nick_name, coun_code) " .
  61. "VALUES (11, '011', 'Arnold', 'Subasinghe', 'Arnold', 'AF')");
  62. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  63. "VALUES (12, '012', 'Mohanjith', 'Sudirikku', 'Hannadige', 'MOHA')");
  64. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  65. "VALUES (13, '013', 'Mohanjithx', 'Sudirikkux', 'Hannadigex', 'MOHAx')");
  66. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  67. "VALUES (14, '014', 'Mohanjith1', 'Sudirikku1', 'Hannadige1', 'MOHA1')");
  68. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  69. "VALUES (15, '015', 'Mohanjith1', 'Sudirikku1', 'Hannadige1', 'MOHA1')");
  70. // For testStoreLeaveTaken
  71. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  72. "VALUES (18, NULL, 'Gayanath', 'Wageeshwara', 'Jayarathne', 'GAYA')");
  73. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  74. "VALUES (19, 'A19', 'Gamalath', 'Kamalra', 'JKD', 'ABC')");
  75. mysql_query("INSERT INTO `hs_hr_emp_reportto` VALUES ('012', '011', 1);");
  76. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");
  77. // For testStoreLeaveTaken
  78. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY012', 'Personal', 1)");
  79. mysql_query("INSERT INTO `hs_hr_workshift` (`workshift_id`, `name`, `hours_per_day`) VALUES (10, 'Test', 6);");
  80. mysql_query("INSERT INTO `hs_hr_employee_workshift` (`workshift_id`, `emp_number`) VALUES (10, 15)");
  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)."', '012')");
  82. 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')");
  83. 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')");
  84. 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')");
  85. 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')");
  86. 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')");
  87. 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')");
  88. 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')");
  89. 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)");
  90. 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)");
  91. 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)");
  92. 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)");
  93. 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')");
  94. 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')");
  95. 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')");
  96. $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());
  97. 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')");
  98. 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 (20, '016', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 8, 1, 4, 'Leave 6', 12)");
  99. // For testStoreLeaveTaken
  100. mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted) VALUES ('2007', 'LTY012', '018', '10')");
  101. }
  102. /**
  103. * Test the retrieveDuplicateLeave method
  104. */
  105. public function testRetrieveDuplicateLeave() {
  106. $leaveObj = $this->classLeave;
  107. // unknown employee id -> return empty array
  108. $result = $leaveObj->retrieveDuplicateLeave(16, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*4));
  109. $this->assertNull($result);
  110. // no duplicate leave -> return empty array
  111. $result = $leaveObj->retrieveDuplicateLeave(15, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*1));
  112. $this->assertNull($result);
  113. // Only cancelled duplicate leave -> return empty array
  114. $result = $leaveObj->retrieveDuplicateLeave(19, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*3));
  115. $this->assertNull($result);
  116. // Return rejected duplicate leave
  117. $result = $leaveObj->retrieveDuplicateLeave(19, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*4));
  118. $this->assertTrue(is_array($result));
  119. $this->assertEquals(1, count($result));
  120. $this->assertEquals($result[0]->getLeaveId(), 19);
  121. // Return duplicate leave
  122. $result = $leaveObj->retrieveDuplicateLeave(13, date('Y-m-d', time()), date('Y-m-d', time()+3600*24*4));
  123. $this->assertTrue(is_array($result));
  124. $this->assertEquals(3, count($result));
  125. $expected = array(12, 13, 16);
  126. foreach ($result as $leave) {
  127. $key = array_search($leave->getLeaveId(), $expected);
  128. $this->assertTrue($key !== false);
  129. unset($expected[$key]);
  130. }
  131. $this->assertEquals(count($expected), 0);
  132. }
  133. /**
  134. * Tears down the fixture, for example, close a network connection.
  135. * This method is called after a test is executed.
  136. *
  137. * @access protected
  138. */
  139. protected function tearDown() {
  140. $this->_deleteTestData();
  141. }
  142. /**
  143. * Deletes test data created during test
  144. */
  145. private function _deleteTestData() {
  146. mysql_query("DELETE FROM `hs_hr_emp_reportto` WHERE `erep_sup_emp_number` = '012' AND `erep_sub_emp_number` = '011'", $this->connection);
  147. mysql_query("TRUNCATE TABLE `hs_hr_leave`", $this->connection);
  148. mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`", $this->connection);
  149. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY010'", $this->connection);
  150. mysql_query("DELETE FROM `hs_hr_employee_workshift` WHERE `workshift_id` = '10'");
  151. mysql_query("DELETE FROM `hs_hr_workshift` WHERE `workshift_id` = '10'");
  152. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '011'", $this->connection);
  153. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '012'", $this->connection);
  154. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '013'", $this->connection);
  155. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '014'", $this->connection);
  156. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '015'", $this->connection);
  157. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '019'", $this->connection);
  158. // For testStoreLeaveTaken
  159. mysql_query("DELETE FROM `hs_hr_employee_leave_quota` WHERE employee_id = '018'");
  160. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '018'", $this->connection);
  161. }
  162. /**
  163. * Run given sql query
  164. */
  165. private function _runQuery($sql) {
  166. $this->assertTrue(mysql_query($sql), mysql_error());
  167. }
  168. public function testRetrieveTakenLeaveAccuracy1() {
  169. $leveObj = $this->classLeave;
  170. $res = $leveObj->retrieveTakenLeave(date('Y', time()+3600*24*367), '013');
  171. $this->assertEquals($res, false, "Returned future record");
  172. }
  173. public function testRetrieveTakenLeaveAccuracy2() {
  174. $leveObj = $this->classLeave;
  175. $res = $leveObj->retrieveTakenLeave(date('Y', time()+3600*24), '010');
  176. $this->assertEquals($res, false, "Returned non exsiting record");
  177. }
  178. public function testRetrieveTakenLeaveAccuracy3() {
  179. $leveObj = $this->classLeave;
  180. $res = $leveObj->retrieveTakenLeave(date('Y', time()+3600*24), '013');
  181. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 3, 8, 'Leave 4', null, null);
  182. $expected[1] = array(date('Y-m-d', time()+3600*24*2), 'Medical', 3, 8, 'Leave 5', null, null);
  183. $expected[2] = array(date('Y-m-d', time()), 'Medical', 3, 8, 'Leave 7', '10:00', '18:00');
  184. $this->assertNotNull($res, "Returned nothing");
  185. $this->assertEquals(count($res), count($expected), "Didn't return the expected number of records");
  186. for ($i=0; $i < count($res); $i++) {
  187. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Didn't return expected result");
  188. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result");
  189. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result");
  190. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][4], "Didn't return expected result");
  191. $this->assertEquals($res[$i]->getStartTime(), $expected[$i][5], "Didn't return expected result");
  192. $this->assertEquals($res[$i]->getEndTime(), $expected[$i][6], "Didn't return expected result");
  193. }
  194. }
  195. public function testRetrieveIndividualLeaveAccuracy1() {
  196. $leveObj = $this->classLeave;
  197. $res = $leveObj->retrieveIndividualLeave('12');
  198. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 3, 8, 'Leave 4', null, null);
  199. $this->assertNotNull($res, "Returned nothing");
  200. $this->assertEquals(count($res), count($expected), "Didn't return the expected number of records");
  201. for ($i=0; $i < count($res); $i++) {
  202. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Didn't return expected result");
  203. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result");
  204. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result");
  205. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][4], "Didn't return expected result");
  206. $this->assertEquals($res[$i]->getStartTime(), $expected[$i][5], "Didn't return expected result");
  207. $this->assertEquals($res[$i]->getEndTime(), $expected[$i][6], "Didn't return expected result");
  208. }
  209. }
  210. public function testRetrieveIndividualLeaveAccuracy2() {
  211. $leveObj = $this->classLeave;
  212. $res = $leveObj->retrieveIndividualLeave('20');
  213. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 4, 8, 'Leave 6');
  214. for ($i=0; $i < count($res); $i++) {
  215. $this->assertEquals($expected[$i][0], $res[$i]->getLeaveDate(), "Didn't return expected result");
  216. $this->assertEquals($expected[$i][2], $res[$i]->getLeaveStatus(), "Didn't return expected result");
  217. $this->assertEquals($expected[$i][3], $res[$i]->getLeaveLengthHours(), "Didn't return expected result");
  218. $this->assertEquals($expected[$i][4], $res[$i]->getLeaveComments(), "Didn't return expected result");
  219. }
  220. }
  221. public function testRetriveLeaveEmployeeAccuracy() {
  222. $res = $this->classLeave->retrieveLeaveEmployee("011");
  223. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 1, 1, 'Leave 1');
  224. $expected[1] = array(date('Y-m-d', time()+3600*24*2), 'Medical', 1, 1, 'Leave 2');
  225. $this->assertNotNull($res, "No record found ");
  226. $this->assertEquals(count($res), 2, "Number of records found is not accurate ");
  227. for ($i=0; $i < count($res); $i++) {
  228. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Didn't return expected result ");
  229. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result ");
  230. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result ");
  231. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][4], "Didn't return expected result ");
  232. }
  233. }
  234. public function testRetriveLeaveEmployeeAccuracy2() {
  235. $res = $this->classLeave->retrieveLeaveEmployee("015");
  236. $expected[0] = array(date('Y-m-d', time()+3600*24*2), 'Medical', 1, 1, 0.17, 'Leave 2', '10:00', '11:00');
  237. $this->assertNotNull($res, "No record found ");
  238. $this->assertEquals(count($res), count($expected), "Number of records found is not accurate ");
  239. for ($i=0; $i < count($res); $i++) {
  240. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Didn't return expected result ");
  241. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result ");
  242. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result ");
  243. $this->assertEquals($res[$i]->getLeaveLengthDays(), $expected[$i][4], "Didn't return expected result ");
  244. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][5], "Didn't return expected result ");
  245. $this->assertEquals($res[$i]->getStartTime(), $expected[$i][6], "Didn't return expected result ");
  246. $this->assertEquals($res[$i]->getEndTime(), $expected[$i][7], "Didn't return expected result ");
  247. }
  248. }
  249. public function testApplyLeave() {
  250. $this->classLeave->setLeaveRequestId("010");
  251. $this->classLeave->setEmployeeId("012");
  252. $this->classLeave->setLeaveTypeId("LTY010");
  253. $this->classLeave->setLeaveDate(date('Y-m-d', time()+3600*24));
  254. $this->classLeave->setLeaveLengthHours("2");
  255. $this->classLeave->setLeaveLengthDays("0.25");
  256. $this->classLeave->setLeaveStatus("1");
  257. $this->classLeave->setLeaveComments("Leave 1");
  258. $res = $this->classLeave->applyLeave();
  259. $res = $this->classLeave->retrieveLeaveEmployee("012");
  260. $this->assertNotNull($res, "No record found");
  261. $this->assertEquals(count($res), 1, "Wrong number of records found");
  262. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 1, 2, 0.25, 'Leave 1');
  263. for ($i=0; $i < count($expected); $i++) {
  264. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Checking added / applied leave ");
  265. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Checking added / applied leave ");
  266. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Checking added / applied leave ");
  267. $this->assertEquals($res[$i]->getLeaveLengthDays(), $expected[$i][4], "Checking added / applied leave ");
  268. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][5], "Checking added / applied leave ");
  269. }
  270. $this->classLeave->setLeaveComments("Leave 2");
  271. $res = $this->classLeave->applyLeave();
  272. $res = $this->classLeave->retrieveLeaveEmployee("012");
  273. $expected[1] = array(date('Y-m-d', time()+3600*24), 'Medical', 1, 2, 0.25, 'Leave 2');
  274. for ($i=0; $i < count($expected); $i++) {
  275. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Checking added / applied leave ");
  276. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Checking added / applied leave ");
  277. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Checking added / applied leave ");
  278. $this->assertEquals($res[$i]->getLeaveLengthDays(), $expected[$i][4], "Checking added / applied leave ");
  279. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][5], "Checking added / applied leave ");
  280. }
  281. }
  282. public function testApplyLeave2() {
  283. $this->classLeave->setLeaveRequestId("010");
  284. $this->classLeave->setEmployeeId("012");
  285. $this->classLeave->setLeaveTypeId("LTY010");
  286. $this->classLeave->setLeaveDate(date('Y-m-d', time()+3600*24));
  287. $this->classLeave->setLeaveLengthHours("2");
  288. $this->classLeave->setLeaveLengthDays("0.25");
  289. $this->classLeave->setLeaveStatus("1");
  290. $this->classLeave->setLeaveComments("Leave 1");
  291. $this->classLeave->setStartTime("08:00");
  292. $this->classLeave->setEndTime("10:00");
  293. $res = $this->classLeave->applyLeave();
  294. $res = $this->classLeave->retrieveLeaveEmployee("012");
  295. $this->assertNotNull($res, "No record found");
  296. $this->assertEquals(count($res), 1, "Wrong number of records found");
  297. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 1, 2, 0.25, 'Leave 1', "08:00", "10:00");
  298. for ($i=0; $i < count($expected); $i++) {
  299. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Checking added / applied leave ");
  300. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Checking added / applied leave ");
  301. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Checking added / applied leave ");
  302. $this->assertEquals($res[$i]->getLeaveLengthDays(), $expected[$i][4], "Checking added / applied leave ");
  303. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][5], "Checking added / applied leave ");
  304. $this->assertEquals($res[$i]->getStartTime(), $expected[$i][6], "Checking added / applied leave ");
  305. $this->assertEquals($res[$i]->getEndTime(), $expected[$i][7], "Checking added / applied leave ");
  306. }
  307. }
  308. public function testApplyLeave3() {
  309. $this->classLeave->setLeaveRequestId("15");
  310. $this->classLeave->setEmployeeId("15");
  311. $this->classLeave->setLeaveTypeId("LTY010");
  312. $this->classLeave->setLeaveDate(date('Y-m-d', time()+3600*24));
  313. $this->classLeave->setLeaveLengthHours("3");
  314. $this->classLeave->setLeaveStatus("1");
  315. $this->classLeave->setLeaveComments("Leave 1");
  316. $this->classLeave->setStartTime("08:00");
  317. $this->classLeave->setEndTime("10:00");
  318. $res = $this->classLeave->applyLeave();
  319. $res = $this->classLeave->retrieveLeaveEmployee("015");
  320. $this->assertNotNull($res, "No record found");
  321. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 1, 3, 0.5, 'Leave 1', "08:00", "10:00");
  322. $expected[1] = array(date('Y-m-d', time()+3600*24*2), 'Medical', 1, 1, 0.17, 'Leave 2', '10:00', '11:00');
  323. $this->assertEquals(count($res), count($expected), "Wrong number of records found");
  324. for ($i=0; $i < count($expected); $i++) {
  325. $this->assertEquals($res[$i]->getLeaveDate(), $expected[$i][0], "Checking added / applied leave ");
  326. $this->assertEquals($res[$i]->getLeaveStatus(), $expected[$i][2], "Checking added / applied leave ");
  327. $this->assertEquals($res[$i]->getLeaveLengthHours(), $expected[$i][3], "Checking added / applied leave ");
  328. $this->assertEquals($res[$i]->getLeaveLengthDays(), $expected[$i][4], "Checking added / applied leave ");
  329. $this->assertEquals($res[$i]->getLeaveComments(), $expected[$i][5], "Checking added / applied leave ");
  330. $this->assertEquals($res[$i]->getStartTime(), $expected[$i][6], "Checking added / applied leave ");
  331. $this->assertEquals($res[$i]->getEndTime(), $expected[$i][7], "Checking added / applied leave ");
  332. }
  333. }
  334. public function testCancelLeaveAccuracy() {
  335. $this->classLeave->setLeaveStatus(Leave::LEAVE_STATUS_LEAVE_CANCELLED);
  336. $res = $this->classLeave->cancelLeave(10);
  337. $expected = true;
  338. $this->assertEquals($res, $expected, "Cancel of leave failed ");
  339. $res = $this->classLeave->cancelLeave(10);
  340. $expected = false;
  341. $this->assertEquals($res, $expected, "Cancelled already cancelled leave ");
  342. $res = $this->classLeave->retrieveLeaveEmployee("011");
  343. $expected[0] = array(date('Y-m-d', time()+3600*24), 'Medical', 0, 1, '');
  344. $expected[1] = array(date('Y-m-d', time()+3600*24*1), 'Medical', 0, 1, '');
  345. $this->assertNotNull($res, "No record found ");
  346. for ($i=0; $i < count($res); $i++) {
  347. $this->assertEquals($res[0]->getLeaveDate(), $expected[$i][0], "Didn't return expected result ");
  348. $this->assertEquals($res[0]->getLeaveStatus(), $expected[$i][2], "Didn't return expected status ");
  349. $this->assertEquals($res[0]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result ");
  350. $this->assertEquals($res[0]->getLeaveComments(), $expected[$i][4], "Didn't return expected result ");
  351. }
  352. }
  353. public function testCountLeave() {
  354. $this->classLeave->setEmployeeId("013");
  355. $res = $this->classLeave->countLeave( "LTY010", date('Y', time()+3600*24));
  356. $this->assertEquals($res, 3, "Retruned wrong count");
  357. }
  358. public function testGetLeaveYears() {
  359. $res = $this->classLeave->getLeaveYears();
  360. $this->assertNotNull($res, "No years returned");
  361. $this->assertEquals(count($res), 2, "Retruned wrong number of records");
  362. $expected = array(date('Y')+1, date('Y'));
  363. $this->assertEquals($res, $expected, "Retruned wrong count");
  364. }
  365. public function testTakeLeaveAccuracy() {
  366. $res = $this->classLeave->retrieveLeaveEmployee("014");
  367. $this->assertNotNull($res, "Exsistent record not found ");
  368. $expected[0] = array(date('Y-m-d', time()), 'Medical', 2, 8, 'Leave 6');
  369. $this->assertNotNull($res, "No record found ");
  370. for ($i=0; $i < count($res); $i++) {
  371. $this->assertEquals($res[0]->getLeaveDate(), $expected[$i][0], "Didn't return expected result ");
  372. $this->assertEquals($res[0]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result ");
  373. $this->assertEquals($res[0]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result ");
  374. $this->assertEquals($res[0]->getLeaveComments(), $expected[$i][4], "Didn't return expected result ");
  375. }
  376. $res = $this->classLeave->takeLeave();
  377. $this->assertNotNull($res, "Unexpected behavior ");
  378. $res = $this->classLeave->retrieveLeaveEmployee("014");
  379. $this->assertNotNull($res, "Exsistent record not found2 ");
  380. $expected[0] = array(date('Y-m-d', time()), 'Medical', 3, 8, 'Leave 6');
  381. $this->assertNotNull($res, "No record found ");
  382. for ($i=0; $i < count($res); $i++) {
  383. $this->assertEquals($res[0]->getLeaveDate(), $expected[$i][0], "Didn't return expected result ");
  384. $this->assertEquals($res[0]->getLeaveStatus(), $expected[$i][2], "Didn't return expected result ");
  385. $this->assertEquals($res[0]->getLeaveLengthHours(), $expected[$i][3], "Didn't return expected result ");
  386. $this->assertEquals($res[0]->getLeaveComments(), $expected[$i][4], "Didn't return expected result ");
  387. }
  388. $res = $this->classLeave->takeLeave();
  389. $this->assertEquals($res, false, "Unexpected behavior ");
  390. }
  391. public function testStoreLeaveTaken() {
  392. $checkStoreTaken = new Leave();
  393. $checkStoreTaken->setLeaveLengthDays(10);
  394. $checkStoreTaken->setLeaveDate("2007-10-12");
  395. $checkStoreTaken->setLeaveTypeId("LTY012");
  396. $checkStoreTaken->setEmployeeId(18);
  397. $this->assertTrue($checkStoreTaken->storeLeaveTaken());
  398. }
  399. public function testIsLeaveTableEmpty() {
  400. $result = Leave::isLeaveTableEmpty();
  401. $this->assertFalse($result);
  402. }
  403. }
  404. // Call LeaveTest::main() if this source file is executed directly.
  405. if (PHPUnit_MAIN_METHOD == "LeaveTest::main") {
  406. LeaveTest::main();
  407. }
  408. ?>