PageRenderTime 170ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/models/leave/LeaveTypeTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 258 lines | 126 code | 85 blank | 47 comment | 4 complexity | f5022c08124206a7e38fa010e220a722 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 LeaveTypeTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "LeaveTypeTest::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 "LeaveType.php";
  29. require_once ROOT_PATH."/lib/confs/Conf.php";
  30. require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';
  31. /**
  32. * Test class for LeaveType.
  33. * Generated by PHPUnit_Util_Skeleton on 2006-10-18 at 10:36:24.
  34. */
  35. class LeaveTypeTest extends PHPUnit_Framework_TestCase {
  36. /**
  37. * Runs the test methods of this class.
  38. *
  39. * @access public
  40. * @static
  41. */
  42. public $classLeaveType = null;
  43. public $connection = null;
  44. public static function main() {
  45. require_once "PHPUnit/TextUI/TestRunner.php";
  46. $suite = new PHPUnit_Framework_TestSuite("LeaveTypeTest");
  47. $result = PHPUnit_TextUI_TestRunner::run($suite);
  48. }
  49. /**
  50. * Sets up the fixture, for example, open a network connection.
  51. * This method is called before a test is executed.
  52. *
  53. * @access protected
  54. */
  55. protected function setUp() {
  56. $this->classLeaveType = new LeaveType();
  57. $conf = new Conf();
  58. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  59. mysql_select_db($conf->dbname);
  60. mysql_query("TRUNCATE TABLE `hs_hr_leavetype`");
  61. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY011', 'Medical', 1)");
  62. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY012', 'Medicals', 1)");
  63. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY013', 'Medicalx', 1)");
  64. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY014', 'Casual', 1)");
  65. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY015', 'Casual', 1)");
  66. mysql_query("INSERT INTO `hs_hr_leavetype` VALUES ('LTY016', 'Casual', 1)");
  67. UniqueIDGenerator::getInstance()->initTable();
  68. }
  69. /**
  70. * Tears down the fixture, for example, close a network connection.
  71. * This method is called after a test is executed.
  72. *
  73. * @access protected
  74. */
  75. protected function tearDown() {
  76. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY011'", $this->connection);
  77. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY012'", $this->connection);
  78. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY013'", $this->connection);
  79. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY014'", $this->connection);
  80. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY015'", $this->connection);
  81. mysql_query("DELETE FROM `hs_hr_leavetype` WHERE `Leave_Type_ID` = 'LTY016'", $this->connection);
  82. }
  83. public function testAddLeaveType() {
  84. $this->classLeaveType->setLeaveTypeName("Anual");
  85. $res = $this->classLeaveType->addLeaveType();
  86. $id = $this->classLeaveType->getLeaveTypeId();
  87. $res = $this->classLeaveType->retriveLeaveType($id);
  88. $this->assertNotNull($res);
  89. $expected = array($id, 'Anual');
  90. $this->assertEquals($res[0]->getLeaveTypeId(), $expected[0], "Didn't return expected result 1");
  91. $this->assertEquals($res[0]->getLeaveTypeName(), $expected[1], "Didn't return expected result 2");
  92. $this->assertEquals(count($res), 1, "Number of records found is not accurate ");
  93. }
  94. public function testRetriveLeaveType() {
  95. $res = $this->classLeaveType->retriveLeaveType("LTY017");
  96. $this->assertEquals($res, null, "Retured non exsistant record ");
  97. }
  98. public function testRetriveLeaveAccuracy() {
  99. $res = $this->classLeaveType->retriveLeaveType("LTY011");
  100. $expected[0] = array('Anual', 'LTY011');
  101. $this->assertNotNull($res, "No record found ");
  102. }
  103. public function testEditLeavetype () {
  104. $this->classLeaveType->setLeaveTypeName("New Medicals");
  105. $this->classLeaveType->setLeaveTypeId("LTY012");
  106. $res = $this->classLeaveType->editLeaveType();
  107. $res = $this->classLeaveType->retriveLeaveType("LTY012");
  108. $expected = array('LTY012', 'New Medicals');
  109. $this->assertEquals($res[0]->getLeaveTypeId(), $expected[0], "Didn't return expected result 1");
  110. $this->assertEquals($res[0]->getLeaveTypeName(), $expected[1], "Didn't return expected result 2");
  111. $this->assertNotNull($res, "No record found ");
  112. }
  113. public function testDeleteLeaveType () {
  114. $this ->classLeaveType->setLeaveTypeId("LTY012");
  115. $res = $this->classLeaveType->deleteLeaveType("LTY012");
  116. $res = $this->classLeaveType->retriveLeaveType("LTY012");
  117. $expected = array('LTY012', 'Medicals' , $res[0]->unAvailableStatusFlag);
  118. $this->assertEquals($res[0]->getLeaveTypeId(), $expected[0], "Didn't return expected result 1");
  119. $this->assertEquals($res[0]->getLeaveTypeName(), $expected[1], "Didn't return expected result 2");
  120. $this->assertNotNull($res, "No record found ");
  121. }
  122. public function testFetchLeave() {
  123. $res = $this->classLeaveType->fetchLeaveTypes();
  124. $this->assertNotNull($res, "No record found ");
  125. }
  126. public function testFetchLeaveAccuracy() {
  127. $res = $this->classLeaveType->fetchLeaveTypes();
  128. $expected[] = array("LTY014", "Casual");
  129. $expected[] = array("LTY015", "Casual");
  130. $expected[] = array("LTY016", "Casual");
  131. $expected[] = array("LTY011", "Medical");
  132. $expected[] = array("LTY012", "Medicals");
  133. $expected[] = array("LTY013", "Medicalx");
  134. for ($i=0; $i < count($res); $i++) {
  135. $this->assertEquals($expected[$i][0], $res[$i]->getLeaveTypeId(), "Didn't return expected result 1");
  136. $this->assertEquals($expected[$i][1], $res[$i]->getLeaveTypeName(), "Didn't return expected result 2");
  137. }
  138. }
  139. public function testGetLeaveTypeWithName() {
  140. // Undeleted leave types
  141. $typeList = $this->classLeaveType->getLeaveTypeWithName("Medical");
  142. $this->assertNotNull($typeList);
  143. $this->assertEquals(1, count($typeList));
  144. $type = $typeList[0];
  145. $this->assertEquals("LTY011", $type->getLeaveTypeId());
  146. $this->assertEquals(1, $type->getLeaveTypeAvailable());
  147. // Deleted leave types
  148. $this->assertTrue(mysql_query("UPDATE `hs_hr_leavetype` SET available_flag = 0 WHERE leave_type_id='LTY011'"));
  149. $typeList = $this->classLeaveType->getLeaveTypeWithName("Medical");
  150. $this->assertNull($typeList);
  151. $typeList = $this->classLeaveType->getLeaveTypeWithName("Medical", true);
  152. $this->assertNotNull($typeList);
  153. $this->assertEquals(1, count($typeList));
  154. $type = $typeList[0];
  155. $this->assertEquals("LTY011", $type->getLeaveTypeId());
  156. $this->assertEquals(0, $type->getLeaveTypeAvailable());
  157. // Unavailable leave type name
  158. $typeList = $this->classLeaveType->getLeaveTypeWithName("Annual");
  159. $this->assertNull($typeList);
  160. //Chek for same leave type error, checks if its returning only one record
  161. $typeList = $this->classLeaveType->getLeaveTypeWithName("Casual");
  162. $this->assertEquals(1, count($typeList));
  163. // test if the most recent levetype is selected
  164. $myres=mysql_query("SELECT * FROM `hs_hr_leavetype` WHERE `leave_type_name` = 'Casual' ORDER BY `leave_type_id` DESC LIMIT 0,1", $this->connection);
  165. $myarr=mysql_fetch_array($myres);
  166. $this->assertEquals('LTY016',$myarr[0]);
  167. }
  168. }
  169. // Call LeaveTypeTest::main() if this source file is executed directly.
  170. if (PHPUnit_MAIN_METHOD == "LeaveTypeTest::main") {
  171. LeaveTypeTest::main();
  172. }
  173. ?>