public function setupOrganizationName() { $this->orgName = new OrganizationName('Test'); $this->orgName->setRankingByCompany(11); $this->target->setOrganizationName($this->orgName); $this->assertEquals(12, $this->orgName->getRankingByCompany()); }
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 dataProvider() { $invalidRole = new GenericRole('test'); $validRole = new User(); $validRole->setId('testId'); $invalidResource = new GenericResource('test'); $validResourceWoPerms = new Organization(); $validResourceWPerms = new Organization(); $validResourceWPerms->setUser($validRole); return [[$invalidRole, $invalidResource, 'invalidPrivilege', false], [$validRole, $invalidResource, 'invalid', false], [$invalidRole, $validResourceWoPerms, 'invalid', false], [$invalidRole, $validResourceWPerms, 'invalid', false], [$invalidRole, $invalidResource, 'edit', false], [$validRole, $invalidResource, 'edit', false], [$validRole, $validResourceWPerms, 'invalid', false], [$validRole, $validResourceWoPerms, 'edit', false], [$validRole, $validResourceWPerms, 'edit', true]]; }
private function setupOrganizationEntityRetrievalMocks($name) { $id = $name . "Id"; $organization = new Organization(); $organization->setOrganizationName(new OrganizationName($name)); $this->queryParams['organization'] = $id; $organizations = $this->getMockBuilder('\\Organizations\\Repository\\Organization')->disableOriginalConstructor()->getMock(); $organizations->expects($this->once())->method('find')->with($id)->willReturn($organization); $repositories = $this->getMockBuilder('\\Core\\Repository\\RepositoryService')->disableOriginalConstructor()->getMock(); $repositories->expects($this->once())->method('get')->with('Organizations')->willReturn($organizations); $services = $this->getMockBuilder('\\Zend\\ServiceManager\\ServiceManager')->disableOriginalConstructor()->getMock(); $services->expects($this->once())->method('get')->with('repositories')->willReturn($repositories); $this->target->setServiceLocator($services); }
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); }
public function testFindActiveOrganizations() { /* @var Cursor $orgs */ $orgs = $this->repository->findActiveOrganizations(); $this->assertCount(1, $orgs); $this->assertEquals($this->organization->getName(), $orgs->getNext()->getName()); }
/** * @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; }
public function testSetGetPermissions() { $permissions = new Permissions(PermissionsInterface::PERMISSION_CHANGE); $this->target->setPermissions($permissions); $this->assertSame($this->target->getPermissions(), $permissions); }
public function testSetGetCompanyWithOrganization() { $input1 = "Company ABC"; $input2 = "Another Company"; $this->target->setCompany($input1); $organization = new Organization(); $organizationName = new OrganizationName(); $organizationName->setName($input2); $organization->setOrganizationName($organizationName); $this->target->setOrganization($organization); $this->assertEquals($this->target->getCompany(), $input2); }
/** * prepare organizations for display * * * @access public * @param array $organizationsArray * @return array organizations prepared for display */ public function prepareForDisplay($organizationsArray) { $OSArray = OrganizationEntity::getOSs(); $langsArray = OrganizationEntity::getStaticLangs(); $officeVersionsArray = OrganizationEntity::getOfficeVersions(); foreach ($organizationsArray as $organization) { switch ($organization->type) { case OrganizationEntity::TYPE_ATC: $organization->typeText = "ATC"; break; case OrganizationEntity::TYPE_ATP: $organization->typeText = "ATP"; break; case OrganizationEntity::TYPE_BOTH: $organization->typeText = "ATC/ATP"; break; } if (array_key_exists($organization->officeLang, $langsArray)) { $organization->officeLangText = $langsArray[$organization->officeLang]; } if (array_key_exists($organization->operatingSystemLang, $langsArray)) { $organization->operatingSystemLangText = $langsArray[$organization->operatingSystemLang]; } if (array_key_exists($organization->officeVersion, $officeVersionsArray)) { $organization->officeVersionText = $officeVersionsArray[$organization->officeVersion]; } if (array_key_exists($organization->operatingSystem, $OSArray)) { $organization->operatingSystemText = $OSArray[$organization->operatingSystem]; } } return $organizationsArray; }
public function testUserIsEmployeeWithJobsChangePermissions() { $userId = 1234; $user = new User(); $user->setId($userId); $organization = new Organization(); $permissionsMock = $this->getMockBuilder('Core\\Entity\\Permissions')->setMethods(['isGranted', 'isAllowed'])->getMock(); $permissionsMock->expects($this->once())->method('isGranted')->willReturn(false); $permissionsMock->expects($this->once())->method('isAllowed')->with(EmployeePermissionsInterface::JOBS_CHANGE)->willReturn(true); $employeeMock = $this->getMockBuilder('Organizations\\Entity\\Employee')->setMethods(['getPermissions', 'getUser'])->getMock(); $employeeMock->expects($this->once())->method('getPermissions')->willReturn($permissionsMock); $employeeMock->expects($this->once())->method('getUser')->willReturn($user); $employees = new ArrayCollection(); $employees->add($employeeMock); $organization->setEmployees($employees); $jobMock = $this->getMockBuilder('Jobs\\Entity\\Job')->setMethods(['getPermissions', 'getOrganization'])->getMock(); $jobMock->expects($this->once())->method('getPermissions')->willReturn($permissionsMock); $jobMock->expects($this->once())->method('getOrganization')->willReturn($organization); $this->assertTrue($this->target->assert(new Acl(), $user, $jobMock, 'edit')); }
/** * more details of an ATC * * * @access public * * @return ViewModel */ public function editAction() { $variables = array(); $id = $this->params('id'); $query = $this->getServiceLocator()->get('wrapperQuery'); $orgsQuery = $this->getServiceLocator()->get('wrapperQuery')->setEntity('Organizations\\Entity\\Organization'); $orgObj = $query->find('Organizations\\Entity\\Organization', $id); $orgModel = $this->getServiceLocator()->get('Organizations\\Model\\Organization'); $rolesArray = $orgModel->getRequiredRoles($orgObj->getType()); $validationResult = $this->getServiceLocator()->get('aclValidator')->validateOrganizationAccessControl($this->getResponse(), $rolesArray, $orgObj); if ($validationResult["isValid"] === false && !empty($validationResult["redirectUrl"])) { return $this->redirect()->toUrl($validationResult["redirectUrl"]); } // for checking on attachments $crAttachment = $orgObj->CRAttachment; $atcLicenseAttachment = $orgObj->atcLicenseAttachment; $atpLicenseAttachment = $orgObj->atpLicenseAttachment; $oldStatus = $orgObj->getStatus(); $auth = new AuthenticationService(); $storage = $auth->getIdentity(); $isAdminUser = false; if ($auth->hasIdentity()) { if (in_array(Role::ADMIN_ROLE, $storage['roles'])) { $isAdminUser = true; } } // allow access for admins for all users // restrict access for current user only for non-admin users $options = array(); $options['query'] = $query; $options['staticLangs'] = OrgEntity::getStaticLangs(); $options['staticOss'] = OrgEntity::getOSs(); $options['staticOfficeVersions'] = OrgEntity::getOfficeVersions(); $atcSkippedParams = $this->getServiceLocator()->get('Config')['atcSkippedParams']; $atpSkippedParams = $this->getServiceLocator()->get('Config')['atpSkippedParams']; $form = new orgForm(null, $options); $form->bind($orgObj); $request = $this->getRequest(); if ($request->isPost()) { // Make certain to merge the files info! // $fileData = $request->getFiles()->toArray(); $fileData = $request->getFiles()->toArray(); $data = array_merge_recursive($request->getPost()->toArray(), $fileData); $form->setInputFilter($orgObj->getInputFilter($orgsQuery->setEntity("Organizations\\Entity\\Organization"))); $inputFilter = $form->getInputFilter(); $form->setData($data); // file not updated if (isset($fileData['CRAttachment']['name']) && empty($fileData['CRAttachment']['name'])) { // Change required flag to false for any previously uploaded files $input = $inputFilter->get('CRAttachment'); $input->setRequired(false); } if (isset($fileData['wireTransferAttachment']['name']) && empty($fileData['wireTransferAttachment']['name'])) { // Change required flag to false for any previously uploaded files $input = $inputFilter->get('wireTransferAttachment'); $input->setRequired(false); } if (isset($fileData['atcLicenseAttachment']['name']) && empty($fileData['atcLicenseAttachment']['name'])) { // Change required flag to false for any previously uploaded files $input = $inputFilter->get('atcLicenseAttachment'); $input->setRequired(false); } if (isset($fileData['atpLicenseAttachment']['name']) && empty($fileData['atpLicenseAttachment']['name'])) { // Change required flag to false for any previously uploaded files $input = $inputFilter->get('atpLicenseAttachment'); $input->setRequired(false); } switch ($data['type']) { case '1': array_push($atcSkippedParams, 'testCenterAdmin_id'); foreach ($atcSkippedParams as $param) { $inputFilter->get($param)->setRequired(false); $data[$param] = null; } break; case '2': array_push($atcSkippedParams, 'trainingManager_id'); foreach ($atpSkippedParams as $param) { $inputFilter->get($param)->setRequired(false); $data[$param] = null; } break; } if ($form->isValid()) { $orgModel->saveOrganization($data, $orgObj, $oldStatus, null, null, $isAdminUser); // redirecting if ($data['type'] == 1) { $url = $this->getEvent()->getRouter()->assemble(array('action' => 'atps'), array('name' => 'list_atc_orgs')); } else { if ($data['type'] == 2 || $data['type'] == 3) { $url = $this->getEvent()->getRouter()->assemble(array('action' => 'atcs'), array('name' => 'list_atp_orgs')); } } $this->redirect()->toUrl($url); } } $variables['wireTransferAttachment'] = $crAttachment; $variables['CRAttachment'] = $crAttachment; $variables['atpLicenseAttachment'] = $atpLicenseAttachment; $variables['atcLicenseAttachment'] = $atcLicenseAttachment; $variables['organizationForm'] = $this->getFormView($form); $organizationArray = array($orgObj); $versionModel = $this->getServiceLocator()->get('Versioning\\Model\\Version'); $organizationLogs = $versionModel->getLogEntriesPerEntities($organizationArray, array(), null, Status::STATUS_NOT_APPROVED); $hasPendingChanges = count($organizationLogs) > 0 ? true : false; $pendingUrl = $this->getEvent()->getRouter()->assemble(array('id' => $id), array('name' => 'organizationsPending')); $variables['messages'] = $versionModel->getPendingMessages($hasPendingChanges, $pendingUrl); return new ViewModel($variables); }
/** * Validate Access Control for actions * * @access private * @param Organizations\Entity\Organization $organization * @return bool is access valid or not */ private function validateAccessControl($organization) { $accessValid = true; $auth = new AuthenticationService(); $storage = $auth->getIdentity(); $query = $this->getServiceLocator()->get('wrapperQuery'); if ($auth->hasIdentity() && !in_array(Role::ADMIN_ROLE, $storage['roles'])) { $currentUserOrganizationUser = $query->findOneBy('Organizations\\Entity\\OrganizationUser', array("user" => $storage['id'], "organization" => $organization->getId())); if (!is_object($currentUserOrganizationUser) || !in_array(Role::TEST_CENTER_ADMIN_ROLE, $storage['roles']) && $organization->getType() == Organization::TYPE_ATC || !in_array(Role::TRAINING_MANAGER_ROLE, $storage['roles']) && $organization->getType() == Organization::TYPE_ATP) { $accessValid = false; } } return $accessValid; }