コード例 #1
0
ファイル: CommentTest.php プロジェクト: utrenkner/YAWIK
 public function testSetGetUser()
 {
     $user = new User();
     $user->setId('test');
     $this->target->setUser($user);
     $this->assertEquals($this->target->getUser(), $user);
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: MailSenderTest.php プロジェクト: webpants/YAWIK
 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;
     }
 }
コード例 #4
0
 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];
 }
コード例 #5
0
 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]];
 }
コード例 #6
0
ファイル: EmployeeTest.php プロジェクト: cross-solution/yawik
 /**
  * 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());
 }
コード例 #7
0
ファイル: AuthTest.php プロジェクト: webpants/YAWIK
 public function testReturnsUserPropertiesWhenInvokedViaObjectInvokationAndAnArgumentIsPassed()
 {
     $login = '******';
     $user = new User();
     $user->setLogin($login);
     $auth = $this->getMockBuilder('Auth\\AuthenticationService')->disableOriginalConstructor()->getMock();
     $auth->expects($this->exactly(2))->method('getUser')->willReturn($user);
     $target = new AuthHelper();
     $target->setService($auth);
     $this->assertEquals($login, $target('login'));
     $this->assertNull($target('nonexistent'));
 }
コード例 #8
0
 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));
 }
コード例 #9
0
 /**
  * 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);
 }
コード例 #10
0
ファイル: UserTest.php プロジェクト: webpants/YAWIK
 /**
  * @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());
 }
コード例 #11
0
 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]);
 }
コード例 #12
0
 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];
 }
コード例 #13
0
 /**
  * @dataProvider dataForPrepareExceptionViewModel
  */
 public function testPrepareExceptionViewModel($error, $result, $exception, $hasIdentity, $isActive, $expectedSetResultCalled)
 {
     $this->event->expects($this->any())->method('getError')->willReturn($error);
     $this->event->expects($this->any())->method('getResult')->willReturn($result);
     $this->event->expects($this->any())->method('getParam')->with($this->equalTo('exception'))->willReturn($exception);
     $this->auth->expects($this->any())->method('hasIdentity')->willReturn($hasIdentity);
     $this->user->expects($this->any())->method('isActive')->willReturn($isActive);
     $this->event->expects($this->exactly($expectedSetResultCalled))->method('setResult');
     $this->listener->prepareExceptionViewModel($this->event);
 }
コード例 #14
0
 /**
  * @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());
 }
コード例 #15
0
 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;
 }
コード例 #16
0
 /**
  * @testdox createService() returns select element with value options if organization is associated to the user.
  */
 public function testCreateServiceWithAssociation()
 {
     /* @var $org \PHPUnit_Framework_MockObject_MockObject */
     $org = $this->user->getOrganization();
     $org->expects($this->once())->method('hasAssociation')->willReturn(true);
     $orgs = new ArrayCollection();
     $org0 = $this->generateOrganizationEntity('testOrg0', 'testOrg0.name', 'org0.testCity', 'org0.testStreet', 'org0.1234');
     $org1 = $this->generateOrganizationEntity('testOrg1', 'testOrg1.name', 'org1.city', 'org1.street', 'org1.number');
     $orgs->add($org1);
     $org->expects($this->once())->method('getHiringOrganizations')->willReturn($orgs);
     $org->expects($this->once())->method('getOrganization')->willReturn($org0);
     $expect = array('testOrg0' => 'testOrg0.name|org0.testCity|org0.testStreet|org0.1234|', 'testOrg1' => 'testOrg1.name|org1.city|org1.street|org1.number|');
     $select = $this->target->createService($this->formElements);
     $actual = $select->getValueOptions();
     $this->assertEquals($expect, $actual);
 }
コード例 #17
0
ファイル: UserEntityProvider.php プロジェクト: webpants/YAWIK
 /**
  * @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;
 }
コード例 #18
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);
 }
コード例 #19
0
 /**
  * @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));
 }
コード例 #20
0
ファイル: PermissionsTest.php プロジェクト: utrenkner/YAWIK
 /**
  * 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());
 }
コード例 #21
0
 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));
 }
コード例 #22
0
 /**
  * {@inheritDoc}
  */
 public function getUsrId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getUsrId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getUsrId', array());
     return parent::getUsrId();
 }
コード例 #23
0
 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', [], []]];
 }
コード例 #24
0
 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());
 }
コード例 #25
0
ファイル: UserTest.php プロジェクト: cross-solution/yawik
 /**
  * @testdox Allows to set a Token of a user
  * @covers Auth\Entity\User::getTokens
  * @covers Auth\Entity\User::setTokens
  * @dataProvider provideTokenTestData
  *
  */
 public function testSetGetToken($token, $expectedToken)
 {
     $this->target->setTokens($token);
     $this->assertEquals($expectedToken, $this->target->getTokens());
 }
コード例 #26
0
ファイル: JobsTest.php プロジェクト: cross-solution/yawik
 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);
 }
コード例 #27
0
 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'));
 }
コード例 #28
0
 /**
  * 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;
 }