public function testGetUserCalendars() { $organizationId = 1; $userId = 10; $user = new User(); $calendars = [['id' => 100, 'name' => null], ['id' => 200, 'name' => 'name2']]; $this->securityFacade->expects($this->once())->method('getOrganizationId')->will($this->returnValue($organizationId)); $this->securityFacade->expects($this->once())->method('getLoggedUserId')->will($this->returnValue($userId)); $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($user)); $repo = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Repository\\CalendarRepository')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with('OroCalendarBundle:Calendar')->will($this->returnValue($repo)); $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $repo->expects($this->once())->method('getUserCalendarsQueryBuilder')->with($organizationId)->will($this->returnValue($qb)); $qb->expects($this->once())->method('select')->with('c.id, c.name')->will($this->returnSelf()); $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getArrayResult'])->getMockForAbstractClass(); $qb->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $query->expects($this->once())->method('getArrayResult')->will($this->returnValue($calendars)); $this->entityNameResolver->expects($this->once())->method('getName')->with($this->identicalTo($user))->will($this->returnValue('name1')); $result = $this->manager->getUserCalendars(); $this->assertEquals([['id' => 100, 'name' => 'name1'], ['id' => 200, 'name' => 'name2']], $result); }
/** * @param bool $isNew * * @return array key = calendarUid, value = calendar name */ protected function getChoices($isNew) { $calendars = $this->calendarEventManager->getSystemCalendars(); if ($isNew && count($calendars) === 1) { $calendars[0]['name'] = $this->translator->trans('oro.calendar.add_to_calendar', ['%name%' => $calendars[0]['name']]); } elseif (!$isNew || count($calendars) !== 0) { usort($calendars, function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); $userCalendars = $this->calendarEventManager->getUserCalendars(); foreach ($userCalendars as $userCalendar) { $userCalendar['alias'] = Calendar::CALENDAR_ALIAS; array_unshift($calendars, $userCalendar); } } $choices = []; foreach ($calendars as $calendar) { $alias = !empty($calendar['alias']) ? $calendar['alias'] : ($calendar['public'] ? SystemCalendar::PUBLIC_CALENDAR_ALIAS : SystemCalendar::CALENDAR_ALIAS); $calendarUid = $this->calendarEventManager->getCalendarUid($alias, $calendar['id']); $choices[$calendarUid] = $calendar['name']; } return $choices; }