public function testCreatedAtGetter() { $obj = new CalendarConnection(new Calendar()); $date = new \DateTime(); ReflectionUtil::setCreatedAt($obj, $date); $this->assertEquals($date, $obj->getCreatedAt()); }
/** * @expectedException \Oro\Bundle\EntityBundle\Exception\InvalidEntityException */ public function testAddConnectionShouldNotAllowConnectEmpty() { $obj = new Calendar(); $connection = new CalendarConnection(new Calendar()); ReflectionUtil::setPrivateProperty($connection, 'connectedCalendar', null); $obj->addConnection($connection); }
public function testGetCalendarDefaultValues() { $organizationId = 1; $userId = 123; $calendarId = 20; $calendarIds = [10, 20]; $calendar1 = new Calendar(); ReflectionUtil::setId($calendar1, $calendarIds[0]); $user1 = new User(); ReflectionUtil::setId($user1, $userId); $calendar1->setOwner($user1); $calendar2 = new Calendar(); ReflectionUtil::setId($calendar2, $calendarIds[1]); $user2 = new User(); ReflectionUtil::setId($user2, 456); $calendar2->setOwner($user2); $calendars = [$calendar1, $calendar2]; $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->once())->method('createQueryBuilder')->with('o')->will($this->returnValue($qb)); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with('OroCalendarBundle:Calendar')->will($this->returnValue($repo)); $qb->expects($this->once())->method('select')->with('o, owner')->will($this->returnSelf()); $qb->expects($this->once())->method('innerJoin')->with('o.owner', 'owner')->will($this->returnSelf()); $qb->expects($this->once())->method('expr')->will($this->returnValue(new Expr())); $qb->expects($this->once())->method('where')->with(new Expr\Func('o.id IN', $calendarIds))->will($this->returnSelf()); $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getResult'])->getMockForAbstractClass(); $qb->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $query->expects($this->once())->method('getResult')->will($this->returnValue($calendars)); $this->entityNameResolver->expects($this->at(0))->method('getName')->with($this->identicalTo($user1))->will($this->returnValue('John Doo')); $this->entityNameResolver->expects($this->at(1))->method('getName')->with($this->identicalTo($user2))->will($this->returnValue('John Smith')); $result = $this->provider->getCalendarDefaultValues($organizationId, $userId, $calendarId, $calendarIds); $this->assertEquals([$calendarIds[0] => ['calendarName' => 'John Doo', 'userId' => $userId], $calendarIds[1] => ['calendarName' => 'John Smith', 'userId' => 456, 'removable' => false, 'canAddEvent' => true, 'canEditEvent' => true, 'canDeleteEvent' => true]], $result); }
public function testProcessPUT() { ReflectionUtil::setId($this->obj, 1); $this->request->setMethod('PUT'); $this->emailSendProcessor->expects($this->once())->method('sendUpdateParentEventNotification'); $handler = new CalendarEventApiHandler($this->form, $this->request, $this->om, $this->emailSendProcessor); $handler->process($this->obj); }
public function testConvertItem() { $user = new User(); ReflectionUtil::setId($user, 1); $user->setFirstName('testFirstName'); $user->setLastName('testLastName'); $calendar = new Calendar(); ReflectionUtil::setId($calendar, 2); $calendar->setOwner($user); $result = $this->handler->convertItem($calendar); $this->assertEquals($result['id'], $calendar->getId()); $this->assertEquals($result['userId'], $calendar->getOwner()->getId()); }
public function testGetCalendarDefaultValuesCanAddEvents() { $organizationId = 1; $userId = 123; $calendarId = 10; $calendarIds = [10]; $calendar1 = new SystemCalendar(); ReflectionUtil::setId($calendar1, 1); $calendar1->setName('Master'); $calendar1->setBackgroundColor('#FF0000'); $calendars = [$calendar1]; $this->calendarConfig->expects($this->once())->method('isPublicCalendarEnabled')->will($this->returnValue(true)); $this->securityFacade->expects($this->once())->method('isGranted')->with('oro_public_calendar_event_management')->will($this->returnValue(true)); $repo = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Repository\\SystemCalendarRepository')->disableOriginalConstructor()->getMock(); $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getResult'])->getMockForAbstractClass(); $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $repo->expects($this->once())->method('getPublicCalendarsQueryBuilder')->will($this->returnValue($qb)); $qb->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $query->expects($this->once())->method('getResult')->will($this->returnValue($calendars)); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with('OroCalendarBundle:SystemCalendar')->will($this->returnValue($repo)); $result = $this->provider->getCalendarDefaultValues($organizationId, $userId, $calendarId, $calendarIds); $this->assertEquals([$calendar1->getId() => ['calendarName' => $calendar1->getName(), 'backgroundColor' => $calendar1->getBackgroundColor(), 'removable' => false, 'position' => -80, 'canAddEvent' => true, 'canEditEvent' => true, 'canDeleteEvent' => true]], $result); }
public function testSubmitValidData() { $formData = ['targetCalendar' => 1, 'calendarAlias' => 'testCalendarAlias', 'calendar' => 2, 'position' => 100, 'visible' => true, 'backgroundColor' => '#00FF00']; $type = new CalendarPropertyApiType(); $form = $this->factory->create($type); $form->submit($formData); $this->assertTrue($form->isSynchronized()); /** @var CalendarProperty $result */ $result = $form->getData(); $this->assertInstanceOf('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarProperty', $result); $calendar = new Calendar(); ReflectionUtil::setId($calendar, 1); $this->assertEquals($calendar, $result->getTargetCalendar()); $this->assertEquals('testCalendarAlias', $result->getCalendarAlias()); $this->assertEquals(2, $result->getCalendar()); $this->assertEquals(100, $result->getPosition()); $this->assertTrue($result->getVisible()); $this->assertEquals('#00FF00', $result->getBackgroundColor()); $view = $form->createView(); $children = $view->children; foreach (array_keys($formData) as $key) { $this->assertArrayHasKey($key, $children); } }
public function testSubmitValidData() { $formData = array('calendar' => 1, 'title' => 'testTitle', 'start' => '2013-10-05T13:00:00Z', 'end' => '2013-10-05T13:30:00+00:00', 'allDay' => true, 'reminder' => true); $type = new CalendarEventApiType(array()); $form = $this->factory->create($type); $form->submit($formData); $this->assertTrue($form->isSynchronized()); /** @var CalendarEvent $result */ $result = $form->getData(); $this->assertInstanceOf('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent', $result); $calendar = new Calendar(); ReflectionUtil::setId($calendar, 1); $this->assertEquals($calendar, $result->getCalendar()); $this->assertEquals('testTitle', $result->getTitle()); $this->assertDateTimeEquals(new \DateTime('2013-10-05T13:00:00Z'), $result->getStart()); $this->assertDateTimeEquals(new \DateTime('2013-10-05T13:30:00Z'), $result->getEnd()); $this->assertTrue($result->getAllDay()); $this->assertTrue($result->getReminder()); $view = $form->createView(); $children = $view->children; foreach (array_keys($formData) as $key) { $this->assertArrayHasKey($key, $children); } }
/** * @dataProvider supportedMethods */ public function testProcessValidDataWithTargetEntityActivity($method) { $targetEntity = new User(); ReflectionUtil::setId($targetEntity, 123); $organization = new Organization(); ReflectionUtil::setId($organization, 1); $targetEntity->setOrganization($organization); $defaultCalendar = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->disableOriginalConstructor()->getMock(); $this->entity->setCalendar($defaultCalendar); $this->entityRoutingHelper->expects($this->once())->method('getEntityClassName')->will($this->returnValue(get_class($targetEntity))); $this->entityRoutingHelper->expects($this->once())->method('getEntityId')->will($this->returnValue($targetEntity->getId())); $this->entityRoutingHelper->expects($this->once())->method('getAction')->will($this->returnValue('activity')); $this->request->setMethod($method); $this->form->expects($this->once())->method('setData')->with($this->identicalTo($this->entity)); $this->form->expects($this->once())->method('submit')->with($this->identicalTo($this->request)); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->entityRoutingHelper->expects($this->once())->method('getEntityReference')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity)); $this->activityManager->expects($this->once())->method('addActivityTarget')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity)); $this->om->expects($this->once())->method('persist')->with($this->identicalTo($this->entity)); $this->om->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $this->assertSame($defaultCalendar, $this->entity->getCalendar()); }
public function testGetCalendarUidPublicCalendar() { $calendar = new SystemCalendar(); ReflectionUtil::setId($calendar, 123); $calendar->setPublic(true); $obj = new CalendarEvent(); $obj->setSystemCalendar($calendar); $this->assertEquals('public_123', $obj->getCalendarUid()); }
public function testIdGetter() { $obj = new SystemCalendar(); ReflectionUtil::setId($obj, 1); $this->assertEquals(1, $obj->getId()); }
/** * 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); }
public function testSetPublicCalendar() { $calendarId = 123; $calendar = new SystemCalendar(); $calendar->setPublic(true); ReflectionUtil::setId($calendar, $calendarId); $event = new CalendarEvent(); $this->calendarConfig->expects($this->once())->method('isPublicCalendarEnabled')->will($this->returnValue(true)); $repo = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Repository\\SystemCalendarRepository')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with('OroCalendarBundle:SystemCalendar')->will($this->returnValue($repo)); $repo->expects($this->once())->method('find')->with($calendarId)->will($this->returnValue($calendar)); $this->manager->setCalendar($event, SystemCalendar::PUBLIC_CALENDAR_ALIAS, $calendarId); $this->assertSame($calendar, $event->getSystemCalendar()); }