/** * Test case for sendApprovalToHiringManager(). */ public function testSendApprovalToHiringManager() { $jobApplication = $this->jobApplications[1]; $notifier = new RecruitmentMailNotifier(); $mockMailer = new MockMailer(); $notifier->setMailer($mockMailer); $event = JobApplicationEvent::getJobApplicationEvent(1); $event->setStatus(JobApplicationEvent::EVENT_APPROVE); $event->setNotes('Notes created for unit testing'); $event->setCreatedBy('USR113'); $event->save(); // Check successfull email $result = $notifier->sendApprovalToHiringManager($jobApplication, $event); $this->assertTrue($result); $to = $mockMailer->getTo(); $this->assertEquals(1, count($to)); $this->assertEquals('*****@*****.**', $to[0]); $subject = $this->_getTemplateFile(RecruitmentMailNotifier::SUBJECT_DIRECTOR_APPROVE); $body = $this->_getTemplateFile(RecruitmentMailNotifier::TEMPLATE_DIRECTOR_APPROVE); $search = array(RecruitmentMailNotifier::VARIABLE_JOB_TITLE, RecruitmentMailNotifier::VARIABLE_TO, RecruitmentMailNotifier::VARIABLE_APPLICANT_FIRSTNAME, RecruitmentMailNotifier::VARIABLE_APPLICANT_MIDDLENAME, RecruitmentMailNotifier::VARIABLE_APPLICANT_LASTNAME, RecruitmentMailNotifier::VARIABLE_APPLICANT_STREET1, RecruitmentMailNotifier::VARIABLE_APPLICANT_STREET2, RecruitmentMailNotifier::VARIABLE_APPLICANT_CITY, RecruitmentMailNotifier::VARIABLE_APPLICANT_PROVINCE, RecruitmentMailNotifier::VARIABLE_APPLICANT_ZIP, RecruitmentMailNotifier::VARIABLE_APPLICANT_COUNTRY, RecruitmentMailNotifier::VARIABLE_APPLICANT_PHONE, RecruitmentMailNotifier::VARIABLE_APPLICANT_MOBILE, RecruitmentMailNotifier::VARIABLE_APPLICANT_EMAIL, RecruitmentMailNotifier::VARIABLE_APPLICANT_QUALIFICATIONS, RecruitmentMailNotifier::VARIABLE_APPROVE_NOTES, RecruitmentMailNotifier::VARIABLE_FROM); $replace = array('Manager', 'Saman', $jobApplication->getFirstName(), $jobApplication->getMiddleName(), $jobApplication->getLastName(), $jobApplication->getStreet1(), $jobApplication->getStreet2(), $jobApplication->getCity(), $jobApplication->getProvince(), $jobApplication->getZip(), 'Sri Lanka', $jobApplication->getPhone(), $jobApplication->getMobile(), $jobApplication->getEmail(), $jobApplication->getQualifications(), $event->getNotes(), 'John Samuel'); $body = str_replace($search, $replace, $body); $subject = str_replace($search, $replace, $subject); $subject = str_replace(array("\r", "\n"), array("", ""), $subject); $this->assertEquals($subject, $mockMailer->getSubject()); $this->assertEquals($body, $mockMailer->getBodyText()); // without to email address - should fail $this->_runQuery("UPDATE hs_hr_employee SET emp_work_email=NULL where emp_number = 11"); $mockMailer = new MockMailer(); $notifier->setMailer($mockMailer); $result = $notifier->sendApprovalToHiringManager($jobApplication, $event); $this->assertFalse($result); }
private function _approve($event) { if ($this->authorizeObj->isAdmin() || $this->authorizeObj->isDirector() || $this->authorizeObj->isAcceptor()) { // TODO: Validate if Hiring manager or interview manager and in correct status $application = JobApplication::getJobApplication($event->getApplicationId()); $application->setStatus(JobApplication::STATUS_HIRED); try { $application->save(); $this->_saveApplicationEvent($event, JobApplicationEvent::EVENT_APPROVE); // Create employee in PIM $empId = $this->createEmployeeFromApplication($application); // Save new employee number in application for reference. $application->setEmpNumber($empId); $application->save(); // Send email informing approval to hiring manager $notifier = new RecruitmentMailNotifier(); $mailResult = $notifier->sendApprovalToHiringManager($application, $event); $message = 'UPDATE_SUCCESS'; } catch (Exception $e) { $message = 'UPDATE_FAILURE'; } $this->redirect($message, '?recruitcode=Application&action=List'); //$this->_viewApplicationList(); } else { $this->_notAuthorized(); } }