PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/models/benefits/HspPayPeriodTest.php

https://bitbucket.org/wildanm/orangehrm
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
  1. <?php
  2. // Call PayPeriodTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "PayPeriodTest::main");
  5. }
  6. require_once "PHPUnit/Framework/TestCase.php";
  7. require_once "PHPUnit/Framework/TestSuite.php";
  8. require_once "testConf.php";
  9. require_once 'HspPayPeriod.php';
  10. require_once ROOT_PATH."/lib/confs/Conf.php";
  11. require_once ROOT_PATH."/lib/common/UniqueIDGenerator.php";
  12. /**
  13. * Test class for HspPayPeriod.
  14. * Generated by PHPUnit_Util_Skeleton on 2007-10-14 at 23:17:10.
  15. */
  16. class HspPayPeriodTest extends PHPUnit_Framework_TestCase {
  17. /**
  18. * Runs the test methods of this class.
  19. *
  20. * @access public
  21. * @static
  22. */
  23. public static function main() {
  24. require_once "PHPUnit/TextUI/TestRunner.php";
  25. $suite = new PHPUnit_Framework_TestSuite("HspPayPeriodTest");
  26. $result = PHPUnit_TextUI_TestRunner::run($suite);
  27. }
  28. /**
  29. * Sets up the fixture, for example, open a network connection.
  30. * This method is called before a test is executed.
  31. *
  32. * @access protected
  33. */
  34. protected function setUp() {
  35. $conf = new Conf();
  36. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  37. mysql_select_db($conf->dbname);
  38. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`", $this->connection));
  39. $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period (id, start_date, end_date, close_date, check_date, timesheet_aproval_due_date) " .
  40. "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)."')"));
  41. // For testGetYears()
  42. $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')"));
  43. UniqueIDGenerator::getInstance()->resetIDs();
  44. }
  45. /**
  46. * Tears down the fixture, for example, close a network connection.
  47. * This method is called after a test is executed.
  48. *
  49. * @access protected
  50. */
  51. protected function tearDown() {
  52. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`", $this->connection));
  53. UniqueIDGenerator::getInstance()->resetIDs();
  54. }
  55. public function testCountPayPeriods() {
  56. $payPeriodsCount = HspPayPeriod::countPayPeriods(date('Y', time()-3600*24*750));
  57. $this->assertEquals(0, $payPeriodsCount);
  58. }
  59. public function testCountPayPeriods1() {
  60. $payPeriodsCount = HspPayPeriod::countPayPeriods(date('Y'));
  61. $this->assertEquals(1, $payPeriodsCount);
  62. }
  63. public function testCountPayPeriods2() {
  64. $payPeriodsCount = HspPayPeriod::countPayPeriods(date('Y'), true);
  65. $this->assertEquals(1, $payPeriodsCount);
  66. }
  67. public function testListPayPeriods() {
  68. $payPeriods = HspPayPeriod::listPayPeriods(date('Y', time()-3600*24*750));
  69. $this->assertTrue(is_array($payPeriods));
  70. $this->assertEquals(0, count($payPeriods));
  71. }
  72. public function testListPayPeriods1() {
  73. $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));
  74. //$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));
  75. $payPeriods = HspPayPeriod::listPayPeriods(date('Y'));
  76. $this->assertTrue(is_array($payPeriods));
  77. $this->assertEquals(1, count($payPeriods));
  78. for ($i=0; $i<count($payPeriods); $i++) {
  79. $this->assertEquals($expected[$i][0], $payPeriods[$i]->getId());
  80. $this->assertEquals($expected[$i][1], $payPeriods[$i]->getStartDate());
  81. $this->assertEquals($expected[$i][2], $payPeriods[$i]->getEndDate());
  82. $this->assertEquals($expected[$i][3], $payPeriods[$i]->getCloseDate());
  83. $this->assertEquals($expected[$i][4], $payPeriods[$i]->getCheckDate());
  84. $this->assertEquals($expected[$i][5], $payPeriods[$i]->getTimesheetAprovalDueDate());
  85. }
  86. }
  87. public function testAdd() {
  88. $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));
  89. $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));
  90. $payPeriod = new HspPayPeriod();
  91. $payPeriod->setStartDate($expected[1][1]);
  92. $payPeriod->setEndDate($expected[1][2]);
  93. $payPeriod->setCloseDate($expected[1][3]);
  94. $payPeriod->setCheckDate($expected[1][4]);
  95. $payPeriod->setTimesheetAprovalDueDate($expected[1][5]);
  96. $payPeriod->add();
  97. $payPeriods = HspPayPeriod::listPayPeriods(date('Y'));
  98. $this->assertTrue(is_array($payPeriods));
  99. //$this->assertEquals(2, count($payPeriods));
  100. for ($i=0; $i<count($payPeriods); $i++) {
  101. $this->assertEquals($expected[$i][0], $payPeriods[$i]->getId());
  102. $this->assertEquals($expected[$i][1], $payPeriods[$i]->getStartDate());
  103. $this->assertEquals($expected[$i][2], $payPeriods[$i]->getEndDate());
  104. $this->assertEquals($expected[$i][3], $payPeriods[$i]->getCloseDate());
  105. $this->assertEquals($expected[$i][4], $payPeriods[$i]->getCheckDate());
  106. $this->assertEquals($expected[$i][5], $payPeriods[$i]->getTimesheetAprovalDueDate());
  107. }
  108. }
  109. public function testUpdate() {
  110. $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));
  111. $payPeriod = new HspPayPeriod();
  112. $payPeriod->setId($expected[0][0]);
  113. $payPeriod->setStartDate($expected[0][1]);
  114. $payPeriod->setEndDate($expected[0][2]);
  115. $payPeriod->setCloseDate($expected[0][3]);
  116. $payPeriod->setCheckDate($expected[0][4]);
  117. $payPeriod->setTimesheetAprovalDueDate($expected[0][5]);
  118. $payPeriod->update();
  119. $payPeriods = HspPayPeriod::listPayPeriods(date('Y'));
  120. $this->assertTrue(is_array($payPeriods));
  121. $this->assertEquals(1, count($payPeriods));
  122. for ($i=0; $i<count($payPeriods); $i++) {
  123. $this->assertEquals($expected[$i][0], $payPeriods[$i]->getId());
  124. $this->assertEquals($expected[$i][1], $payPeriods[$i]->getStartDate());
  125. $this->assertEquals($expected[$i][2], $payPeriods[$i]->getEndDate());
  126. $this->assertEquals($expected[$i][3], $payPeriods[$i]->getCloseDate());
  127. $this->assertEquals($expected[$i][4], $payPeriods[$i]->getCheckDate());
  128. $this->assertEquals($expected[$i][5], $payPeriods[$i]->getTimesheetAprovalDueDate());
  129. }
  130. }
  131. public function testDelete() {
  132. $payPeriod = new HspPayPeriod();
  133. $payPeriod->setId(1);
  134. $payPeriod->delete();
  135. $payPeriods = HspPayPeriod::listPayPeriods(date('Y'));
  136. $this->assertTrue(is_array($payPeriods));
  137. $this->assertEquals(0, count($payPeriods));
  138. }
  139. public function testGetYears() {
  140. $years = HspPayPeriod::getYears();
  141. $expected = array(date('Y'), date('Y')+1, date('Y')+20);
  142. $this->assertEquals($expected, $years);
  143. }
  144. public function testCountCheckDates() {
  145. $thisYear = date('Y');
  146. $previousYear = $thisYear - 1;
  147. $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`"));
  148. $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')"));
  149. $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')"));
  150. $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')"));
  151. $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')"));
  152. $this->assertEquals(HspPayPeriod::countCheckDates("$thisYear-01-01", "$thisYear-04-01"), 3);
  153. $this->assertEquals(HspPayPeriod::countCheckDates("$previousYear-12-01", "$thisYear-04-01"), 3);
  154. $this->assertEquals(HspPayPeriod::countCheckDates("2005-12-01", "$thisYear-04-01"), 3);
  155. $this->assertEquals(HspPayPeriod::countCheckDates("$thisYear-01-25", "$thisYear-03-31"), 2);
  156. $this->assertEquals(HspPayPeriod::countCheckDates("$thisYear-03-31", "$thisYear-05-31"), 0);
  157. }
  158. }
  159. // Call HspPayPeriodTest::main() if this source file is executed directly.
  160. if (PHPUnit_MAIN_METHOD == "HspPayPeriodTest::main") {
  161. PayPeriodTest::main();
  162. }
  163. ?>