/** * @testdox Allows to set the role name of a user * @covers Auth\Entity\User::getEmail * @covers Auth\Entity\User::setEmail * @dataProvider provideEmailTestData */ public function testSetGetEmail($userEmail, $infoEmail, $expectedEmail) { $info = new Info(); $info->setEmail($infoEmail); $this->target->setInfo($info); $this->target->setEmail($userEmail); $this->assertEquals($expectedEmail, $this->target->getEmail()); }
/** * @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()); }
/** * @param array $params * * @return User */ public static function createEntityWithRandomData(array $params = array()) { $withId = true; $entityId = bin2hex(substr(uniqid(), 1)); $email = uniqid('email'); $login = uniqid('login'); $password = uniqid('password'); $role = User::ROLE_RECRUITER; extract($params); $userEntity = new User(); $userEntity->setEmail($email)->setLogin($login)->setPassword($password)->setRole($role); $infoEntity = new Info(); $infoEntity->setEmail($email); $userEntity->setInfo($infoEntity); if ($withId) { $userEntity->setId($entityId); } $organization = new OrganizationReferenceMock(); $userEntity->setOrganization($organization); return $userEntity; }
protected function createUser($role = User::ROLE_RECRUITER) { $email = '*****@*****.**'; $locator = $this->getApplicationServiceLocator(); /* @var DocumentManager $dm */ $dm = $locator->get('doctrine.documentmanager.odm_default'); $userRepo = $dm->getRepository('Auth\\Entity\\User'); $user = $userRepo->findOneBy(array('login' => $email)); if (empty($user)) { $user = new User(); $user->setEmail($email)->setLogin($email)->setRole($role)->setPassword($email); $infoEntity = new Info(); $infoEntity->setEmail($email); $user->setInfo($infoEntity); $dm->persist($user); } else { $user->setRole($role); } $dm->flush(); $this->activeUser = $user; return $user; }
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); }