public function setUp()
 {
     $this->target = new HiringOrganizationSelectFactory();
     if ("testImplementsFactoryInterface" == $this->getName(false)) {
         return;
     }
     $userOrg = $this->getMockBuilder('\\Organizations\\Entity\\OrganizationReference')->disableOriginalConstructor()->getMock();
     $user = new User();
     $user->setId('testUser');
     $user->setOrganization($userOrg);
     $this->user = $user;
     $auth = $this->getMockBuilder('Auth\\AuthenticationService')->disableOriginalConstructor()->getMock();
     $auth->expects($this->once())->method('getUser')->willReturn($user);
     $headscript = $this->getMockBuilder('\\Zend\\View\\Helper\\HeadScript')->disableOriginalConstructor()->getMock();
     $headscript->expects($this->once())->method('__call')->with('appendFile', array('Jobs/js/form.hiring-organization-select.js'));
     $basepath = $this->getMockBuilder('\\Zend\\View\\Helper\\BasePath')->disableOriginalConstructor()->getMock();
     $basepath->expects($this->once())->method('__invoke')->with('Jobs/js/form.hiring-organization-select.js')->will($this->returnArgument(0));
     $helper = $this->getMockBuilder('\\Zend\\View\\HelperPluginManager')->disableOriginalConstructor()->getMock();
     $helper->expects($this->exactly(2))->method('get')->withConsecutive(array('headscript'), array('basepath'))->will($this->onConsecutiveCalls($headscript, $basepath));
     $services = $this->getMockBuilder('\\Zend\\ServiceManager\\ServiceManager')->disableOriginalConstructor()->getMock();
     $services->expects($this->exactly(2))->method('get')->withConsecutive(array('AuthenticationService'), array('ViewHelperManager'))->will($this->onConsecutiveCalls($auth, $helper));
     $formElements = $this->getMockBuilder('\\Zend\\Form\\FormElementManager')->disableOriginalConstructor()->getMock();
     $formElements->expects($this->once())->method('getServiceLocator')->willReturn($services);
     $this->formElements = $formElements;
 }
Beispiel #2
0
 public function testSetGetUser()
 {
     $user = new User();
     $user->setId('test');
     $this->target->setUser($user);
     $this->assertEquals($this->target->getUser(), $user);
 }
 private function getTargetArgsForCreateQueryTest()
 {
     $user = new User();
     $user->setId('PqtUser');
     $auth = $this->getMockBuilder(AuthenticationService::class)->disableOriginalConstructor()->setMethods(['getUser'])->getMock();
     $auth->expects($this->any())->method('getUser')->willReturn($user);
     $this->authMock = $auth;
     return [$auth];
 }
 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]];
 }
Beispiel #5
0
 /**
  * Does getUser returns null, if value is not set or not UserInterface?
  * Does getUser reurns the User, if one is set?
  */
 public function testGetUser()
 {
     $target = new Employee();
     $user = new User();
     $user->setId('test1234');
     $this->assertNull($target->getUser());
     $target->setValue($user);
     $this->assertSame($user, $target->getUser());
     $target->setValue('test1234');
     $this->assertNull($target->getUser());
 }
 public function provideAssertTestData()
 {
     $role = new GenericRole('Test');
     $resource = new GenericResource('Test');
     $user = new User();
     $user->setId('testuser');
     $user2 = new User();
     $user2->setId('testuser2');
     $app = new Application();
     $app2 = new Application();
     $app2->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
     return array('nouser-noapp' => array($role, $resource, null, false), 'user-noapp' => array($user, $resource, null, false), 'user-app-no-perm' => array($role, $app, null, false), 'read-not-granted' => array($user, $app, 'read', false), 'change-not-granted' => array($user, $app, 'write', false), 'read-granted' => array($user2, $app2, 'read', true), 'change-granted' => array($user2, $app2, 'write', true), 'change-not-granted2' => array($user, $app2, 'change', false));
 }
 /**
  * post load hook must inject organization reference to UserInterface instances!
  */
 public function testPostLoadHookInjectsOrganizationReferenceIfDocumentIsUserInterface()
 {
     $target = new InjectOrganizationReferenceListener();
     $dm = $this->getMockBuilder('\\Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->getMock();
     $doc = new User();
     $rep = $this->getMockBuilder('\\Organizations\\Repository\\Organization')->disableOriginalConstructor()->getMock();
     $dm->expects($this->once())->method('getRepository')->with('Organizations\\Entity\\Organization')->willReturn($rep);
     $doc->setId('test1234');
     $args = new LifecycleEventArgs($doc, $dm);
     $result = $target->postLoad($args);
     $this->assertNull($result);
     $ref = $doc->getOrganization();
     $this->assertInstanceOf('\\Organizations\\Entity\\OrganizationReference', $ref);
     $this->assertAttributeSame($rep, '_repository', $ref);
     $this->assertAttributeEquals($doc->getId(), '_userId', $ref);
 }
 public function provideAssertTestData()
 {
     $role = new GenericRole('Test');
     $resource = new GenericResource('Test');
     $user = new User();
     $user->setId('testuser');
     $user2 = new User();
     $user2->setId('testuser2');
     $app = new Application();
     $app2 = new Application();
     $app2->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
     $app3 = new Application();
     $app3->setIsDraft(true);
     //$app3->setUser($user);
     $app3->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
     return array('nouser-noapp' => array($role, $resource, null, false), 'user-noapp' => array($user, $resource, null, false), 'user-app-no-perm' => array($role, $app, null, false), 'read-not-granted' => array($user, $app, 'read', false), 'change-not-granted' => array($user, $app, 'write', false), 'read-granted' => array($user2, $app2, 'read', true), 'change-granted' => array($user2, $app2, 'write', true), 'change-not-granted2' => array($user, $app2, 'change', false), 'subsequentAttachmentUpload-not-granted' => array($user, $app, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, false), 'subsequentAttachmentUpload-granted' => array($user, $app2, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, true), 'allow-draft-view' => [$user2, $app3, 'change', true], 'disallow-draft-view' => [$user, $app3, 'change', false]);
 }
 private function getTargetArgs()
 {
     switch ($this->getName(false)) {
         case 'testInheritance':
         case 'testDefaultPropertyValues':
             return [];
             break;
         case 'testConstructSetsUserProperty':
             $user = new User();
             break;
         default:
             $user = new User();
             $user->setId('testId');
             break;
     }
     $this->user = $user;
     return [$user];
 }
 public function setUp()
 {
     $this->target = new HiringOrganizationSelectFactory();
     if ("testImplementsFactoryInterface" == $this->getName(false)) {
         return;
     }
     $userOrg = $this->getMockBuilder('\\Organizations\\Entity\\OrganizationReference')->disableOriginalConstructor()->getMock();
     $user = new User();
     $user->setId('testUser');
     $user->setOrganization($userOrg);
     $this->user = $user;
     $auth = $this->getMockBuilder('Auth\\AuthenticationService')->disableOriginalConstructor()->getMock();
     $auth->expects($this->once())->method('getUser')->willReturn($user);
     $services = $this->getMockBuilder('\\Zend\\ServiceManager\\ServiceManager')->disableOriginalConstructor()->getMock();
     $services->expects($this->once())->method('get')->with('AuthenticationService')->willReturn($auth);
     $formElements = $this->getMockBuilder('\\Zend\\Form\\FormElementManager')->disableOriginalConstructor()->getMock();
     $formElements->expects($this->once())->method('getServiceLocator')->willReturn($services);
     $this->formElements = $formElements;
 }
 /**
  * @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 #12
0
 /**
  * @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;
 }
 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);
 }
 public function provideOrganizationInterfaceFunctionValues()
 {
     $hydrator = new EntityHydrator();
     $date = new \DateTime();
     $parent = new Organization();
     $name = new OrganizationName('noname');
     $emps = new ArrayCollection();
     $user = new User();
     $user->setId('543');
     $perms = new Permissions();
     $contact = new OrganizationContact();
     return array(array(array('__set', '__get', '__isset'), array(array('id', '4321'), array('id'), array('id')), array('__self__', '4321', true)), array('setHydrator', array($hydrator), '__self__'), array('getHydrator', array(), '\\Zend\\Stdlib\\Hydrator\\HydratorInterface', 'instance'), array(array('setId', 'getId'), array(array('4321'), array()), array('__self__', '4321')), array(array('setDateCreated', 'getDateCreated'), array(array($date), array()), array('__self__', $date)), array(array('setDateModified', 'getDateModified'), array(array($date), array()), array('__self__', $date)), array(array('setParent', 'getParent'), array(array($parent), array()), array('__self__', $parent)), array(array('setContact', 'getContact'), array(array($contact), array()), array('__self__', $contact)), array('isHiringOrganization', array(), false), array('getHiringOrganizations', array(), null), array(array('setOrganizationName', 'getOrganizationName'), array(array($name), array()), array('__self__', $name)), array(array('setDescription', 'getDescription'), array(array('nodesc'), array()), array('__self__', 'nodesc')), array(array('setEmployees', 'getEmployees'), array(array($emps), array()), array('__self__', $emps)), array('getEmployee', array('4321'), null), array(array('setUser', 'getUser', 'getPermissionsUserIds'), array(array($user), array(), array()), array('__self__', $user, array(PermissionsInterface::PERMISSION_ALL => array($user->getId())))), array('getJobs', array(), null), array(array('setPermissions', 'getPermissions'), array(array($perms), array()), array('__self__', $perms)), array('getPermissionsResourceId', array(), 'organization:'), array('getSearchableProperties', array(), array()), array(array('setKeywords', 'getKeywords'), array(array(array('no', 'keywords')), array()), array(null, null)), array('clearKeywords', array(), null));
 }
Beispiel #15
0
 /**
  * Tests if getAssigned returns the correct value.
  *
  */
 public function testGetAssignedReturnsSpecificationArray()
 {
     $target = new Permissions();
     $target->grantAll('testUser');
     $user = new User();
     $user->setId('testUser2');
     $target->grantView($user);
     $expected = array('user:testUser' => array(PermissionsInterface::PERMISSION_ALL => array('testUser')), 'user:testUser2' => array(PermissionsInterface::PERMISSION_VIEW => array('testUser2')));
     $this->assertEquals($expected, $target->getAssigned());
 }
 public function provideOrganizationInterfaceFunctionValues()
 {
     $hydrator = new EntityHydrator();
     $date = new \DateTime();
     $parent = new Organization();
     $name = new OrganizationName('noname');
     $emps = new ArrayCollection();
     $user = new User();
     $user->setId('543');
     $user->setRole('department manager');
     $perms = new Permissions();
     $contact = new OrganizationContact();
     $image = new OrganizationImage();
     $externalId = 'myReference';
     $template = new Template();
     $template->setLabelBenefits('These are your Benefits');
     $workflowSettings = new WorkflowSettings();
     $workflowSettings->setAcceptApplicationByDepartmentManager(true);
     return [[['__set', '__get', '__isset'], [['id', '4321'], ['id'], ['id']], ['__self__', '4321', true]], ['setHydrator', [$hydrator], '__self__'], ['getHydrator', [], '\\Zend\\Hydrator\\HydratorInterface', 'instance'], [['setId', 'getId'], [['4321'], []], ['__self__', '4321']], [['setContact', 'getContact'], [[$contact], []], ['__self__', $contact]], [['setDateCreated', 'getDateCreated'], [[$date], []], ['__self__', $date]], [['setDateModified', 'getDateModified'], [[$date], []], ['__self__', $date]], [['setExternalId', 'getExternalId'], [[$externalId], []], ['__self__', $externalId]], [['setParent', 'getParent'], [[$parent], []], ['__self__', $parent]], [['setImage', 'getImage'], [[$image], []], ['__self__', $image]], [['setTemplate', 'getTemplate'], [[$template], []], ['__self__', $template]], [['setWorkflowSettings', 'getWorkflowSettings'], [[$workflowSettings], []], ['__self__', $workflowSettings]], ['isHiringOrganization', [], false], ['getHiringOrganizations', [], null], [['setOrganizationName', 'getOrganizationName'], [[$name], []], ['__self__', $name]], [['setDescription', 'getDescription'], [['nodesc'], []], ['__self__', 'nodesc']], [['setEmployees', 'getEmployees'], [[$emps], []], ['__self__', $emps]], ['getEmployee', ['4321'], null], [['setUser', 'getUser', 'getPermissionsUserIds'], [[$user], [], []], ['__self__', $user, [PermissionsInterface::PERMISSION_ALL => [$user->getId()]]]], ['getJobs', [], null], [['setPermissions', 'getPermissions'], [[$perms], []], ['__self__', $perms]], ['getPermissionsResourceId', [], 'organization:'], ['getSearchableProperties', [], []]];
 }
 public function testCopyAttachments()
 {
     $applicationAttachment1Data = ['getContent' => 'content', 'getName' => 'name', 'getType' => 'type', 'getDateUploaded' => new \DateTime()];
     $applicationAttachment1 = $this->getMockBuilder(ApplicationAttachment::class)->setMethods(array_keys($applicationAttachment1Data))->getMock();
     foreach ($applicationAttachment1Data as $method => $return) {
         $applicationAttachment1->expects($this->once())->method($method)->willReturn($return);
     }
     $applicationAttachments = new ArrayCollection([$applicationAttachment1]);
     $this->repository->expects($this->once())->method('create');
     $job = new Job();
     $user = new User();
     $user->setId('jobUser');
     $job->setUser($user);
     $application = $this->getMockBuilder(Application::class)->setMethods(['getContact', 'getAttachments'])->getMock();
     $application->method('getContact')->willReturn(new ApplicationContact());
     $application->expects($this->once())->method('getAttachments')->willReturn($applicationAttachments);
     $application->setJob($job);
     $cv = $this->repository->createFromApplication($application, $this->user);
     $this->assertSame($this->cv, $cv);
     $cvAttachments = $cv->getAttachments();
     $this->assertSame($applicationAttachments->count(), $cvAttachments->count());
     $cvAttachment1 = $cvAttachments->first();
     $this->assertInstanceOf(CvAttachment::class, $cvAttachment1);
     $this->assertSame($applicationAttachment1Data['getContent'], $cvAttachment1->getFile()->getBytes());
     $this->assertSame($applicationAttachment1Data['getName'], $cvAttachment1->getName());
     $this->assertSame($applicationAttachment1Data['getType'], $cvAttachment1->getType());
     $this->assertSame($applicationAttachment1Data['getDateUploaded'], $cvAttachment1->getDateUploaded());
     $this->assertSame($user, $cvAttachment1->getUser());
 }
 /**
  * Gets an Assertion event seeded with Mock objects.
  *
  * @param bool $isOneEmployeeAllowed if true, one employee in the employees collection gets job create permissions.
  *
  * @return AssertionEvent
  */
 protected function getTestEvent($isOneEmployeeAllowed = true)
 {
     $employees = new ArrayCollection();
     for ($i = 0; $i < 3; $i++) {
         $empUser = new User();
         $empUser->setId('1234-' . $i);
         $perm = new EmployeePermissions(EmployeePermissionsInterface::JOBS_VIEW);
         if (2 == $i && $isOneEmployeeAllowed) {
             $perm->grant(EmployeePermissionsInterface::JOBS_CREATE);
         }
         $emp = new Employee($empUser, $perm);
         $employees->add($emp);
     }
     $org = $this->getMockBuilder('\\Organizations\\Entity\\OrganizationReference')->disableOriginalConstructor()->getMock();
     $org->expects($this->once())->method('hasAssociation')->willReturn(true);
     $org->expects($this->once())->method('isOwner')->willReturn(false);
     $org->expects($this->once())->method('getEmployees')->willReturn($employees);
     $role = new User();
     $role->setId('1234-2');
     $role->setOrganization($org);
     $e = new AssertionEvent();
     $e->setRole($role);
     return $e;
 }
Beispiel #19
0
 public function testSetGetUserTwice()
 {
     $user1 = new User();
     $user1->setId(123);
     $this->target->setUser($user1);
     $user2 = new User();
     $user2->setId(456);
     $this->target->setUser($user2);
     $this->assertEquals($this->target->getUser(), $user2);
 }
 /**
  * @covers Applications\Entity\Application::addReadBy
  */
 public function testAddReadByWithUser()
 {
     $user = new User();
     $user->setId(123);
     $this->target->addReadBy($user);
     $this->assertEquals(false, $this->target->isUnReadBy($user));
     $this->assertEquals(true, $this->target->isReadBy($user));
 }
 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'));
 }