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']); }
/** * 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 testToStringUsername() { $obj = new Calendar(); $owner = new User(); $owner->setUsername('testUsername'); $obj->setOwner($owner); $this->assertEquals($owner->getUsername(), (string) $obj); }
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); }
/** * @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()); }
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()); }
/** * 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); }
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); }
/** * @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; }
/** * @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); } } }