PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/leave/HolidaysTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 477 lines | 307 code | 108 blank | 62 comment | 11 complexity | d3d008cbcd8c3fb4f28c8796ca138750 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 HolidaysTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "HolidaysTest::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 'Holidays.php';
  30. require_once ROOT_PATH.'/lib/dao/DMLFunctions.php';
  31. require_once ROOT_PATH."/lib/confs/Conf.php";
  32. require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';
  33. /**
  34. * Test class for Holidays.
  35. * Generated by PHPUnit_Util_Skeleton on 2006-12-29 at 13:24:41.
  36. */
  37. class HolidaysTest extends PHPUnit_Framework_TestCase {
  38. public $classHoliday = null;
  39. public $connection = null;
  40. /**
  41. * Runs the test methods of this class.
  42. *
  43. * @access public
  44. * @static
  45. */
  46. public static function main() {
  47. require_once "PHPUnit/TextUI/TestRunner.php";
  48. $suite = new PHPUnit_Framework_TestSuite("HolidaysTest");
  49. $result = PHPUnit_TextUI_TestRunner::run($suite);
  50. }
  51. /**
  52. * Sets up the fixture, for example, open a network connection.
  53. * This method is called before a test is executed.
  54. *
  55. * @access protected
  56. */
  57. protected function setUp() {
  58. $this->classHoliday = new Holidays();
  59. $conf = new Conf();
  60. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  61. mysql_select_db($conf->dbname);
  62. mysql_query("TRUNCATE TABLE `hs_hr_holidays`", $this->connection);
  63. mysql_query("INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (10, 'Independence', '".date('Y')."-07-04', ".Holidays::HOLIDAYS_RECURRING.", 8)");
  64. mysql_query("INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (11, 'Poya', '".date('Y')."-01-04', ".Holidays::HOLIDAYS_NOT_RECURRING.", 4)");
  65. UniqueIDGenerator::getInstance()->initTable();
  66. mysql_query("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  67. "VALUES (18, NULL, 'Nadeeth', 'H', 'Lansakara', 'rc')");
  68. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");
  69. 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)."', '18')");
  70. 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, '18', 'LTY010', '".date('Y-m-d', time()-3600*24*2)."', 4, 0.5, 3, '', 11)");
  71. 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, '18', 'LTY010', '".date('Y-m-d', time()-3600*24*1)."', 8, 1, 5, '', 11)");
  72. 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, '18', 'LTY010', '".date('Y-m-d', time()+3600*24*2)."', 8, 1, 2, '', 11)");
  73. 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, '18', 'LTY010', '".date('Y-m-d', time()+3600*24*3)."', 8, 1, 5, '', 11)");
  74. }
  75. /**
  76. * Tears down the fixture, for example, close a network connection.
  77. * This method is called after a test is executed.
  78. *
  79. * @access protected
  80. */
  81. protected function tearDown() {
  82. mysql_query("TRUNCATE TABLE `hs_hr_holidays`", $this->connection);
  83. mysql_query("TRUNCATE TABLE `hs_hr_leave`", $this->connection);
  84. mysql_query("TRUNCATE TABLE `hs_hr_employee`", $this->connection);
  85. mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`", $this->connection);
  86. }
  87. public function testIsHoliday1() {
  88. $holiday = $this->classHoliday;
  89. $expected[0] = array(date('Y').'-07-04', 8);
  90. $expected[1] = array(date('Y').'-01-04', 4);
  91. $res = $holiday->isHoliday($expected[0][0]);
  92. $this->assertNotNull($res, 'Unexpected behavior');
  93. $this->assertEquals($res, $expected[0][1], 'Invalid Length');
  94. $res = $holiday->isHoliday($expected[1][0]);
  95. $this->assertNotNull($res, 'Unexpected behavior');
  96. $this->assertEquals($res, $expected[1][1], 'Invalid Length');
  97. }
  98. public function testIsHoliday2() {
  99. $holiday = $this->classHoliday;
  100. $expected[0] = array((date('Y')+1).'-01-04', 4);
  101. $res = $holiday->isHoliday($expected[0][0]);
  102. $this->assertNull($res, 'Unexpected behavior');
  103. }
  104. public function testGetHolidayForDate() {
  105. // exact day for recurring holiday
  106. $holiday = Holidays::getHolidayForDate(date('Y').'-07-04');
  107. $this->assertNotNull($holiday);
  108. $this->assertEquals('Independence', $holiday->getDescription());
  109. $this->assertEquals(10, $holiday->getHolidayId());
  110. $this->assertEquals(date('Y').'-07-04', $holiday->getDate());
  111. $this->assertEquals(Holidays::HOLIDAYS_RECURRING, $holiday->getRecurring());
  112. $this->assertEquals(8, $holiday->getLength());
  113. // next year for recurring holiday
  114. $holiday = Holidays::getHolidayForDate((date('Y') + 1) .'-07-04', true);
  115. $this->assertNotNull($holiday);
  116. $this->assertEquals('Independence', $holiday->getDescription());
  117. $this->assertEquals(10, $holiday->getHolidayId());
  118. $this->assertEquals(date('Y').'-07-04', $holiday->getDate());
  119. $this->assertEquals(Holidays::HOLIDAYS_RECURRING, $holiday->getRecurring());
  120. $this->assertEquals(8, $holiday->getLength());
  121. // previous year for recurring holiday
  122. $holiday = Holidays::getHolidayForDate((date('Y') - 1) .'-07-04', true);
  123. $this->assertNull($holiday);
  124. // exact day for non-recurring holiday
  125. $holiday = Holidays::getHolidayForDate(date('Y').'-01-04');
  126. $this->assertNotNull($holiday);
  127. $this->assertEquals('Poya', $holiday->getDescription());
  128. $this->assertEquals(11, $holiday->getHolidayId());
  129. $this->assertEquals(date('Y').'-01-04', $holiday->getDate());
  130. $this->assertEquals(Holidays::HOLIDAYS_NOT_RECURRING, $holiday->getRecurring());
  131. $this->assertEquals(4, $holiday->getLength());
  132. // next year for non-recurring holiday
  133. $holiday = Holidays::getHolidayForDate((date('Y') + 1).'-01-04', true);
  134. $this->assertNull($holiday);
  135. // random non-holiday
  136. $holiday = Holidays::getHolidayForDate((date('Y') + 1).'-03-04');
  137. $this->assertNull($holiday);
  138. $holiday = Holidays::getHolidayForDate((date('Y') + 1).'-03-04', true);
  139. $this->assertNull($holiday);
  140. }
  141. /**
  142. * Test that for a recurring holiday, the holiday is only considered from the starting date.
  143. */
  144. public function testIsRecurringHolidayConsideredOnlyFromDefinedDate() {
  145. $holiday = $this->classHoliday;
  146. // check for holiday in year previous to year on which recurring holiday is defined.
  147. $res = $holiday->isHoliday((date('Y')-1).'-07-04');
  148. $this->assertNull($res, 'Recurring holiday should be only conidered from defined date.');
  149. // check for holiday on year on which recurring holiday is defined.
  150. $res = $holiday->isHoliday(date('Y').'-07-04');
  151. $this->assertNotNull($res, 'Unexpected behavior');
  152. $this->assertEquals($res, 8, 'Invalid Length');
  153. // check for holiday on year after year on which recurring holiday is defined.
  154. $res = $holiday->isHoliday((date('Y')+2).'-07-04');
  155. $this->assertNotNull($res, 'Unexpected behavior');
  156. $this->assertEquals($res, 8, 'Invalid Length');
  157. }
  158. public function testListHolidays1() {
  159. $holiday = $this->classHoliday;
  160. $res = $holiday->listHolidays();
  161. $this->assertNotNull($res, 'Exsisting records not found');
  162. $expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
  163. $expected[1] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);
  164. $this->assertEquals(count($res), count($expected), 'Invalid Number of records found ('.count($res).')');
  165. for ($i=0; $i<count($expected); $i++) {
  166. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  167. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  168. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  169. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  170. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  171. }
  172. }
  173. public function testListHolidays2() {
  174. $holiday = $this->classHoliday;
  175. $res = $holiday->listHolidays(date('Y')+1);
  176. $this->assertNotNull($res, 'Exsisting records not found');
  177. $expected[0] = array(10, (date('Y')+1).'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);
  178. $this->assertEquals(count($res), count($expected), 'Invalid Number of records found ('.count($res).')');
  179. for ($i=0; $i<count($expected); $i++) {
  180. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  181. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  182. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  183. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  184. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  185. }
  186. }
  187. /**
  188. * Unit test to check that a recurring holiday defined for a future year is not returned as a holiday
  189. * in the current year.
  190. *
  191. * Eg: If this year is 2007 and a recurring holiday is defined on 2009-11-02,
  192. * listHolidays should not return 2007-11-02 as a holiday.
  193. */
  194. public function testListHolidaysRecurringDateNotBeforeDefinedDate() {
  195. $holiday = $this->classHoliday;
  196. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_holidays`", $this->connection), mysql_error());
  197. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (13, 'Recurring holiday in the future', '".(date('Y')+1) ."-11-02', ".Holidays::HOLIDAYS_RECURRING.", 8)"), mysql_error());
  198. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (14, 'Recurring holiday in the past', '".(date('Y')-1) ."-10-02', ".Holidays::HOLIDAYS_RECURRING.", 8)"), mysql_error());;
  199. $this->assertTrue(mysql_query("INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (15, 'Recurring holiday in this year', '".date('Y') ."-09-02', ".Holidays::HOLIDAYS_RECURRING.", 8)"), mysql_error());;
  200. $res = $holiday->listHolidays(date('Y'));
  201. $this->assertNotNull($res, 'Existing records not found');
  202. $expected[0] = array(15, (date('Y')).'-09-02', 'Recurring holiday in this year', Holidays::HOLIDAYS_RECURRING, 8);
  203. $expected[1] = array(14, (date('Y')).'-10-02', 'Recurring holiday in the past', Holidays::HOLIDAYS_RECURRING, 8);
  204. $expected[2] = array(13, (date('Y')+1).'-11-02', 'Recurring holiday in the future', Holidays::HOLIDAYS_RECURRING, 8);
  205. $this->assertEquals(count($res), count($expected), 'Invalid Number of records found ('.count($res).')');
  206. for ($i=0; $i<count($expected); $i++) {
  207. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  208. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  209. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  210. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  211. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  212. }
  213. }
  214. public function testFetchHoliday1() {
  215. $holiday = $this->classHoliday;
  216. $res = $holiday->fetchHoliday('97');
  217. $this->assertNull($res, 'Non exsistent record found');
  218. }
  219. public function testFetchHoliday2() {
  220. $holiday = $this->classHoliday;
  221. $expected[0] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);
  222. $res = $holiday->fetchHoliday($expected[0][0]);
  223. $this->assertNotNull($res, 'Exsisting records not found');
  224. $this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');
  225. for ($i=0; $i<count($expected); $i++) {
  226. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  227. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  228. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  229. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  230. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  231. }
  232. }
  233. public function testAdd() {
  234. $holiday = $this->classHoliday;
  235. $expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
  236. $expected[1] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);
  237. $expected[2] = array(12, date('Y').'-12-25', 'Christmas', Holidays::HOLIDAYS_RECURRING, 8);
  238. $holiday->setDescription($expected[2][2]);
  239. $holiday->setDate($expected[2][1]);
  240. $holiday->setRecurring($expected[2][3]);
  241. $holiday->setLength($expected[2][4]);
  242. $holiday->add();
  243. // Set the expected ID for newly added holiday
  244. $expected[2][0] = $holiday->getHolidayId();
  245. $res = $holiday->listHolidays();
  246. $this->assertNotNull($res, 'Exsisting records not found');
  247. $this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');
  248. for ($i=0; $i<count($expected); $i++) {
  249. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  250. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  251. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  252. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  253. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  254. }
  255. }
  256. public function testEdit() {
  257. $holiday = $this->classHoliday;
  258. $expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
  259. $expected[1] = array(10, date('Y').'-05-01', 'May Day', Holidays::HOLIDAYS_RECURRING, 8);
  260. $holiday->setHolidayId($expected[1][0]);
  261. $holiday->setDescription($expected[1][2]);
  262. $holiday->setDate($expected[1][1]);
  263. $holiday->setRecurring($expected[1][3]);
  264. $holiday->setLength($expected[1][4]);
  265. $holiday->edit();
  266. $res = $holiday->listHolidays();
  267. $this->assertNotNull($res, 'Exsisting records not found');
  268. $this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');
  269. for ($i=0; $i<count($expected); $i++) {
  270. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  271. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  272. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  273. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  274. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  275. }
  276. }
  277. public function testDelete() {
  278. $holiday = $this->classHoliday;
  279. $expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
  280. $expected[1] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);
  281. $res = $holiday->listHolidays();
  282. $this->assertNotNull($res, 'Exsisting records not found');
  283. $this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');
  284. for ($i=0; $i<count($expected); $i++) {
  285. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  286. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  287. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  288. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  289. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  290. }
  291. $holiday->setHolidayId($expected[0][0]);
  292. $holiday->delete();
  293. $res = $holiday->listHolidays();
  294. $this->assertNotNull($res, 'Exsisting records not found');
  295. array_shift($expected);
  296. $this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');
  297. for ($i=0; $i<count($expected); $i++) {
  298. $this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
  299. $this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
  300. $this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
  301. $this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
  302. $this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
  303. }
  304. }
  305. public function testUpdateHolidaysForLeavesOnCreate(){
  306. $dbConnection = new DMLFunctions();
  307. $date = date('Y-m-d', time()-3600*24*2);
  308. $date2 = date('Y-m-d', time()+3600*24*2);
  309. $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (12, 'National Day', '$date', 0, 8)";
  310. $result = $dbConnection -> executeQuery($query);
  311. $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (12, 'Pooya Day', '$date2', 0, 8)";
  312. $result = $dbConnection -> executeQuery($query);
  313. Holidays::updateHolidaysForLeavesOnCreate($date, '8');
  314. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 10 ";
  315. $result = $dbConnection -> executeQuery($query);
  316. $row = $dbConnection->dbObject->getArray($result);
  317. $this->assertEquals(3, $row['leave_status'], 'Invalid status');
  318. Holidays::updateHolidaysForLeavesOnCreate($date2, '8');
  319. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 12 ";
  320. $result = $dbConnection -> executeQuery($query);
  321. $row = $dbConnection->dbObject->getArray($result);
  322. $this->assertEquals(5, $row['leave_status'], 'Invalid status');
  323. }
  324. public function testUpdateHolidaysForLeavesOnUpdate(){
  325. $dbConnection = new DMLFunctions();
  326. $date = date('Y-m-d', time()-3600*24*2);
  327. $date2 = date('Y-m-d', time()+3600*24*2);
  328. $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (12, 'National Day', '$date', 0, 8)";
  329. $result = $dbConnection -> executeQuery($query);
  330. $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (13, 'Pooya Day', '$date2', 0, 8)";
  331. $result = $dbConnection -> executeQuery($query);
  332. Holidays::updateHolidaysForLeavesOnUpdate($date, '8');
  333. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 10 ";
  334. $result = $dbConnection -> executeQuery($query);
  335. $row = $dbConnection->dbObject->getArray($result);
  336. $this->assertEquals(5, $row['leave_status'], 'Invalid status');
  337. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 11 ";
  338. $result = $dbConnection -> executeQuery($query);
  339. $row = $dbConnection->dbObject->getArray($result);
  340. $this->assertEquals(5, $row['leave_status'], 'Invalid status');
  341. Holidays::updateHolidaysForLeavesOnUpdate($date2, '8');
  342. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 12 ";
  343. $result = $dbConnection -> executeQuery($query);
  344. $row = $dbConnection->dbObject->getArray($result);
  345. $this->assertEquals(5, $row['leave_status'], 'Invalid status');
  346. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 13 ";
  347. $result = $dbConnection -> executeQuery($query);
  348. $row = $dbConnection->dbObject->getArray($result);
  349. $this->assertEquals(1, $row['leave_status'], 'Invalid status');
  350. }
  351. public function testUpdateHolidaysForLeavesOnDelete(){
  352. $dbConnection = new DMLFunctions();
  353. Holidays::updateHolidaysForLeavesOnDelete(date('Y-m-d', time()-3600*24*2), '8');
  354. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 11 ";
  355. $result = $dbConnection -> executeQuery($query);
  356. $row = $dbConnection->dbObject->getArray($result);
  357. $this->assertEquals(5, $row['leave_status'], 'Invalid status');
  358. Holidays::updateHolidaysForLeavesOnDelete(date('Y-m-d', time()+3600*24*3), '8');
  359. $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 13 ";
  360. $result = $dbConnection -> executeQuery($query);
  361. $row = $dbConnection->dbObject->getArray($result);
  362. $this->assertEquals(1, $row['leave_status'], 'Invalid status');
  363. }
  364. }
  365. // Call HolidaysTest::main() if this source file is executed directly.
  366. if (PHPUnit_MAIN_METHOD == "HolidaysTest::main") {
  367. HolidaysTest::main();
  368. }
  369. ?>