/**
  * @expectedException \Oro\Bundle\SecurityBundle\Exception\ForbiddenException
  * @expectedExceptionMessage Access denied.
  */
 public function testHandleDeleteWhenPublicCalendarDeleteNotGranted()
 {
     $calendar = new SystemCalendar();
     $calendar->setPublic(true);
     $this->manager->expects($this->once())->method('find')->will($this->returnValue($calendar));
     $this->calendarConfig->expects($this->once())->method('isPublicCalendarEnabled')->will($this->returnValue(true));
     $this->securityFacade->expects($this->once())->method('isGranted')->with('oro_public_calendar_management')->will($this->returnValue(false));
     $this->handler->handleDelete(1, $this->manager);
 }
Example #2
0
 /**
  * Test update of system calendar
  */
 public function testPreUpdateSystemCalendar()
 {
     $organization = new Organization();
     $entity = new SystemCalendar();
     $this->assertNull($entity->getOrganization());
     $changeSet = [];
     $args = new PreUpdateEventArgs($entity, $this->em, $changeSet);
     $token = new UsernamePasswordOrganizationToken(new User(), 'admin', 'key', $organization);
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $this->listener->preUpdate($args);
     $this->assertSame($organization, $entity->getOrganization());
 }
Example #3
0
 public function testSetOrganizationForPublic()
 {
     $obj = new SystemCalendar();
     $obj->setPublic(true);
     $this->assertTrue($obj->isPublic());
     $this->assertNull($obj->getOrganization());
     $obj->setOrganization(new Organization());
     $this->assertNull($obj->getOrganization());
 }
Example #4
0
 /**
  * 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 SystemCalendar $entity
  *
  * @throws NotFoundHttpException
  */
 protected function checkPermissionByConfig(SystemCalendar $entity)
 {
     if ($entity->isPublic()) {
         if (!$this->getCalendarConfig()->isPublicCalendarEnabled()) {
             throw $this->createNotFoundException('Public calendars are disabled.');
         }
     } else {
         if (!$this->getCalendarConfig()->isSystemCalendarEnabled()) {
             throw $this->createNotFoundException('System calendars are disabled.');
         }
     }
 }
 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());
 }