/**
  * Test existing user modification
  */
 public function testOnFlushUpdateUser()
 {
     $args = new OnFlushEventArgs($this->em);
     $user = new User();
     $org = new Organization();
     $org->setId(1);
     $org->setName('test');
     $user->addOrganization($org);
     $newCalendar = new Calendar();
     $newCalendar->setOwner($user);
     $newCalendar->setOrganization($org);
     $newConnection = new CalendarConnection($newCalendar);
     $newCalendar->addConnection($newConnection);
     $calendarMetadata = new ClassMetadata(get_class($newCalendar));
     $connectionMetadata = new ClassMetadata(get_class($newConnection));
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValueMap([['Oro\\Bundle\\CalendarBundle\\Entity\\Calendar', $calendarMetadata], ['Oro\\Bundle\\CalendarBundle\\Entity\\CalendarConnection', $connectionMetadata]]));
     $calendarRepo = $this->getMockBuilder('\\Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $calendarRepo->expects($this->any())->method('findDefaultCalendar')->will($this->returnValue(false));
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->uow));
     $this->uow->expects($this->once())->method('getScheduledEntityInsertions')->will($this->returnValue([]));
     $this->uow->expects($this->once())->method('getScheduledEntityUpdates')->will($this->returnValue([$user]));
     $this->em->expects($this->any())->method('getRepository')->with('OroCalendarBundle:Calendar')->will($this->returnValue($calendarRepo));
     $this->em->expects($this->at(2))->method('persist')->with($this->equalTo($newCalendar));
     $this->em->expects($this->at(3))->method('persist')->with($this->equalTo($newConnection));
     $this->uow->expects($this->at(2))->method('computeChangeSet')->with($calendarMetadata, $newCalendar);
     $this->uow->expects($this->at(3))->method('computeChangeSet')->with($connectionMetadata, $newConnection);
     $this->listener->onFlush($args);
 }
 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 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]]);
 }
 protected function getTestOrganization()
 {
     $organization = new Organization();
     $organization->setId(1);
     return $organization;
 }