public function init()
 {
     if (!$this->job) {
         return false;
     }
     /* @var \Auth\Entity\Info $userInfo */
     $userInfo = $this->user->getInfo();
     $name = $userInfo->getDisplayName();
     if ('' == trim($name)) {
         $name = $userInfo->getEmail();
     }
     $variables = ['name' => $name, 'title' => $this->job->getTitle()];
     $this->setTo($this->user->getInfo()->getEmail(), $this->user->getInfo()->getDisplayName(false));
     $this->setVariables($variables);
     $subject = 'New application for your vacancy "%s"';
     if ($this->isTranslatorEnabled()) {
         $subject = $this->getTranslator()->translate($subject);
     }
     $this->setSubject(sprintf($subject, $this->job->getTitle()));
     /* @var \Applications\Entity\Settings $settings */
     $settings = $this->user->getSettings('Applications');
     $body = $settings->getMailAccessText();
     if ('' == $body) {
         $body = "Hello ##name##,\n\nThere is a new application for your vacancy:\n\"##title##\"\n\n";
         if ($this->isTranslatorEnabled()) {
             $body = $this->getTranslator()->translate($body);
         }
     }
     $this->setBody($body);
     return $this;
 }
Beispiel #2
0
 public function setUp()
 {
     switch ($this->getName(false)) {
         case 'testImplementsListenerAggregateInterface':
             $this->target = $this->getMockBuilder('\\Jobs\\Listener\\MailSender')->disableOriginalConstructor()->getMock();
             break;
         case 'testRequiresMailServiceAndOptionsInConstructorAndSetsInternalProperties':
         case 'testAttachsToAndDetachsFromJobEvents':
             $this->mailServiceMock = $this->getMockBuilder('\\Core\\Mail\\MailService')->disableOriginalConstructor()->getMock();
             $this->targetOptions = array('siteName' => 'TestConstructor', 'adminEmail' => 'test@constructor');
             $this->target = new MailSender($this->mailServiceMock, $this->targetOptions);
             break;
         default:
             $this->mailServiceMock = $this->getMockBuilder('\\Core\\Mail\\MailService')->disableOriginalConstructor()->getMock();
             $this->mailServiceMock->expects($this->atLeastOnce())->method('send')->with($this->callback(array($this, 'popMailMock')));
             $this->mailServiceMock->expects($this->any())->method('get')->with('htmltemplate')->will($this->returnCallback(array($this, 'pushMailMock')));
             $this->targetOptions = array('siteName' => 'Test', 'adminEmail' => 'test@admin');
             $this->target = new MailSender($this->mailServiceMock, $this->targetOptions);
             $user = new User();
             $user->getInfo()->setEmail('test@email');
             $user->getInfo()->setFirstName('TestFirstName');
             $user->getInfo()->setLastName('TestLastName');
             $job = new Job();
             $job->setUser($user);
             $job->setReference('testRef');
             $this->jobEvent = new JobEvent();
             $this->jobEvent->setJobEntity($job);
             $this->inspectMailsCount = 0;
     }
 }
 public function testReturnsErrorResultIfMailSendingFailed()
 {
     $email = '*****@*****.**';
     $this->setupMocks(true);
     $user = new User();
     $user->setId('testUserId');
     $user->setEmail($email);
     $user->getInfo()->setEmail($email);
     $message = 'Sending invitation mail failed.';
     $this->translatorMock->expects($this->once())->method('translate')->with($message)->will($this->returnArgument(0));
     $this->userRepositoryMock->expects($this->once())->method('findByEmail')->with($email, null)->willReturn($user);
     $this->userRepositoryMock->expects($this->never())->method('create');
     $this->userTokenGeneratorMock->expects($this->once())->method('generate')->with($user, 7)->willReturn('testToken');
     $this->mailerPluginMock->expects($this->once())->method('__invoke')->will($this->throwException(new \Exception()));
     $expected = array('ok' => false, 'message' => $message);
     $result = $this->target->process($email);
     $this->assertEquals($expected, $result);
 }
 /**
  * @testdox Creates a proper configured HTMLTemplate Mail.
  */
 public function testCreateService()
 {
     $user = new User();
     $user->setId('testUser');
     $user->setEmail('test@user');
     $options = array('token' => 'testToken', 'user' => $user, 'template' => 'testTemplate');
     $ownerOrg = new Organization();
     $ownerOrg->setId('ownerOrg');
     $ownerOrgName = new OrganizationName('TestOwnerOrg');
     $ownerOrg->setOrganizationName($ownerOrgName);
     $userOrg = new Organization();
     $userOrg->setId('userOrg');
     $userOrgName = new OrganizationName('TestUserOrg');
     $userOrg->setOrganizationName($userOrgName);
     $orgRep = $this->getMockBuilder('\\Organizations\\Repository\\Organization')->disableOriginalConstructor()->getMock();
     $orgRep->expects($this->exactly(2))->method('findByUser')->withConsecutive(array('testOwner'), array('testUser'))->will($this->onConsecutiveCalls($ownerOrg, $userOrg));
     $ownerOrgRef = new OrganizationReference('testOwner', $orgRep);
     $userOrgRef = new OrganizationReference('testUser', $orgRep);
     $user->setOrganization($userOrgRef);
     $owner = new User();
     $owner->getInfo()->setFirstName('Test')->setLastName('Owner');
     $owner->setOrganization($ownerOrgRef);
     $authService = $this->getMockBuilder('\\Auth\\AuthenticationService')->disableOriginalConstructor()->getMock();
     $authService->expects($this->once())->method('getUser')->willReturn($owner);
     $router = $this->getMockForAbstractClass('\\Zend\\Mvc\\Router\\RouteStackInterface');
     $router->expects($this->once())->method('assemble')->with(array('action' => 'accept'), array('name' => 'lang/organizations/invite', 'query' => array('token' => $options['token'], 'organization' => $ownerOrg->getId())))->willReturn('testUrl');
     $services = $this->getMockBuilder('\\Zend\\ServiceManager\\ServiceManager')->disableOriginalConstructor()->getMock();
     $services->expects($this->exactly(2))->method('get')->withConsecutive(array('AuthenticationService'), array('Router'))->will($this->onConsecutiveCalls($authService, $router));
     $mailService = $this->getMockBuilder('\\Core\\Mail\\MailService')->disableOriginalConstructor()->getMock();
     $mailService->expects($this->once())->method('getServiceLocator')->willReturn($services);
     $mailMock = new HTMLTemplateMessage();
     $translator = $this->getMockBuilder('\\Zend\\I18n\\Translator\\Translator')->disableOriginalConstructor()->getMock();
     $translator->expects($this->any())->method('translate')->will($this->returnArgument(0));
     $mailMock->setTranslator($translator);
     $mailService->expects($this->once())->method('get')->with('htmltemplate')->willReturn($mailMock);
     $target = new EmployeeInvitationFactory();
     $target->setCreationOptions($options);
     $mail = $target->createService($mailService);
     $vars = $mail->getVariables()->getArrayCopy();
     $expected = array('inviter' => 'Test Owner', 'organization' => 'TestOwnerOrg', 'token' => $options['token'], 'user' => '', 'hasAssociation' => true, 'url' => 'testUrl', 'isOwner' => true, 'currentOrganization' => 'TestUserOrg', 'template' => 'testTemplate');
     $this->assertEquals($expected, $vars);
     $this->assertEquals($user->getEmail(), $mail->getTo()->current()->getEmail());
 }
Beispiel #5
0
 /**
  * @testdox Allows to set the role name of a user
  * @covers Auth\Entity\User::getInfo
  * @covers Auth\Entity\User::setInfo
  * @dataProvider provideInfoTestData
  */
 public function testSetGetInfo($info, $expectedInfo)
 {
     $this->target->setInfo($info);
     $this->assertEquals($expectedInfo, $this->target->getInfo());
 }