PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/controllers/RecruitmentControllerTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 214 lines | 133 code | 32 blank | 49 comment | 3 complexity | bb3bd5dc6f9fbe0a985051d31ea2ddea 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 RecruitmentControllerTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "RecruitmentControllerTest::main");
  5. }
  6. require_once "PHPUnit/Framework/TestCase.php";
  7. require_once "PHPUnit/Framework/TestSuite.php";
  8. require_once 'testConf.php';
  9. require_once ROOT_PATH."/lib/confs/Conf.php";
  10. require_once ROOT_PATH."/lib/confs/sysConf.php";
  11. require_once ROOT_PATH."/lib/models/recruitment/JobApplication.php";
  12. require_once ROOT_PATH."/lib/common/UniqueIDGenerator.php";
  13. require_once ROOT_PATH."/lib/models/hrfunct/EmpInfo.php";
  14. require_once 'RecruitmentController.php';
  15. /**
  16. * Test class for RecruitmentController.
  17. * Generated by PHPUnit_Util_Skeleton on 2008-03-03 at 08:30:30.
  18. */
  19. class RecruitmentControllerTest extends PHPUnit_Framework_TestCase {
  20. /**
  21. * Runs the test methods of this class.
  22. *
  23. * @access public
  24. * @static
  25. */
  26. public static function main() {
  27. require_once "PHPUnit/TextUI/TestRunner.php";
  28. $suite = new PHPUnit_Framework_TestSuite("RecruitmentControllerTest");
  29. $result = PHPUnit_TextUI_TestRunner::run($suite);
  30. }
  31. /**
  32. * Sets up the fixture, for example, open a network connection.
  33. * This method is called before a test is executed.
  34. *
  35. * @access protected
  36. */
  37. protected function setUp() {
  38. $conf = new Conf();
  39. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  40. mysql_select_db($conf->dbname);
  41. $this->_deleteTables();
  42. // Insert job titles
  43. $this->_runQuery("INSERT INTO hs_hr_job_title(jobtit_code, jobtit_name, jobtit_desc, jobtit_comm, sal_grd_code) " .
  44. "VALUES('JOB001', 'Manager', 'Manager job title', 'no comments', null)");
  45. $this->_runQuery("INSERT INTO hs_hr_job_title(jobtit_code, jobtit_name, jobtit_desc, jobtit_comm, sal_grd_code) " .
  46. "VALUES('JOB002', 'Driver', 'Driver job title', 'no comments', null)");
  47. // Insert employees (managers)
  48. $this->_runQuery("INSERT INTO hs_hr_employee(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, job_title_code) " .
  49. "VALUES(11, '0011', 'Rajasinghe', 'Saman', 'Marlon', 'JOB001')");
  50. // Insert Job Vacancies
  51. $this->_runQuery("INSERT INTO hs_hr_job_vacancy(vacancy_id, jobtit_code, manager_id, active, description) " .
  52. "VALUES(1, 'JOB002', 11, " . JobVacancy::STATUS_ACTIVE . ", 'Job vacancy 1')");
  53. // Insert Job Applications
  54. $application = $this->_getJobApplication(1, 1, 'Janaka', 'T', 'Kulathunga', '111 Main Street', 'Apt X2',
  55. 'Colombo', 'Western', '2222', 'Sri Lanka', '01121111121', '077282828282', 'janaka@example.com',
  56. 'aaa bbb', JobApplication::STATUS_HIRED);
  57. $application->setHiringManagerName('Saman Rajasinghe');
  58. $application->setJobTitleName('Driver');
  59. $this->jobApplications[1] = $application;
  60. $this->_createJobApplications($this->jobApplications);
  61. UniqueIDGenerator::getInstance()->resetIDs();
  62. }
  63. /**
  64. * Tears down the fixture, for example, close a network connection.
  65. * This method is called after a test is executed.
  66. *
  67. * @access protected
  68. */
  69. protected function tearDown() {
  70. $this->_deleteTables();
  71. UniqueIDGenerator::getInstance()->resetIDs();
  72. }
  73. private function _deleteTables() {
  74. $this->_runQuery("DELETE FROM `hs_hr_users` WHERE id = 'USR111'");
  75. $this->_runQuery("TRUNCATE TABLE `hs_hr_job_application`");
  76. $this->_runQuery("TRUNCATE TABLE `hs_hr_job_vacancy`");
  77. $this->_runQuery("TRUNCATE TABLE `hs_hr_job_title`");
  78. $this->_runQuery("TRUNCATE TABLE `hs_hr_employee`");
  79. }
  80. /**
  81. * Test case for createEmployeeFromApplication
  82. */
  83. public function testCreateEmployeeFromApplication() {
  84. $jobApplication = JobApplication::getJobApplication(1);
  85. $empInfo = new EmpInfo();
  86. $before = $empInfo->countEmployee();
  87. $recController = new RecruitmentController();
  88. $empNum = $recController->createEmployeeFromApplication($jobApplication);
  89. $this->assertNotNull($empNum);
  90. // check employee count increased by 1
  91. $after = $empInfo->countEmployee();
  92. $this->assertEquals($before + 1, $after);
  93. // verify employee main details
  94. $empMain = $empInfo->filterEmpMain($empNum);
  95. $this->assertTrue(isset($empMain[0]));
  96. $this->assertEquals($empNum, $empMain[0][0]);
  97. $this->assertEquals($jobApplication->getLastName(), $empMain[0][1]);
  98. $this->assertEquals($jobApplication->getFirstName(), $empMain[0][2]);
  99. $this->assertEquals($jobApplication->getMiddleName(), $empMain[0][3]);
  100. // check that empId saved as well.
  101. $employeeId = str_pad($empNum, $empInfo->getEmployeeIdLength(), "0", STR_PAD_LEFT);
  102. $this->assertEquals($employeeId, $empMain[0][5]);
  103. // verify employee contact details
  104. $empContact = $empInfo->filterEmpContact($empNum);
  105. $this->assertTrue(isset($empContact[0]));
  106. $this->assertEquals($empNum, $empMain[0][0]);
  107. $this->assertEquals($jobApplication->getStreet1(), $empContact[0][1]);
  108. $this->assertEquals($jobApplication->getStreet2(), $empContact[0][2]);
  109. $this->assertEquals($jobApplication->getCity(), $empContact[0][3]);
  110. $this->assertEquals($jobApplication->getCountry(), $empContact[0][4]);
  111. $this->assertEquals($jobApplication->getProvince(), $empContact[0][5]);
  112. $this->assertEquals($jobApplication->getZip(), $empContact[0][6]);
  113. // Phone saved as home telephone
  114. $this->assertEquals($jobApplication->getPhone(), $empContact[0][7]);
  115. $this->assertEquals($jobApplication->getMobile(), $empContact[0][8]);
  116. // Email stored as other email.
  117. $this->assertEquals($jobApplication->getEmail(), $empContact[0][11]);
  118. // Job title
  119. $empJobInfo = $empInfo->filterEmpJobInfo($empNum);
  120. $this->assertTrue(isset($empJobInfo[0]));
  121. $this->assertEquals($empNum, $empJobInfo[0][0]);
  122. $vacancy = JobVacancy::getJobVacancy($jobApplication->getVacancyId());
  123. $this->assertEquals($vacancy->getJobTitleCode(), $empJobInfo[0][2]);
  124. }
  125. /**
  126. * Create a JobApplication object with the passed parameters
  127. */
  128. private function _getJobApplication($id, $vacancyId, $firstName, $middleName, $lastName, $street1, $street2,
  129. $city, $province, $zip, $country, $mobile, $phone, $email, $qualifications, $status = JobApplication::STATUS_SUBMITTED) {
  130. $application = new JobApplication($id);
  131. $application->setVacancyId($vacancyId);
  132. $application->setFirstName($firstName);
  133. $application->setMiddleName($middleName);
  134. $application->setLastName($lastName);
  135. $application->setStreet1($street1);
  136. $application->setStreet2($street2);
  137. $application->setCity($city);
  138. $application->setProvince($province);
  139. $application->setZip($zip);
  140. $application->setCountry($country);
  141. $application->setMobile($mobile);
  142. $application->setPhone($phone);
  143. $application->setEmail($email);
  144. $application->setQualifications($qualifications);
  145. $application->setStatus($status);
  146. $application->setAppliedDateTime(date(LocaleUtil::STANDARD_TIMESTAMP_FORMAT));
  147. return $application;
  148. }
  149. /**
  150. * Saves the given JobApplication objects in the database
  151. *
  152. * @param array $applications Array of JobApplication objects to save.
  153. */
  154. private function _createJobApplications($applications) {
  155. foreach ($applications as $application) {
  156. $sql = sprintf("INSERT INTO hs_hr_job_application(application_id, vacancy_id, firstname, middlename, ".
  157. "lastname, street1, street2, city, country_code, province, zip, " .
  158. "phone, mobile, email, qualifications, status, applied_datetime) " .
  159. "VALUES(%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s')",
  160. $application->getId(), $application->getVacancyId(), $application->getFirstName(),
  161. $application->getMiddleName(), $application->getLastName(), $application->getStreet1(),
  162. $application->getStreet2(), $application->getCity(), $application->getCountry(),
  163. $application->getProvince(), $application->getZip(), $application->getPhone(),
  164. $application->getMobile(), $application->getEmail(),
  165. $application->getQualifications(), $application->getStatus(),
  166. $application->getAppliedDateTime());
  167. $this->assertTrue(mysql_query($sql), mysql_error());
  168. }
  169. UniqueIDGenerator::getInstance()->initTable();
  170. }
  171. /**
  172. * Run given sql query, checking the return value
  173. */
  174. private function _runQuery($sql) {
  175. $this->assertTrue(mysql_query($sql), mysql_error());
  176. }
  177. }
  178. // Call RecruitmentControllerTest::main() if this source file is executed directly.
  179. if (PHPUnit_MAIN_METHOD == "RecruitmentControllerTest::main") {
  180. RecruitmentControllerTest::main();
  181. }
  182. ?>