orangehrm /lib/models/benefits/HspPayPeriodTest.php

Language PHP Lines 218
MD5 Hash db3dc70f0aa770b91f8186292819285b Estimated Cost $3,274 (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
<?php
// Call PayPeriodTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "PayPeriodTest::main");
}

require_once "PHPUnit/Framework/TestCase.php";
require_once "PHPUnit/Framework/TestSuite.php";

require_once "testConf.php";

require_once 'HspPayPeriod.php';

require_once ROOT_PATH."/lib/confs/Conf.php";
require_once ROOT_PATH."/lib/common/UniqueIDGenerator.php";

/**
 * Test class for HspPayPeriod.
 * Generated by PHPUnit_Util_Skeleton on 2007-10-14 at 23:17:10.
 */
class HspPayPeriodTest extends PHPUnit_Framework_TestCase {
    /**
     * 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("HspPayPeriodTest");
        $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() {
    	$conf = new Conf();
    	$this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
        mysql_select_db($conf->dbname);

		$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`", $this->connection));

        $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period (id, start_date, end_date, close_date, check_date, timesheet_aproval_due_date) " .
        			"VALUES(1, '".date('Y-m-d')."', '".date('Y-m-d', time()+3600*24)."', '".date('Y-m-d', time()+3600*24*2)."', '".date('Y-m-d', time()+3600*24*3)."', '".date('Y-m-d', time()+3600*24*4)."')"));

        // For testGetYears()
        $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period (id, start_date, end_date, close_date, check_date, timesheet_aproval_due_date) VALUES(45, '".(date('Y')+20)."-01-01', '".(date('Y')+20)."-01-15', '".(date('Y')+20)."-01-15', '".(date('Y')+20)."-01-16', '".(date('Y')+20)."-01-17')"));

    	UniqueIDGenerator::getInstance()->resetIDs();
    }

    /**
     * Tears down the fixture, for example, close a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown() {
    	$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`", $this->connection));

    	UniqueIDGenerator::getInstance()->resetIDs();
    }

    public function testCountPayPeriods() {
    	$payPeriodsCount = HspPayPeriod::countPayPeriods(date('Y', time()-3600*24*750));

    	$this->assertEquals(0, $payPeriodsCount);
    }

    public function testCountPayPeriods1() {
    	$payPeriodsCount = HspPayPeriod::countPayPeriods(date('Y'));

    	$this->assertEquals(1, $payPeriodsCount);
    }

    public function testCountPayPeriods2() {
    	$payPeriodsCount = HspPayPeriod::countPayPeriods(date('Y'), true);

    	$this->assertEquals(1, $payPeriodsCount);
    }


    public function testListPayPeriods() {
		$payPeriods = HspPayPeriod::listPayPeriods(date('Y', time()-3600*24*750));

		$this->assertTrue(is_array($payPeriods));
		$this->assertEquals(0, count($payPeriods));
    }

    public function testListPayPeriods1() {
    	$expected[0] = array(1, date('Y-m-d'), date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2), date('Y-m-d', time()+3600*24*3), date('Y-m-d', time()+3600*24*4));
    	//$expected[1] = array(2, date('Y-m-d', time()+3600*24*370), date('Y-m-d', time()+3600*24*371), date('Y-m-d', time()+3600*24*372), date('Y-m-d', time()+3600*24*373), date('Y-m-d', time()+3600*24*374));

		$payPeriods = HspPayPeriod::listPayPeriods(date('Y'));

		$this->assertTrue(is_array($payPeriods));
		$this->assertEquals(1, count($payPeriods));

		for ($i=0; $i<count($payPeriods); $i++) {
			$this->assertEquals($expected[$i][0], $payPeriods[$i]->getId());
			$this->assertEquals($expected[$i][1], $payPeriods[$i]->getStartDate());
			$this->assertEquals($expected[$i][2], $payPeriods[$i]->getEndDate());
			$this->assertEquals($expected[$i][3], $payPeriods[$i]->getCloseDate());
			$this->assertEquals($expected[$i][4], $payPeriods[$i]->getCheckDate());
			$this->assertEquals($expected[$i][5], $payPeriods[$i]->getTimesheetAprovalDueDate());
		}
    }

    public function testAdd() {
		$expected[0] = array(1, date('Y-m-d'), date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2), date('Y-m-d', time()+3600*24*3), date('Y-m-d', time()+3600*24*4));
		$expected[1] = array(2, date('Y-m-d', time()+3600*24*2), date('Y-m-d', time()+3600*24*3), date('Y-m-d', time()+3600*24*4), date('Y-m-d', time()+3600*24*5), date('Y-m-d', time()+3600*24*6));

		$payPeriod = new HspPayPeriod();
		$payPeriod->setStartDate($expected[1][1]);
		$payPeriod->setEndDate($expected[1][2]);
		$payPeriod->setCloseDate($expected[1][3]);
		$payPeriod->setCheckDate($expected[1][4]);
		$payPeriod->setTimesheetAprovalDueDate($expected[1][5]);

		$payPeriod->add();

		$payPeriods = HspPayPeriod::listPayPeriods(date('Y'));

		$this->assertTrue(is_array($payPeriods));
		//$this->assertEquals(2, count($payPeriods));

		for ($i=0; $i<count($payPeriods); $i++) {
			$this->assertEquals($expected[$i][0], $payPeriods[$i]->getId());
			$this->assertEquals($expected[$i][1], $payPeriods[$i]->getStartDate());
			$this->assertEquals($expected[$i][2], $payPeriods[$i]->getEndDate());
			$this->assertEquals($expected[$i][3], $payPeriods[$i]->getCloseDate());
			$this->assertEquals($expected[$i][4], $payPeriods[$i]->getCheckDate());
			$this->assertEquals($expected[$i][5], $payPeriods[$i]->getTimesheetAprovalDueDate());
		}
    }

    public function testUpdate() {
    	$expected[0] = array(1, date('Y-m-d'), date('Y-m-d', time()+3600*24), date('Y-m-d', time()+3600*24*2), date('Y-m-d', time()+3600*24*3), date('Y-m-d', time()+3600*24*5));

		$payPeriod = new HspPayPeriod();
		$payPeriod->setId($expected[0][0]);
		$payPeriod->setStartDate($expected[0][1]);
		$payPeriod->setEndDate($expected[0][2]);
		$payPeriod->setCloseDate($expected[0][3]);
		$payPeriod->setCheckDate($expected[0][4]);
		$payPeriod->setTimesheetAprovalDueDate($expected[0][5]);

		$payPeriod->update();

		$payPeriods = HspPayPeriod::listPayPeriods(date('Y'));

		$this->assertTrue(is_array($payPeriods));
		$this->assertEquals(1, count($payPeriods));

		for ($i=0; $i<count($payPeriods); $i++) {
			$this->assertEquals($expected[$i][0], $payPeriods[$i]->getId());
			$this->assertEquals($expected[$i][1], $payPeriods[$i]->getStartDate());
			$this->assertEquals($expected[$i][2], $payPeriods[$i]->getEndDate());
			$this->assertEquals($expected[$i][3], $payPeriods[$i]->getCloseDate());
			$this->assertEquals($expected[$i][4], $payPeriods[$i]->getCheckDate());
			$this->assertEquals($expected[$i][5], $payPeriods[$i]->getTimesheetAprovalDueDate());
		}
    }

    public function testDelete() {
		$payPeriod = new HspPayPeriod();
		$payPeriod->setId(1);

		$payPeriod->delete();

		$payPeriods = HspPayPeriod::listPayPeriods(date('Y'));

		$this->assertTrue(is_array($payPeriods));
		$this->assertEquals(0, count($payPeriods));
    }

    public function testGetYears() {

    	$years = HspPayPeriod::getYears();

		$expected = array(date('Y'), date('Y')+1, date('Y')+20);

    	$this->assertEquals($expected, $years);
    }

	public function testCountCheckDates() {
		
		$thisYear = date('Y');
		$previousYear = $thisYear - 1;

		$this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`"));

		$this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(1, '$previousYear-12-01', '$previousYear-12-31', '$previousYear-12-31', '$previousYear-12-25', '$previousYear-12-20')"));
		$this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(2, '$thisYear-01-01', '$thisYear-01-31', '$thisYear-01-31', '$thisYear-01-25', '$thisYear-01-20')"));
		$this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(3, '$thisYear-02-01', '$thisYear-02-29', '$thisYear-02-29', '$thisYear-02-25', '$thisYear-02-20')"));
		$this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(4, '$thisYear-03-01', '$thisYear-03-31', '$thisYear-03-31', '$thisYear-03-25', '$thisYear-03-20')"));

		$this->assertEquals(HspPayPeriod::countCheckDates("$thisYear-01-01", "$thisYear-04-01"), 3);
		$this->assertEquals(HspPayPeriod::countCheckDates("$previousYear-12-01", "$thisYear-04-01"), 3);
		$this->assertEquals(HspPayPeriod::countCheckDates("2005-12-01", "$thisYear-04-01"), 3);
		$this->assertEquals(HspPayPeriod::countCheckDates("$thisYear-01-25", "$thisYear-03-31"), 2);
		$this->assertEquals(HspPayPeriod::countCheckDates("$thisYear-03-31", "$thisYear-05-31"), 0);

    }

}

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