예제 #1
0
 /**
  * Gets calendars connected to the given calendar
  *
  * @param int $organizationId The id of an organization for which this information is requested
  * @param int $userId         The id of an user requested this information
  * @param int $calendarId     The target calendar id
  *
  * @return array
  */
 public function getCalendars($organizationId, $userId, $calendarId)
 {
     // make sure input parameters have proper types
     $userId = (int) $userId;
     $calendarId = (int) $calendarId;
     $result = $this->calendarPropertyProvider->getItems($calendarId);
     $existing = [];
     foreach ($result as $key => $item) {
         $existing[$item['calendarAlias']][$item['calendar']] = $key;
     }
     foreach ($this->providers as $alias => $provider) {
         $calendarIds = isset($existing[$alias]) ? array_keys($existing[$alias]) : [];
         $calendarDefaultValues = $provider->getCalendarDefaultValues($organizationId, $userId, $calendarId, $calendarIds);
         foreach ($calendarDefaultValues as $id => $values) {
             if (isset($existing[$alias][$id])) {
                 $key = $existing[$alias][$id];
                 if ($values !== null) {
                     $calendar = $result[$key];
                     $this->applyCalendarDefaultValues($calendar, $values);
                     $result[$key] = $calendar;
                 } else {
                     unset($result[$key]);
                 }
             } else {
                 $values['targetCalendar'] = $calendarId;
                 $values['calendarAlias'] = $alias;
                 $values['calendar'] = $id;
                 $result[] = $values;
             }
         }
     }
     $this->normalizeCalendarData($result);
     return $result;
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItems()
 {
     $calendarId = 123;
     $fieldConfigs = [$this->getFieldConfig('id', 'integer'), $this->getFieldConfig('targetCalendar', 'ref-one'), $this->getFieldConfig('visible', 'boolean'), $this->getFieldConfig('enum', 'enum')];
     $items = [['id' => 1, 'targetCalendar' => '123', 'visible' => true, 'enum' => 'opt1']];
     $this->configManager->expects($this->once())->method('getConfigs')->with('extend', CalendarPropertyProvider::CALENDAR_PROPERTY_CLASS)->will($this->returnValue($fieldConfigs));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityMetadata')->with(CalendarPropertyProvider::CALENDAR_PROPERTY_CLASS)->will($this->returnValue($metadata));
     $metadata->expects($this->exactly(2))->method('hasAssociation')->will($this->returnValueMap([['targetCalendar', true], ['enum', true]]));
     $metadata->expects($this->exactly(2))->method('getAssociationTargetClass')->will($this->returnValueMap([['targetCalendar', 'Oro\\Bundle\\CalendarBundle\\Entity\\Calendar'], ['enum', 'Test\\Enum']]));
     $this->doctrineHelper->expects($this->exactly(2))->method('getSingleEntityIdentifierFieldType')->will($this->returnValueMap([['Oro\\Bundle\\CalendarBundle\\Entity\\Calendar', false, 'integer'], ['Test\\Enum', false, 'string']]));
     $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with(CalendarPropertyProvider::CALENDAR_PROPERTY_CLASS)->will($this->returnValue($repo));
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $repo->expects($this->once())->method('createQueryBuilder')->with('o')->will($this->returnValue($qb));
     $qb->expects($this->once())->method('select')->with('o.id,IDENTITY(o.targetCalendar) AS targetCalendar,o.visible,IDENTITY(o.enum) AS enum')->will($this->returnSelf());
     $qb->expects($this->once())->method('where')->with('o.targetCalendar = :calendar_id')->will($this->returnSelf());
     $qb->expects($this->once())->method('setParameter')->with('calendar_id', $calendarId)->will($this->returnSelf());
     $qb->expects($this->once())->method('orderBy')->with('o.id')->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($items));
     $result = $this->provider->getItems($calendarId);
     $this->assertSame([['id' => 1, 'targetCalendar' => 123, 'visible' => true, 'enum' => 'opt1']], $result);
 }