PageRenderTime 92ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/models/eimadmin/ProjectsTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 278 lines | 159 code | 74 blank | 45 comment | 5 complexity | 4eba41fe84a095ec9b4212a216d9fac8 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 ProjectTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "ProjectTest::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 ROOT_PATH."/lib/confs/Conf.php";
  29. require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';
  30. require_once 'Projects.php';
  31. /**
  32. * Test class for Project.
  33. * Generated by PHPUnit_Util_Skeleton on 2007-03-22 at 15:43:08.
  34. */
  35. class ProjectTest extends PHPUnit_Framework_TestCase {
  36. /**
  37. * Runs the test methods of this class.
  38. *
  39. * @access public
  40. * @static
  41. */
  42. public $classProject = null;
  43. public $connection = null;
  44. public static function main() {
  45. require_once "PHPUnit/TextUI/TestRunner.php";
  46. $suite = new PHPUnit_Framework_TestSuite("ProjectTest");
  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->classProject = new Projects();
  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_project`", $this->connection);
  61. mysql_query("INSERT INTO `hs_hr_customer` VALUES ('1001','zanfer1','forrw',0 )");
  62. mysql_query("INSERT INTO `hs_hr_customer` VALUES ('1002','zanfer2','forrw',0 )");
  63. mysql_query("INSERT INTO `hs_hr_customer` VALUES ('1003','zanfer3','forrw',0 )");
  64. mysql_query("INSERT INTO `hs_hr_project` VALUES ('1001','1001','p1','w',0 )");
  65. mysql_query("INSERT INTO `hs_hr_project` VALUES ('1002','1002','p2','w',0 )");
  66. mysql_query("INSERT INTO `hs_hr_project` VALUES ('1003','1003','p3','w',0 )");
  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("TRUNCATE TABLE `hs_hr_project`", $this->connection);
  77. mysql_query("DELETE FROM `hs_hr_customer` WHERE `customer_id` IN (1001, 1002, 1003);", $this->connection);
  78. UniqueIDGenerator::getInstance()->initTable();
  79. }
  80. public function testFetchProject() {
  81. $res = $this->classProject->fetchProject("1001");
  82. $this->assertNotNull($res, "No record found");
  83. $this->assertEquals($res->getProjectId(),'1001','Invalid project id');
  84. $this->assertEquals($res->getCustomerId(),'1001','Invalid customer id');
  85. $this->assertEquals($res->getProjectName(),'p1','Invalid description');
  86. $this->assertEquals($res->getProjectDescription(),'w','Invalid description');
  87. $this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
  88. }
  89. public function testAddProject() {
  90. $this->classProject->setCustomerId("1003");
  91. $this->classProject->setProjectName("Dodle");
  92. $this->classProject->setProjectDescription("jhgjhg");
  93. $res = $this->classProject->addProject();
  94. $id = $this->classProject->getProjectId();
  95. $this->assertTrue($res, "Adding failed");
  96. $res = $this->classProject->fetchProject($id);
  97. $this->assertNotNull($res, "No record found");
  98. $this->assertEquals($res->getProjectId(), $id,'Invalid project id');
  99. $this->assertEquals($res->getCustomerId(),'1003','Invalid customer id');
  100. $this->assertEquals($res->getProjectName(),'Dodle','Invalid description');
  101. $this->assertEquals($res->getProjectDescription(),'jhgjhg','Invalid description');
  102. $this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
  103. }
  104. public function testFetchProjects() {
  105. $res = $this->classProject->fetchProjects();
  106. $this->assertNotNull($res, "record Not found");
  107. $this->assertEquals(count($res), 3,'count incorrect');
  108. $expected[0] = array('1001', '1001', 'p1', 'w', Projects::PROJECT_NOT_DELETED);
  109. $expected[1] = array('1002', '1002', 'p2', 'w', Projects::PROJECT_NOT_DELETED);
  110. $expected[2] = array('1003', '1003', 'p3', 'w', Projects::PROJECT_NOT_DELETED);
  111. $i= 0;
  112. for ($i=0; $i<count($res); $i++) {
  113. $this->assertEquals($expected[$i][0], $res[$i]->getProjectId(), 'Wrong Project Request Id');
  114. $this->assertEquals($expected[$i][1], $res[$i]->getCustomerId(), 'Wrong Cus Id ');
  115. $this->assertEquals($expected[$i][2], $res[$i]->getProjectName(), 'Wrong Project Name ');
  116. $this->assertEquals($expected[$i][3], $res[$i]->getProjectDescription(),'Wrong Project Description ');
  117. $this->assertEquals($expected[$i][4], $res[$i]->getDeleted(),'Invalid description');
  118. }
  119. // Delete one project
  120. mysql_query("UPDATE `hs_hr_project` SET deleted = 1 WHERE project_id = 1001");
  121. // By default, all projects are returned
  122. $res = $this->classProject->fetchProjects();
  123. $this->assertNotNull($res, "record Not found");
  124. $this->assertEquals(count($res), 3,'count incorrect');
  125. // Fetch only NOT DELETED projects
  126. $res = $this->classProject->setDeleted(Projects::PROJECT_NOT_DELETED);
  127. $res = $this->classProject->fetchProjects();
  128. $this->assertNotNull($res, "record Not found");
  129. $this->assertEquals(count($res), 2,'count incorrect');
  130. }
  131. public function testGetListOfProjects() {
  132. $res = $this->classProject->fetchProjects();
  133. $this->assertNotNull($res, "record Not found");
  134. $this->assertEquals(count($res), 3,'count incorrect');
  135. $expected[0] = array('1001', '1001', 'p1', 'w', Projects::PROJECT_NOT_DELETED);
  136. $expected[1] = array('1002', '1002', 'p2', 'w', Projects::PROJECT_NOT_DELETED);
  137. $expected[2] = array('1003', '1003', 'p3', 'w', Projects::PROJECT_NOT_DELETED);
  138. $i= 0;
  139. for ($i=0; $i<count($res); $i++) {
  140. $this->assertEquals($expected[$i][0], $res[$i]->getProjectId(), 'Wrong Project Request Id');
  141. $this->assertEquals($expected[$i][1], $res[$i]->getCustomerId(), 'Wrong Cus Id ');
  142. $this->assertEquals($expected[$i][2], $res[$i]->getProjectName(), 'Wrong Project Name ');
  143. $this->assertEquals($expected[$i][3], $res[$i]->getProjectDescription(),'Wrong Project Description ');
  144. $this->assertEquals($expected[$i][4], $res[$i]->getDeleted(),'Invalid description');
  145. }
  146. }
  147. public function testUpdateProject() {
  148. $res = $this->classProject->fetchProject("1001");
  149. $res->setCustomerId('1002');
  150. $res = $res->updateProject();
  151. $this->assertTrue($res, "Adding failed");
  152. $res = $this->classProject->fetchProject("1001");
  153. $this->assertNotNull($res, "No record found");
  154. $this->assertEquals($res->getProjectId(),'1001','Invalid project id');
  155. $this->assertEquals($res->getCustomerId(),'1002','Invalid customer id');
  156. $this->assertEquals($res->getProjectName(),'p1','Invalid description');
  157. $this->assertEquals($res->getProjectDescription(),'w','Invalid description');
  158. $this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
  159. }
  160. public function testUpdateProject2() {
  161. $res = $this->classProject->fetchProject("1001");
  162. $res->setCustomerId('1002');
  163. $res->setProjectName('px');
  164. $res->setProjectDescription('ogg');
  165. $res = $res->updateProject();
  166. $this->assertTrue($res, "Adding failed");
  167. $res = $this->classProject->fetchProject("1001");
  168. $this->assertNotNull($res, "No record found");
  169. $this->assertEquals($res->getProjectId(),'1001','Invalid project id');
  170. $this->assertEquals($res->getCustomerId(),'1002','Invalid customer id');
  171. $this->assertEquals($res->getProjectName(),'px','Invalid description');
  172. $this->assertEquals($res->getProjectDescription(),'ogg','Invalid description');
  173. $this->assertEquals($res->getDeleted(), Projects::PROJECT_NOT_DELETED,'Invalid description');
  174. }
  175. public function testDeleteProject() {
  176. $this->classProject->setProjectId("1001");
  177. $res = $this->classProject->deleteProject();
  178. $this->assertTrue($res, "Adding failed");
  179. $res = $this->classProject->fetchProject("1001");
  180. $this->assertNotNull($res, "No record found");
  181. $this->assertEquals($res->getProjectId(),'1001','Invalid project id');
  182. $this->assertEquals($res->getCustomerId(),'1001','Invalid customer id');
  183. $this->assertEquals($res->getProjectName(),'p1','Invalid description');
  184. $this->assertEquals($res->getProjectDescription(),'w','Invalid description');
  185. $this->assertEquals($res->getDeleted(), Projects::PROJECT_DELETED,'Invalid description');
  186. }
  187. public function testRetrieveProjectName() {
  188. $actual = $this->classProject->retrieveProjectName(1001);
  189. $this->assertEquals('p1', $actual);
  190. $actual = $this->classProject->retrieveProjectName(1009);
  191. $this->assertEquals('', $actual);
  192. }
  193. public function testRetrieveCustomerName() {
  194. $actual = $this->classProject->retrieveCustomerName(1001);
  195. $this->assertEquals('zanfer1', $actual);
  196. $actual = $this->classProject->retrieveCustomerName(1009);
  197. $this->assertEquals('', $actual);
  198. }
  199. }
  200. // Call ProjectTest::main() if this source file is executed directly.
  201. if (PHPUnit_MAIN_METHOD == "ProjectTest::main") {
  202. ProjectTest::main();
  203. }
  204. ?>