예제 #1
0
 public function provideInjectOrganizationTestData()
 {
     $org = new Organization();
     $org->setId('alreadyHereOrg');
     $job = new Job();
     $job->setOrganization($org);
     return array(array(new \stdClass(), 'default'), array($job, 'default'), array(new Job(), 'one'), array(new Job(), 'more'));
 }
 public function setUp()
 {
     $name = $this->getName(false);
     $this->target = new AcceptInvitationHandler();
     if (false !== strpos($name, 'Exception')) {
         return;
     }
     $this->authMock = $this->getMockBuilder('\\Auth\\AuthenticationService')->disableOriginalConstructor()->getMock();
     $this->organizationRepositoryMock = $this->getMockBuilder('Organizations\\Repository\\Organization')->disableOriginalConstructor()->getMock();
     $this->userRepositoryMock = $this->getMockBuilder('\\Auth\\Repository\\User')->disableOriginalConstructor()->getMock();
     if (false !== strpos($this->getName(false), 'Setter')) {
         return;
     }
     $this->target->setAuthenticationService($this->authMock);
     $this->target->setOrganizationRepository($this->organizationRepositoryMock);
     if (false !== strpos($this->getName(false), 'OrganizationNotFound')) {
         return;
     }
     $this->organizationMock = $this->getMock('\\Organizations\\Entity\\Organization');
     $this->organizationRepositoryMock->expects($this->once())->method('find')->with('testOrgId')->willReturn($this->organizationMock);
     $this->target->setUserRepository($this->userRepositoryMock);
     if (false !== strpos($this->getName(false), 'TokenIsInvalid')) {
         return;
     }
     $this->userMock = new User();
     $this->userMock->setId('testUserId');
     $employee = $this->getMock('\\Organizations\\Entity\\Employee');
     $employee->expects($this->once())->method('setStatus')->with(Employee::STATUS_ASSIGNED);
     $this->organizationMock->expects($this->once())->method('getEmployee')->with($this->userMock->getId())->willReturn($employee);
     $this->organizationMock->expects($this->any())->method('getId')->willReturn('testOrgId');
     $this->userRepositoryMock->expects($this->once())->method('findByToken')->with('testToken')->willReturn($this->userMock);
     $sameOrganization = new Organization();
     $sameOrganization->setId('testOrgId');
     $assignedEmp = $this->getMock('\\Organizations\\Entity\\Employee');
     $assignedEmp->expects($this->once())->method('isUnassigned')->with(true)->willReturn(false);
     $assignedEmp->expects($this->once())->method('setStatus')->with(Employee::STATUS_REJECTED);
     $assignedEmpOrganization = $this->getMock('\\Organizations\\Entity\\Organization');
     $assignedEmpOrganization->expects($this->once())->method('getId')->willReturn('otherId');
     $assignedEmpOrganization->expects($this->once())->method('getEmployee')->with($this->userMock->getId())->willReturn($assignedEmp);
     $unassignedEmp = $this->getMock('\\Organizations\\Entity\\Employee');
     $unassignedEmp->expects($this->once())->method('isUnassigned')->with(true)->willReturn(true);
     $unassignedEmp->expects($this->never())->method('setStatus');
     $unassignedEmpOrganization = $this->getMock('\\Organizations\\Entity\\Organization');
     $unassignedEmpOrganization->expects($this->once())->method('getId')->willReturn('otherId');
     $unassignedEmpOrganization->expects($this->once())->method('getEmployee')->with($this->userMock->getId())->willReturn($unassignedEmp);
     $this->organizationRepositoryMock->expects($this->once())->method('findPendingOrganizationsByEmployee')->with($this->userMock->getId())->willReturn(array($sameOrganization, $assignedEmpOrganization, $unassignedEmpOrganization));
     $storageMock = $this->getMockForAbstractClass('\\Zend\\Authentication\\Storage\\StorageInterface');
     $storageMock->expects($this->once())->method('write')->with($this->userMock->getId());
     $this->authMock->expects($this->once())->method('getStorage')->willReturn($storageMock);
 }
 /**
  * @param array $params
  *
  * @return Organization
  */
 public static function createEntityWithRandomData(array $params = array())
 {
     $params = static::createNewRelations($params);
     $withId = true;
     $entityId = bin2hex(substr(uniqid(), 1));
     // define here another variables
     extract($params);
     $organizationEntity = new Organization();
     // here set another variables
     if (!empty($organizationName)) {
         $organizationEntity->setOrganizationName($organizationName);
     }
     if ($withId) {
         $organizationEntity->setId($entityId);
     }
     return $organizationEntity;
 }
 /**
  * @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());
 }
 private function generateOrganizationEntity($id, $name, $city, $street, $number)
 {
     $org = new Organization();
     $name = new OrganizationName($name);
     $org->setOrganizationName($name);
     $org->setId($id);
     $orgContact = new OrganizationContact();
     $orgContact->setCity($city)->setStreet($street)->setHouseNumber($number);
     $org->setContact($orgContact);
     return $org;
 }
예제 #6
0
 public function testGetPermissionsResourceId()
 {
     $input = 1234;
     $this->target->setId($input);
     $this->assertSame($this->target->getPermissionsResourceId(), 'organization:' . $input);
 }