/lib/models/benefits/HspPayPeriodTest.php
PHP | 217 lines | 136 code | 54 blank | 27 comment | 6 complexity | db3dc70f0aa770b91f8186292819285b 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
- <?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();
- }
- ?>