/** * Test add and remove activity owner from ActivityList */ public function testAddRemoveActivityOwner() { $activity = new ActivityList(); $activity->setId(1); $organization = new Organization(); $user1 = new User(); $user1->setId(1); $user1->setFirstName('TestUserName1'); $entity1 = new ActivityOwner(); $entity1->setActivity($activity); $entity1->setUser($user1); $entity1->setOrganization($organization); $activity->addActivityOwner($entity1); $user2 = new User(); $user1->setId(2); $user2->setFirstName('TestUserName2'); $entity2 = new ActivityOwner(); $entity2->setActivity($activity); $entity2->setUser($user2); $entity2->setOrganization($organization); $activity->addActivityOwner($entity2); $this->assertTrue($activity->getActivityOwners()->contains($entity1)); $this->assertTrue($activity->getActivityOwners()->contains($entity2)); $activity->removeActivityOwner($entity1); $activity->removeActivityOwner($entity2); $this->assertFalse($activity->getActivityOwners()->contains($entity1)); $this->assertFalse($activity->getActivityOwners()->contains($entity2)); }
public function testProcessValidData() { $appendedUser = new User(); $appendedUser->setId(1); $removedUser = new User(); $removedUser->setId(2); $removedUser->addBusinessUnit($this->entity); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedUser))); $this->form->expects($this->at(3))->method('get')->with('appendUsers')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedUser))); $this->form->expects($this->at(4))->method('get')->with('removeUsers')->will($this->returnValue($removeForm)); $this->manager->expects($this->at(0))->method('persist')->with($appendedUser); $this->manager->expects($this->at(1))->method('persist')->with($removedUser); $this->manager->expects($this->at(2))->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $businessUnits = $appendedUser->getBusinessUnits()->toArray(); $this->assertCount(1, $businessUnits); $this->assertEquals($this->entity, current($businessUnits)); $this->assertCount(0, $removedUser->getBusinessUnits()->toArray()); }
public function testSetUserIdAndOrganizationIds() { $this->assertEmpty($this->securityContext->getToken()); $userId = 1; $user = new User(); $user->setId($userId); $organizationId = 2; $organization = new Organization(); $organization->setId($organizationId); $organization->setEnabled(true); $user->addOrganization($organization); $event = $this->getEvent(); /** @var \PHPUnit_Framework_MockObject_MockObject $input */ $input = $event->getInput(); $input->expects($this->at(0))->method('getParameterOption')->with('--' . ConsoleContextListener::OPTION_USER)->will($this->returnValue($userId)); $input->expects($this->at(1))->method('getParameterOption')->with('--' . ConsoleContextListener::OPTION_ORGANIZATION)->will($this->returnValue($organizationId)); $this->userRepository->expects($this->once())->method('find')->with($userId)->will($this->returnValue($user)); $this->organizationRepository->expects($this->once())->method('find')->with($organizationId)->will($this->returnValue($organization)); $this->listener->onConsoleCommand($event); /** @var ConsoleToken $token */ $token = $this->securityContext->getToken(); $this->assertNotEmpty($token); $this->assertInstanceOf('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\ConsoleToken', $token); $this->assertEquals($user, $token->getUser()); $this->assertEquals($organization, $token->getOrganizationContext()); }
public function testInitializeScopeId() { $user = new User(); $user->setId(123); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $this->securityContext->expects($this->once())->method('getToken')->willReturn($token); $token->expects($this->once())->method('getUser')->willReturn($user); $this->assertEquals(123, $this->manager->getScopeId()); }
public function testProcessEvent() { $user = new User(); $user->setId(1); $this->configManager->expects($this->once())->method('get')->with('diamante_desk.email_notification')->will($this->returnValue(true)); $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($user)); $event = $this->event(); $this->notificationDeliveryManager->expects($this->once())->method('add')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\Notifications\\TicketNotification'), $this->attributeEqualTo('ticketUniqueId', $event->getAggregateId()), $this->attributeEqualTo('author', $user), $this->attributeEqualTo('headerText', $event->getHeaderText()), $this->attributeEqualTo('subject', $event->getSubject()), $this->attributeEqualTo('attachments', $event->attachments()), $this->attribute($this->logicalAnd($this->isInstanceOf('\\ArrayIterator'), $this->arrayHasKey('Description'), $this->contains('New Description')), 'changeList'))); $this->subscriber->processEvent($event); }
/** * @dataProvider hasAccessEditFiledDataProvider * * @param int $currentUserId * @param int $userId * @param string $fieldName * @param bool $result */ public function testHasAccessEditField($currentUserId, $userId, $fieldName, $result) { $currentUser = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\User')->setMethods(['getId'])->disableOriginalConstructor()->getMock(); if ('enabled' === $fieldName) { $currentUser->expects(self::once())->method('getId')->willReturn($currentUserId); } $this->securityFacade->expects(self::once())->method('getLoggedUser')->willReturn($currentUser); $entity = new User(); $entity->setId($userId); self::assertEquals($this->validator->hasAccessEditField($entity, $fieldName), $result); }
public function testSendNotNewEntity() { $organization = new Organization(); $organization->setId(1); $user = new User(); $user->setId(1); $this->emailUser->expects($this->exactly(1))->method('getOwner')->willReturn($user); $this->emailUser->expects($this->exactly(2))->method('getOrganization')->willReturn($organization); $this->topicPublisher->expects($this->once())->method('send')->with(WebSocketSendProcessor::getUserTopic($this->emailUser->getOwner(), $this->emailUser->getOrganization()), json_encode(['hasNewEmail' => false])); $this->processor->send([1 => ['entity' => $this->emailUser, 'new' => 0]]); }
/** * @return User */ protected function getUser() { $user = new User(); /** @var \PHPUnit_Framework_MockObject_MockObject|Group $group1 */ $group1 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group'); /** @var \PHPUnit_Framework_MockObject_MockObject|Group $group2 */ $group2 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group'); $group1->expects($this->any())->method('getId')->will($this->returnValue(2)); $group2->expects($this->any())->method('getId')->will($this->returnValue(3)); $user->setId(1)->addGroup($group1)->addGroup($group2); return $user; }
/** * @param array $params * @param array $expected * * @dataProvider permissionsDataProvider */ public function testGetInvitationPermissions(array $params, array $expected) { $record = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecordInterface'); $user = new User(); $user->setId(self::ADMIN); $this->securityFacade->expects($this->any())->method('getLoggedUser')->will($this->returnValue($user)); $record->expects($this->at(0))->method('getValue')->with('invitationStatus')->will($this->returnValue($params['invitationStatus'])); $record->expects($this->at(1))->method('getValue')->with('parentId')->will($this->returnValue($params['parentId'])); $record->expects($this->at(2))->method('getValue')->with('ownerId')->will($this->returnValue($params['ownerId'])); $record->expects($this->at(3))->method('getValue')->with('childrenCount')->will($this->returnValue($params['childrenCount'])); $result = $this->provider->getInvitationPermissions($record); $this->assertEquals($expected, $result); }
public function testAddRemoveUser() { $org = new Organization(); $user = new User(); $user->setId(uniqid()); $this->assertFalse($org->hasUser($user)); $org->addUser($user); $users = $org->getUsers()->toArray(); $this->assertCount(1, $users); $this->assertTrue($org->hasUser($user)); $this->assertEquals($user, reset($users)); $org->removeUser($user); $this->assertFalse($org->hasUser($user)); }
public function testReverseTransform() { $this->assertSame([], $this->transformer->reverseTransform(null)); $this->assertSame([], $this->transformer->reverseTransform([])); $organizationId = 42; $firstUser = new User(); $firstUser->setId(1)->setUsername('1'); $secondUser = new User(); $secondUser->setId(2)->setUsername('2'); $firstCalendar = new Calendar(); $this->securityFacade->expects($this->any())->method('getOrganizationId')->will($this->returnValue($organizationId)); $calendarRepository = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Repository\\CalendarRepository')->disableOriginalConstructor()->getMock(); $calendarRepository->expects($this->once())->method('findDefaultCalendars')->with([1, 2], $organizationId)->will($this->returnValue([$firstCalendar])); $this->registry->expects($this->any())->method('getRepository')->with('OroCalendarBundle:Calendar')->will($this->returnValue($calendarRepository)); $events = $this->transformer->reverseTransform([$firstUser, $secondUser]); $this->assertCount(1, $events); /** @var CalendarEvent $event */ $event = $events->first(); $this->assertInstanceOf('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent', $event); $this->assertEquals($firstCalendar, $event->getCalendar()); }
/** * @dataProvider addEntityFieldsDataProvider * @param $permissions * @param $isMyProfile */ public function testAddEntityFields($permissions, $isMyProfile) { $user = new User(); $user->setId(1); $order = 0; foreach ($permissions as $rule => $isGranted) { $this->securityFacade->expects($this->at($order))->method('isGranted')->with($rule)->will($this->returnValue($isGranted)); $order++; } $request = new Request(); $request->attributes->add(array('_route' => $isMyProfile ? self::MY_PROFILE_ROUTE : self::OTHER_PROFILE_ROUTE)); $formFactory = $this->getMockBuilder('Symfony\\Component\\Form\\FormFactory')->disableOriginalConstructor()->getMock(); $userSubscriber = new UserSubscriber($formFactory, $this->securityInterface); $order = 0; $builder = $this->getMockBuilder('Symfony\\Component\\Form\\FormBuilder')->disableOriginalConstructor()->setMethods(array('addEventSubscriber', 'add', 'getFormFactory'))->getMock(); $builder->expects($this->at($order))->method('getFormFactory')->will($this->returnValue($formFactory)); $builder->expects($this->at(++$order))->method('addEventSubscriber')->with($userSubscriber)->will($this->returnSelf()); $this->mockSetDefaultUserFields($builder, $order); if ($permissions[self::RULE_ROLE]) { $builder->expects($this->at(++$order))->method('add')->with('roles', 'entity')->will($this->returnValue($builder)); } if ($permissions[self::RULE_GROUP]) { $arr = array('label' => 'oro.user.groups.label', 'class' => 'OroUserBundle:Group', 'property' => 'name', 'multiple' => true, 'expanded' => true, 'required' => false, 'read_only' => $isMyProfile, 'disabled' => $isMyProfile); $builder->expects($this->at(++$order))->method('add')->with('groups', 'entity', $arr)->will($this->returnValue($builder)); } if ($permissions[self::RULE_BUSINESS_UNIT] && $permissions[self::RULE_ORGANIZATION]) { $builder->expects($this->at(++$order))->method('add')->with('organizations', 'oro_organizations_select')->will($this->returnValue($builder)); } $builder->expects($this->at(++$order))->method('add')->with('plainPassword', 'repeated')->will($this->returnValue($builder)); $builder->expects($this->at(++$order))->method('add')->with('emails', 'collection')->will($this->returnValue($builder)); $builder->expects($this->at(++$order))->method('add')->with('tags', 'oro_tag_select')->will($this->returnValue($builder)); $builder->expects($this->at(++$order))->method('add')->with('imapConfiguration', 'oro_imap_configuration')->will($this->returnValue($builder)); $builder->expects($this->at(++$order))->method('add')->with('change_password', 'oro_change_password')->will($this->returnValue($builder)); $builder->expects($this->at(++$order))->method('add')->with('avatar', 'oro_image')->will($this->returnValue($builder)); $builder->expects($this->at(++$order))->method('add')->with('inviteUser', 'checkbox')->will($this->returnValue($builder)); $type = new UserType($this->securityInterface, $this->securityFacade, $request); $type->buildForm($builder, []); }
public function testFlush() { $changesetAnswer = ['seen' => true]; $user1 = new User(); $user1->setId(1); $user2 = new User(); $user2->setId(2); $emailUser1 = new EmailUser(); $emailUser1->setOwner($user1); $emailUser2 = new EmailUser(); $emailUser2->setOwner($user2); $emailUserArray = [$emailUser1, $emailUser2, $emailUser1]; $onFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\OnFlushEventArgs')->setMethods(['getEntityManager', 'getUnitOfWork', 'getScheduledEntityInsertions', 'getScheduledEntityUpdates', 'getEntityChangeSet'])->disableOriginalConstructor()->getMock(); $onFlushEventArgs->expects($this->once())->method('getEntityManager')->will($this->returnValue($onFlushEventArgs)); $onFlushEventArgs->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($onFlushEventArgs)); $onFlushEventArgs->expects($this->exactly(3))->method('getEntityChangeSet')->will($this->returnValue($changesetAnswer)); $onFlushEventArgs->expects($this->once())->method('getScheduledEntityInsertions')->will($this->returnValue($emailUserArray)); $onFlushEventArgs->expects($this->once())->method('getScheduledEntityUpdates')->will($this->returnValue($emailUserArray)); $this->processor->expects($this->exactly(1))->method('send')->with([$user1->getId() => ['entity' => $emailUser1, 'new' => 2], $user2->getId() => ['entity' => $emailUser2, 'new' => 1]]); $postFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\PostFlushEventArgs')->disableOriginalConstructor()->getMock(); $this->listener->onFlush($onFlushEventArgs); $this->listener->postFlush($postFlushEventArgs); }
protected function getTestUser() { $user = new User(); $user->setId(1); $user->setEmail('*****@*****.**'); $user->setSalt('1fqvkjskgry8s8cs400840c0ok8ggck'); return $user; }
public function testForecastOfOpportunitiesValuesWithBusinessUnits() { $user = new User(); $user->setId(1); $businessUnit = new BusinessUnit(); $businessUnit->addUser($user); $options = ['owners' => [], 'businessUnits' => [$businessUnit]]; $widgetOptions = new WidgetOptionBag($options); $this->opportunityRepository->expects($this->any())->method('getForecastOfOpporunitiesData')->with([$user->getId()], null, $this->aclHelper)->will($this->returnValue(['inProgressCount' => 5, 'budgetAmount' => 1000, 'weightedForecast' => 500])); $this->businessUnitRepository->expects($this->any())->method('findById')->will($this->returnValue([$businessUnit])); $result = $this->provider->getForecastOfOpportunitiesValues($widgetOptions, 'getInProgressValues', 'integer', false); $this->assertEquals(['value' => 5], $result); $result = $this->provider->getForecastOfOpportunitiesValues($widgetOptions, 'getTotalForecastValues', 'currency', false); $this->assertEquals(['value' => 1000], $result); $result = $this->provider->getForecastOfOpportunitiesValues($widgetOptions, 'getWeightedForecastValues', 'currency', false); $this->assertEquals(['value' => 500], $result); }
/** * @test */ public function getUserUrl() { $user = new User(); $user->setId(1); $url = '/user/view/4'; $this->router->expects($this->once())->method('generate')->with('oro_user_view', ['id' => $user->getId()])->will($this->returnValue($url)); $this->twigExtension->getUserUrl($user); }
public function testNotifyWithEmptyAuthor() { $ticketUniqueId = UniqueId::generate(); $reporter = new UserAdapter(1, UserAdapter::TYPE_DIAMANTE); $assignee = new User(); $assignee->setId(2); $assignee->setEmail('*****@*****.**'); $author = null; $branch = new Branch('KEY', 'Name', 'Description'); $ticket = new Ticket($ticketUniqueId, new TicketSequenceNumber(1), 'Subject', 'Description', $branch, $reporter, $assignee, new Source(Source::WEB), new Priority(Priority::PRIORITY_MEDIUM), new Status(Status::NEW_ONE)); $notification = new TicketNotification((string) $ticketUniqueId, $author, 'Header', 'Subject', new \ArrayIterator(array('key' => 'value')), array('file.ext')); $message = new \Swift_Message(); $this->watchersService->expects($this->once())->method('getWatchers')->will($this->returnValue([new WatcherList($ticket, 'diamante_1')])); $this->diamanteUserRepository->expects($this->exactly(2))->method('get')->with(1)->will($this->returnValue($this->diamanteUser)); $this->configManager->expects($this->once())->method('get')->will($this->returnValue('*****@*****.**')); $this->nameFormatter->expects($this->once())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last')); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->ticketRepository->expects($this->once())->method('getByUniqueId')->with($ticketUniqueId)->will($this->returnValue($ticket)); $this->templateResolver->expects($this->any())->method('resolve')->will($this->returnValueMap(array(array($notification, TemplateResolver::TYPE_TXT, 'txt.template.html'), array($notification, TemplateResolver::TYPE_HTML, 'html.template.html')))); $optionsConstraint = $this->logicalAnd($this->arrayHasKey('changes'), $this->arrayHasKey('attachments'), $this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains($notification->getChangeList()), $this->contains($notification->getAttachments()), $this->contains('First Last'), $this->contains($notification->getHeaderText())); $this->twig->expects($this->at(0))->method('render')->with('txt.template.html', $optionsConstraint)->will($this->returnValue('Rendered TXT template')); $this->twig->expects($this->at(1))->method('render')->with('html.template.html', $optionsConstraint)->will($this->returnValue('Rendered HTML template')); $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($notification) { $to = $other->getTo(); return false !== strpos($other->getSubject(), $notification->getSubject()) && false !== strpos($other->getSubject(), 'KEY-1') && false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('*****@*****.**', $to) && $other->getHeaders()->has('References') && false !== strpos($other->getHeaders()->get('References'), '*****@*****.**') && false !== strpos($other->getHeaders()->get('References'), '*****@*****.**'); }))); $this->messageReferenceRepository->expects($this->once())->method('findAllByTicket')->with($ticket)->will($this->returnValue(array(new MessageReference('*****@*****.**', $ticket), new MessageReference('*****@*****.**', $ticket)))); $this->messageReferenceRepository->expects($this->once())->method('store')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\EmailProcessing\\MessageReference'))); $notifier = new EmailNotifier($this->container, $this->twig, $this->mailer, $this->templateResolver, $this->ticketRepository, $this->messageReferenceRepository, $this->userService, $this->nameFormatter, $this->diamanteUserRepository, $this->configManager, $this->oroUserManager, $this->watchersService, $this->senderHost); $notifier->notify($notification); }