orangehrm /lib/models/leave/HolidaysTest.php

Language PHP Lines 478
MD5 Hash d3d008cbcd8c3fb4f28c8796ca138750 Estimated Cost $7,765 (why?)
Repository https://bitbucket.org/wildanm/orangehrm View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?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 HolidaysTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "HolidaysTest::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 'Holidays.php';
require_once ROOT_PATH.'/lib/dao/DMLFunctions.php';
require_once ROOT_PATH."/lib/confs/Conf.php";
require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';

/**
 * Test class for Holidays.
 * Generated by PHPUnit_Util_Skeleton on 2006-12-29 at 13:24:41.
 */
class HolidaysTest extends PHPUnit_Framework_TestCase {
    public $classHoliday = 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("HolidaysTest");
        $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->classHoliday = new Holidays();

    	$conf = new Conf();

    	$this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
        mysql_select_db($conf->dbname);

    	mysql_query("TRUNCATE TABLE `hs_hr_holidays`", $this->connection);
    	mysql_query("INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (10, 'Independence', '".date('Y')."-07-04', ".Holidays::HOLIDAYS_RECURRING.", 8)");
    	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)");
        UniqueIDGenerator::getInstance()->initTable();

        mysql_query("INSERT INTO `hs_hr_employee`(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
                "VALUES (18, NULL, 'Nadeeth', 'H', 'Lansakara', 'rc')");
        mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");
        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')");
        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)");
        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)");
        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)");
        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)");
    }

    /**
     * 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("TRUNCATE TABLE `hs_hr_holidays`", $this->connection);
        mysql_query("TRUNCATE TABLE `hs_hr_leave`", $this->connection);
        mysql_query("TRUNCATE TABLE `hs_hr_employee`", $this->connection);
        mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`", $this->connection);
    }

    public function testIsHoliday1() {
    	$holiday = $this->classHoliday;
    	$expected[0] = array(date('Y').'-07-04', 8);
    	$expected[1] = array(date('Y').'-01-04', 4);

    	$res = $holiday->isHoliday($expected[0][0]);

        $this->assertNotNull($res, 'Unexpected behavior');
        $this->assertEquals($res, $expected[0][1], 'Invalid Length');

        $res = $holiday->isHoliday($expected[1][0]);

        $this->assertNotNull($res, 'Unexpected behavior');
        $this->assertEquals($res, $expected[1][1], 'Invalid Length');
    }

    public function testIsHoliday2() {

    	$holiday = $this->classHoliday;
    	$expected[0] = array((date('Y')+1).'-01-04', 4);

        $res = $holiday->isHoliday($expected[0][0]);

        $this->assertNull($res, 'Unexpected behavior');
    }

    public function testGetHolidayForDate() {
    	// exact day for recurring holiday
    	$holiday = Holidays::getHolidayForDate(date('Y').'-07-04');
    	$this->assertNotNull($holiday);
    	$this->assertEquals('Independence', $holiday->getDescription());
    	$this->assertEquals(10, $holiday->getHolidayId());
    	$this->assertEquals(date('Y').'-07-04', $holiday->getDate());
    	$this->assertEquals(Holidays::HOLIDAYS_RECURRING, $holiday->getRecurring());
    	$this->assertEquals(8, $holiday->getLength());

    	// next year for recurring holiday
    	$holiday = Holidays::getHolidayForDate((date('Y') + 1) .'-07-04', true);
		$this->assertNotNull($holiday);
    	$this->assertEquals('Independence', $holiday->getDescription());
    	$this->assertEquals(10, $holiday->getHolidayId());
    	$this->assertEquals(date('Y').'-07-04', $holiday->getDate());
    	$this->assertEquals(Holidays::HOLIDAYS_RECURRING, $holiday->getRecurring());
    	$this->assertEquals(8, $holiday->getLength());

    	// previous year for recurring holiday
    	$holiday = Holidays::getHolidayForDate((date('Y') - 1) .'-07-04', true);
		$this->assertNull($holiday);

    	// exact day for non-recurring holiday
    	$holiday = Holidays::getHolidayForDate(date('Y').'-01-04');
		$this->assertNotNull($holiday);
    	$this->assertEquals('Poya', $holiday->getDescription());
    	$this->assertEquals(11, $holiday->getHolidayId());
    	$this->assertEquals(date('Y').'-01-04', $holiday->getDate());
    	$this->assertEquals(Holidays::HOLIDAYS_NOT_RECURRING, $holiday->getRecurring());
    	$this->assertEquals(4, $holiday->getLength());

    	// next year for non-recurring holiday
    	$holiday = Holidays::getHolidayForDate((date('Y') + 1).'-01-04', true);
		$this->assertNull($holiday);

		// random non-holiday
    	$holiday = Holidays::getHolidayForDate((date('Y') + 1).'-03-04');
		$this->assertNull($holiday);

    	$holiday = Holidays::getHolidayForDate((date('Y') + 1).'-03-04', true);
		$this->assertNull($holiday);

    }

	/**
	 * Test that for a recurring holiday, the holiday is only considered from the starting date.
	 */
    public function testIsRecurringHolidayConsideredOnlyFromDefinedDate() {

    	$holiday = $this->classHoliday;

    	// check for holiday in year previous to year on which recurring holiday is defined.
        $res = $holiday->isHoliday((date('Y')-1).'-07-04');

        $this->assertNull($res, 'Recurring holiday should be only conidered from defined date.');

    	// check for holiday on year on which recurring holiday is defined.
        $res = $holiday->isHoliday(date('Y').'-07-04');
        $this->assertNotNull($res, 'Unexpected behavior');
        $this->assertEquals($res, 8, 'Invalid Length');

    	// check for holiday on year after year on which recurring holiday is defined.
        $res = $holiday->isHoliday((date('Y')+2).'-07-04');
        $this->assertNotNull($res, 'Unexpected behavior');
        $this->assertEquals($res, 8, 'Invalid Length');
    }

    public function testListHolidays1() {
    	$holiday = $this->classHoliday;

    	$res = $holiday->listHolidays();

    	$this->assertNotNull($res, 'Exsisting records not found');

    	$expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
    	$expected[1] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);

    	$this->assertEquals(count($res), count($expected), 'Invalid Number of records found ('.count($res).')');

    	for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}
    }

    public function testListHolidays2() {
    	$holiday = $this->classHoliday;

    	$res = $holiday->listHolidays(date('Y')+1);

    	$this->assertNotNull($res, 'Exsisting records not found');

    	$expected[0] = array(10, (date('Y')+1).'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);

    	$this->assertEquals(count($res), count($expected), 'Invalid Number of records found ('.count($res).')');

    	for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}
    }

	/**
	 * Unit test to check that a recurring holiday defined for a future year is not returned as a holiday
	 * in the current year.
	 *
	 * Eg: If this year is 2007 and a recurring holiday is defined on 2009-11-02,
	 * listHolidays should not return 2007-11-02 as a holiday.
	 */
    public function testListHolidaysRecurringDateNotBeforeDefinedDate() {
    	$holiday = $this->classHoliday;

		$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_holidays`", $this->connection), mysql_error());
    	$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());
    	$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());;
    	$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());;

    	$res = $holiday->listHolidays(date('Y'));

    	$this->assertNotNull($res, 'Existing records not found');

    	$expected[0] = array(15, (date('Y')).'-09-02', 'Recurring holiday in this year', Holidays::HOLIDAYS_RECURRING, 8);
    	$expected[1] = array(14, (date('Y')).'-10-02', 'Recurring holiday in the past', Holidays::HOLIDAYS_RECURRING, 8);
    	$expected[2] = array(13, (date('Y')+1).'-11-02', 'Recurring holiday in the future', Holidays::HOLIDAYS_RECURRING, 8);

    	$this->assertEquals(count($res), count($expected), 'Invalid Number of records found ('.count($res).')');

    	for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}
    }

    public function testFetchHoliday1() {
    	$holiday = $this->classHoliday;

    	$res = $holiday->fetchHoliday('97');

    	$this->assertNull($res, 'Non exsistent record found');
    }

    public function testFetchHoliday2() {
    	$holiday = $this->classHoliday;

    	$expected[0] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);

    	$res = $holiday->fetchHoliday($expected[0][0]);

    	$this->assertNotNull($res, 'Exsisting records not found');

    	$this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');

    	for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}
    }

    public function testAdd() {
        $holiday = $this->classHoliday;

        $expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
    	$expected[1] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);
        $expected[2] = array(12, date('Y').'-12-25', 'Christmas', Holidays::HOLIDAYS_RECURRING, 8);

        $holiday->setDescription($expected[2][2]);
        $holiday->setDate($expected[2][1]);
        $holiday->setRecurring($expected[2][3]);
        $holiday->setLength($expected[2][4]);

        $holiday->add();

		// Set the expected ID for newly added holiday
		$expected[2][0] = $holiday->getHolidayId();

        $res = $holiday->listHolidays();

    	$this->assertNotNull($res, 'Exsisting records not found');

    	$this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');

        for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}
    }

    public function testEdit() {
       	$holiday = $this->classHoliday;
        $expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
        $expected[1] = array(10, date('Y').'-05-01', 'May Day', Holidays::HOLIDAYS_RECURRING, 8);

        $holiday->setHolidayId($expected[1][0]);
        $holiday->setDescription($expected[1][2]);
        $holiday->setDate($expected[1][1]);
        $holiday->setRecurring($expected[1][3]);
        $holiday->setLength($expected[1][4]);

        $holiday->edit();

        $res = $holiday->listHolidays();

    	$this->assertNotNull($res, 'Exsisting records not found');

    	$this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');

        for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}

    }

    public function testDelete() {
    	$holiday = $this->classHoliday;

       	$expected[0] = array(11, date('Y').'-01-04', 'Poya', Holidays::HOLIDAYS_NOT_RECURRING, 4);
    	$expected[1] = array(10, date('Y').'-07-04', 'Independence', Holidays::HOLIDAYS_RECURRING, 8);

        $res = $holiday->listHolidays();

    	$this->assertNotNull($res, 'Exsisting records not found');

    	$this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');

        for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
    	}

        $holiday->setHolidayId($expected[0][0]);
        $holiday->delete();

        $res = $holiday->listHolidays();

    	$this->assertNotNull($res, 'Exsisting records not found');

    	array_shift($expected);

    	$this->assertEquals(count($res), count($expected), 'Invalid Nuber of records found');

       	for ($i=0; $i<count($expected); $i++) {
    		$this->assertEquals($res[$i]->getHolidayId(), $expected[$i][0], 'Invalid Hoiday Id');
    		$this->assertEquals($res[$i]->getDate(), $expected[$i][1], 'Invalid Date');
    		$this->assertEquals($res[$i]->getDescription(), $expected[$i][2], 'Invalid Description');
    		$this->assertEquals($res[$i]->getRecurring(), $expected[$i][3], 'Invalid Recurring Status');
    		$this->assertEquals($res[$i]->getLength(), $expected[$i][4], 'Invalid Length');
       	}
    }

    public function testUpdateHolidaysForLeavesOnCreate(){
        $dbConnection = new DMLFunctions();

        $date = date('Y-m-d', time()-3600*24*2);
        $date2 = date('Y-m-d', time()+3600*24*2);

        $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (12, 'National Day', '$date', 0, 8)";
        $result = $dbConnection -> executeQuery($query);
        $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (12, 'Pooya Day', '$date2', 0, 8)";
        $result = $dbConnection -> executeQuery($query);

        Holidays::updateHolidaysForLeavesOnCreate($date, '8');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 10 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(3, $row['leave_status'], 'Invalid status');

        Holidays::updateHolidaysForLeavesOnCreate($date2, '8');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 12 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(5, $row['leave_status'], 'Invalid status');
    }

    public function testUpdateHolidaysForLeavesOnUpdate(){
        $dbConnection = new DMLFunctions();

        $date = date('Y-m-d', time()-3600*24*2);
        $date2 = date('Y-m-d', time()+3600*24*2);

        $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (12, 'National Day', '$date', 0, 8)";
        $result = $dbConnection -> executeQuery($query);
        $query = "INSERT INTO `hs_hr_holidays` (`holiday_id`, `description`, `date`, `recurring`, `length`) VALUES (13, 'Pooya Day', '$date2', 0, 8)";
        $result = $dbConnection -> executeQuery($query);

        Holidays::updateHolidaysForLeavesOnUpdate($date, '8');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 10 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(5, $row['leave_status'], 'Invalid status');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 11 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(5, $row['leave_status'], 'Invalid status');

        Holidays::updateHolidaysForLeavesOnUpdate($date2, '8');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 12 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(5, $row['leave_status'], 'Invalid status');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 13 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(1, $row['leave_status'], 'Invalid status');
    }

    public function testUpdateHolidaysForLeavesOnDelete(){
        $dbConnection = new DMLFunctions();

        Holidays::updateHolidaysForLeavesOnDelete(date('Y-m-d', time()-3600*24*2), '8');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 11 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(5, $row['leave_status'], 'Invalid status');

        Holidays::updateHolidaysForLeavesOnDelete(date('Y-m-d', time()+3600*24*3), '8');
        $query = "SELECT leave_id, leave_status FROM hs_hr_leave WHERE leave_id = 13 ";
        $result = $dbConnection -> executeQuery($query);
        $row = $dbConnection->dbObject->getArray($result);
        $this->assertEquals(1, $row['leave_status'], 'Invalid status');
    }
}

// Call HolidaysTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "HolidaysTest::main") {
    HolidaysTest::main();
}
?>
Back to Top