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

/lib/models/leave/LeaveSummaryTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 165 lines | 81 code | 36 blank | 48 comment | 4 complexity | b7cfa8617603f6b856a0463d9c00f8e1 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 LeaveSummaryTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "LeaveSummaryTest::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 "LeaveSummary.php";
  29. require_once ROOT_PATH."/lib/confs/Conf.php";
  30. /**
  31. * Test class for LeaveSummary.
  32. * Generated by PHPUnit_Util_Skeleton on 2006-10-19 at 13:16:38.
  33. */
  34. class LeaveSummaryTest extends PHPUnit_Framework_TestCase {
  35. /**
  36. * Runs the test methods of this class.
  37. *
  38. * @access public
  39. * @static
  40. */
  41. private $leaveSummary = null;
  42. private $connection = null;
  43. public static function main() {
  44. require_once "PHPUnit/TextUI/TestRunner.php";
  45. $suite = new PHPUnit_Framework_TestSuite("LeaveSummaryTest");
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. /**
  49. * Sets up the fixture, for example, open a network connection.
  50. * This method is called before a test is executed.
  51. *
  52. * @access protected
  53. */
  54. protected function setUp() {
  55. $this->leaveSummary = new LeaveSummary();
  56. $conf = new Conf();
  57. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  58. mysql_select_db($conf->dbname);
  59. $this->_deleteTestData();
  60. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_nick_name, coun_code) " .
  61. "VALUES ('011', 'Arnold', 'Subasinghe', 'Arnold', 'AF')");
  62. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  63. "VALUES ('012', 'Mohanjith', 'Sudirikku', 'Hannadige', 'MOHA')");
  64. $this->_runQuery("INSERT INTO `hs_hr_employee`(emp_number, emp_lastname, emp_firstname, emp_middle_name, emp_nick_name) " .
  65. "VALUES ('013', 'Rasmus', 'Vido', 'Q', 'Ras')");
  66. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY010', 'Medical', 1)");
  67. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY011', 'Casual', 1)");
  68. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY012', 'Annual', 0)");
  69. mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted, leave_taken) VALUES ('".date('Y')."', 'LTY010', '012', 10, 5);");
  70. mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted, leave_taken) VALUES ('".date('Y')."', 'LTY011', '012', 20, 30);");
  71. mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted) VALUES ('".date('Y')."', 'LTY012', '013', 30);");
  72. mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted) VALUES ('".date('Y')."', 'LTY010', '011', 10);");
  73. mysql_query("INSERT INTO `hs_hr_employee_leave_quota` (year, leave_type_id, employee_id, no_of_days_allotted) VALUES ('".date('Y')."', 'LTY011', '011', 20);");
  74. mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (10, 'LTY010', 'Medical', '".date('Y-m-d', time()+3600*24)."', '011')");
  75. mysql_query("INSERT INTO `hs_hr_leave_requests` (`leave_request_id`, `leave_type_id`, `leave_type_name`, `date_applied`, `employee_id`) VALUES (11, 'LTY012', 'Medical', '".date('Y-m-d', time()+3600*24)."', '013')");
  76. 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, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 8, 1, 3, 'Leave 1', 10)");
  77. 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, '011', 'LTY010', '".date('Y-m-d', time()+3600*24)."', 8, 1, 3, 'Leave 2', 10)");
  78. 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, '013', 'LTY012', '".date('Y-m-d', time()+3600*24)."', 8, 1, 3, 'Leave 3', 11)");
  79. }
  80. /**
  81. * Tears down the fixture, for example, close a network connection.
  82. * This method is called after a test is executed.
  83. *
  84. * @access protected
  85. */
  86. protected function tearDown() {
  87. $this->_deleteTestData();
  88. }
  89. /**
  90. * Deletes test data created during test
  91. */
  92. private function _deleteTestData() {
  93. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '011'", $this->connection);
  94. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '012'", $this->connection);
  95. mysql_query("DELETE FROM `hs_hr_employee` WHERE `emp_number` = '013'", $this->connection);
  96. mysql_query("DELETE FROM `hs_hr_employee_leave_quota` WHERE `Employee_ID` = '012'", $this->connection);
  97. mysql_query("DELETE FROM `hs_hr_employee_leave_quota` WHERE `Employee_ID` = '013'", $this->connection);
  98. mysql_query("DELETE FROM `hs_hr_employee_leave_quota` WHERE `Employee_ID` = '011'", $this->connection);
  99. mysql_query("TRUNCATE TABLE `hs_hr_leave`", $this->connection);
  100. mysql_query("TRUNCATE TABLE `hs_hr_leave_requests`", $this->connection);
  101. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY010'", $this->connection);
  102. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY011'", $this->connection);
  103. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY012'", $this->connection);
  104. }
  105. /**
  106. * Run given sql query
  107. */
  108. private function _runQuery($sql) {
  109. $this->assertTrue(mysql_query($sql), mysql_error());
  110. }
  111. public function testFetchAllEmployeeLeaveSummaryAccuracy() {
  112. $res = $this->leaveSummary->fetchAllEmployeeLeaveSummary("012", date('Y', time()+3600*24));
  113. $this->assertNotNull($res, "No records returned");
  114. $this->assertEquals(count($res), 2, "Returned invalid numner of records");
  115. $expected[] = array("Medical", 10, 5, 5);
  116. $expected[] = array("Casual", 20, 30, -10);
  117. for ($i=0; $i < count($res); $i++) {
  118. $this->assertEquals($res[$i]['leave_type_name'], $expected[$i][0], "Didn't return expected leave_type_name ");
  119. $this->assertEquals($res[$i]['no_of_days_allotted'], $expected[$i][1], "Didn't return expected no_of_days_allotted ");
  120. $this->assertEquals($res[$i]['leave_taken'], $expected[$i][2], "Didn't return expected leave_taken ");
  121. $this->assertEquals($res[$i]['leave_available'], $expected[$i][3], "Didn't return expected leave_available ");
  122. }
  123. }
  124. }
  125. // Call LeaveSummaryTest::main() if this source file is executed directly.
  126. if (PHPUnit_MAIN_METHOD == "LeaveSummaryTest::main") {
  127. LeaveSummaryTest::main();
  128. }
  129. ?>