public function testBuildView() { $firstUser = new User(); $firstUser->setUsername('1'); $secondUser = new User(); $secondUser->setUsername('2'); $firstCalendar = new Calendar(); $firstCalendar->setOwner($firstUser); $secondCalendar = new Calendar(); $secondCalendar->setOwner($secondUser); $firstEvent = new CalendarEvent(); $firstEvent->setCalendar($firstCalendar); $secondEvent = new CalendarEvent(); $secondEvent->setCalendar($secondCalendar); $formData = [$firstEvent, $secondEvent]; $transformedData = [$firstUser, $secondUser]; $form = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $form->expects($this->once())->method('getData')->will($this->returnValue($formData)); $this->transformer->expects($this->once())->method('transform')->with($formData)->will($this->returnValue($transformedData)); $converter = $this->getMock('Oro\\Bundle\\FormBundle\\Autocomplete\\ConverterInterface'); $converter->expects($this->any())->method('convertItem')->will($this->returnCallback([$this, 'convertEvent'])); $formView = new FormView(); $expectedSelectedData = json_encode([$this->convertEvent($firstUser), $this->convertEvent($secondUser)]); $this->type->buildView($formView, $form, ['converter' => $converter]); $this->assertArrayHasKey('attr', $formView->vars); $this->assertEquals(['data-selected-data' => $expectedSelectedData], $formView->vars['attr']); }
public function testPostSubmitChildEvents() { $firstCalendar = new Calendar(); $firstCalendar->setName('1'); $secondCalendar = new Calendar(); $secondCalendar->setName('2'); $firstEvent = new CalendarEvent(); $firstEvent->setTitle('1')->setCalendar($firstCalendar); $secondEvent = new CalendarEvent(); $secondEvent->setTitle('2')->setCalendar($secondCalendar); $firstExistingEvent = new CalendarEvent(); $firstExistingEvent->setTitle('1_existing')->setCalendar($firstCalendar); $parentEvent = new CalendarEvent(); $parentEvent->addChildEvent($firstExistingEvent); $parentForm = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $parentForm->expects($this->any())->method('getData')->will($this->returnValue($parentEvent)); $events = new ArrayCollection([$firstEvent, $secondEvent]); $form = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $form->expects($this->any())->method('getData')->will($this->returnValue($events)); $this->type->preSubmit(new FormEvent($parentForm, [])); $this->type->postSubmitChildEvents(new FormEvent($form, [])); $this->assertCount(2, $events); $this->assertEquals($firstExistingEvent, $events[0]); $this->assertEquals($secondEvent, $events[1]); }
/** * 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); }
/** * @param Calendar $calendar * * @return string */ protected function buildCalendarName(Calendar $calendar) { $name = $calendar->getName(); if (!$name) { $name = $this->entityNameResolver->getName($calendar->getOwner()); } return $name; }
public function testToStringUsername() { $obj = new Calendar(); $owner = new User(); $owner->setUsername('testUsername'); $obj->setOwner($owner); $this->assertEquals($owner->getUsername(), (string) $obj); }
/** * View calendar * * @Route("/view/{id}", name="oro_calendar_view", requirements={"id"="\d+"}) * * @Template * @Acl( * id="oro_calendar_view", * type="entity", * class="OroCalendarBundle:Calendar", * permission="VIEW", * group_name="" * ) */ public function viewAction(Calendar $calendar) { /** @var SecurityFacade $securityFacade */ $securityFacade = $this->get('oro_security.security_facade'); /** @var CalendarDateTimeConfigProvider $calendarConfigProvider */ $calendarConfigProvider = $this->get('oro_calendar.provider.calendar_config'); $dateRange = $calendarConfigProvider->getDateRange(); $result = array('event_form' => $this->get('oro_calendar.calendar_event.form')->createView(), 'user_select_form' => $this->get('form.factory')->createNamed('new_calendar_owner', 'oro_user_select', null, array('autocomplete_alias' => 'acl_users', 'configs' => array('entity_id' => $calendar->getId(), 'entity_name' => 'OroCalendarBundle:Calendar', 'excludeCurrent' => true, 'extra_config' => 'acl_user_autocomplete', 'permission' => 'VIEW', 'placeholder' => 'oro.calendar.form.choose_user_to_add_calendar', 'result_template_twig' => 'OroUserBundle:User:Autocomplete/result.html.twig', 'selection_template_twig' => 'OroUserBundle:User:Autocomplete/selection.html.twig'), 'grid_name' => 'users-select-grid-exclude-owner', 'random_id' => false, 'required' => true))->createView(), 'entity' => $calendar, 'calendar' => array('selectable' => $securityFacade->isGranted('oro_calendar_event_create'), 'editable' => $securityFacade->isGranted('oro_calendar_event_update'), 'removable' => $securityFacade->isGranted('oro_calendar_event_delete'), 'timezoneOffset' => $calendarConfigProvider->getTimezoneOffset()), 'startDate' => $dateRange['startDate'], 'endDate' => $dateRange['endDate']); return $result; }
protected function setUp() { $this->contextAccessor = new ContextAccessor(); $calendarRepository = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Repository\\CalendarRepository')->disableOriginalConstructor()->setMethods(['findDefaultCalendar'])->getMock(); $calendar = new Calendar(); $calendar->setOwner($this->getUserMock()); $calendarRepository->method('findDefaultCalendar')->willReturn($calendar); $this->registry = $this->getMockBuilder('Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->setMethods(['getManagerForClass', 'getManager', 'getRepository'])->getMock(); $this->registry->method('getRepository')->willReturn($calendarRepository); }
public function testEvents() { $obj = new Calendar(); $this->assertCount(0, $obj->getConnections()); $event = new CalendarEvent(); $obj->addEvent($event); $this->assertCount(1, $obj->getEvents()); $events = $obj->getEvents(); $this->assertTrue($event === $events[0]); $this->assertTrue($obj === $events[0]->getCalendar()); }
/** * @param EntityManager $em * @param UnitOfWork $uow * @param User $entity * @param Organization $organization */ protected function createCalendar($em, $uow, $entity, $organization) { // create a default calendar for assigned organization $calendar = new Calendar(); $calendar->setOwner($entity); $calendar->setOrganization($organization); // connect the calendar to itself $calendarConnection = new CalendarConnection($calendar); $calendar->addConnection($calendarConnection); $em->persist($calendar); $em->persist($calendarConnection); $uow->computeChangeSet($this->getClassMetadata($calendar, $em), $calendar); $uow->computeChangeSet($this->getClassMetadata($calendarConnection, $em), $calendarConnection); }
public function testTransform() { $this->assertNull($this->transformer->transform(null)); $firstUser = new User(); $firstUser->setUsername('1'); $secondUser = new User(); $secondUser->setUsername('2'); $firstCalendar = new Calendar(); $firstCalendar->setOwner($firstUser); $secondCalendar = new Calendar(); $secondCalendar->setOwner($secondUser); $firstEvent = new CalendarEvent(); $firstEvent->setCalendar($firstCalendar); $secondEvent = new CalendarEvent(); $secondEvent->setCalendar($secondCalendar); $this->assertEquals([$firstUser, $secondUser], $this->transformer->transform([$firstEvent, $secondEvent])->toArray()); }
/** * Test existing user modification */ public function testOnFlushUpdateUser() { $args = new OnFlushEventArgs($this->em); $user = new User(); ReflectionUtil::setId($user, 123); $org = new Organization(); ReflectionUtil::setId($org, 1); $coll = $this->getPersistentCollection($user, ['fieldName' => 'organizations'], [$org]); $newCalendar = new Calendar(); $newCalendar->setOwner($user); $newCalendar->setOrganization($org); $calendarMetadata = new ClassMetadata(get_class($newCalendar)); $calendarRepo = $this->getMockBuilder('\\Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $calendarRepo->expects($this->any())->method('findDefaultCalendar')->will($this->returnValue(false)); $this->uow->expects($this->once())->method('getScheduledEntityInsertions')->will($this->returnValue([])); $this->uow->expects($this->once())->method('getScheduledCollectionUpdates')->will($this->returnValue([$coll])); $this->em->expects($this->at(1))->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('getClassMetadata')->with('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->will($this->returnValue($calendarMetadata)); $this->uow->expects($this->once())->method('computeChangeSet')->with($calendarMetadata, $newCalendar); $this->listener->onFlush($args); }
public function testGetReminderData() { $obj = new CalendarEvent(); ReflectionUtil::setId($obj, 1); $obj->setTitle('testTitle'); $calendar = new Calendar(); $calendar->setOwner(new User()); $obj->setCalendar($calendar); /** @var ReminderData $reminderData */ $reminderData = $obj->getReminderData(); $this->assertEquals($reminderData->getSubject(), $obj->getTitle()); $this->assertEquals($reminderData->getExpireAt(), $obj->getStart()); $this->assertTrue($reminderData->getRecipient() === $calendar->getOwner()); }
/** * Gets UID of a calendar this event belongs to * The calendar UID is a string includes a calendar alias and id in the following format: {alias}_{id} * * @return string|null */ public function getCalendarUid() { if ($this->calendar) { return sprintf('%s_%d', Calendar::CALENDAR_ALIAS, $this->calendar->getId()); } elseif ($this->systemCalendar) { $alias = $this->systemCalendar->isPublic() ? SystemCalendar::PUBLIC_CALENDAR_ALIAS : SystemCalendar::CALENDAR_ALIAS; return sprintf('%s_%d', $alias, $this->systemCalendar->getId()); } return null; }
/** * @param Calendar $calendar * * @return string */ protected function buildCalendarName(Calendar $calendar) { return $calendar->getName() ?: $this->entityNameResolver->getName($calendar->getOwner()); }
/** * Returns calendar owner name formatted based on system configuration * * @param Calendar $calendar * @return string */ protected function getOwnerName(Calendar $calendar) { return $this->get('oro_locale.formatter.name')->format($calendar->getOwner()); }
/** * @param OnFlushEventArgs $event */ public function onFlush(OnFlushEventArgs $event) { $em = $event->getEntityManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledEntityInsertions() as $entity) { if ($entity instanceof User) { // create a default calendar to a new user $calendar = new Calendar(); $calendar->setOwner($entity); // connect the calendar to itself $calendarConnection = new CalendarConnection($calendar); $calendar->addConnection($calendarConnection); $em->persist($calendar); $em->persist($calendarConnection); // can't inject entity manager through constructor because of circular dependency $uow->computeChangeSet($this->getCalendarMetadata($em), $calendar); $uow->computeChangeSet($this->getCalendarConnectionMetadata($em), $calendarConnection); } } }
/** * @param EntityManager $em * @param UnitOfWork $uow * @param User $user * @param Organization $organization */ protected function createCalendar($em, $uow, $user, $organization) { // create default user's calendar $calendar = new Calendar(); $calendar->setOwner($user)->setOrganization($organization); $em->persist($calendar); $uow->computeChangeSet($this->getClassMetadata($calendar, $em), $calendar); $this->insertedCalendars[] = $calendar; }
protected function setUpEvent(CalendarEvent $event, $id, $email) { $user = new User(); $user->setEmail($email); $calendar = new Calendar(); $calendar->setOwner($user); $event->setCalendar($calendar); ReflectionUtil::setPrivateProperty($event, 'id', $id); $event->setReminded(false); }