Ejemplo n.º 1
0
 public function testName()
 {
     $withoutName = new Place();
     $this->assertSame([], $withoutName->getName());
     $withName = new Place(['fr' => 'test name']);
     $this->assertSame(['fr' => 'test name'], $withName->getName());
 }
Ejemplo n.º 2
0
 public function testPlaceRelation()
 {
     $place = new Place();
     $image = new Image();
     $this->assertCount(0, $place->getImages());
     $this->assertNull($image->getPlace());
     $image->setPlace($place);
     $this->assertSame($place, $image->getPlace());
     $this->assertSame($image, $place->getImages()[0]);
 }
Ejemplo n.º 3
0
 public function testCanSaveLocationInDatabase()
 {
     $location = new \CrEOF\Spatial\PHP\Types\Geography\Point(151.2094, 33.865, 4326);
     $place = new Place(['fr' => 'test place']);
     $place->setLocation($location);
     $this->getEntityManager()->persist($place);
     $this->getEntityManager()->flush();
     // Test we can reload
     $this->getEntityManager()->clear();
     $placeRepository = $this->getEntityManager()->getRepository(Place::class);
     $reloadedPlace = $placeRepository->findOneById($place->getId());
     $reloadedLocation = $reloadedPlace->getLocation();
     $this->assertSame($location->getX(), $reloadedLocation->getX());
     $this->assertSame($location->getY(), $reloadedLocation->getY());
 }
Ejemplo n.º 4
0
 public function testUserRelation()
 {
     $userPlace = new UserPlace();
     $user = new User();
     $place = new Place();
     $this->assertCount(0, $user->getUserPlaces(), 'collection is initialized on creation');
     $this->assertCount(0, $place->getUserPlaces(), 'collection is initialized on creation');
     $this->assertCount(0, $place->getUsers(), 'collection is initialized on creation');
     $userPlace->setUser($user);
     $userPlace->setPlace($place);
     $this->assertCount(1, $user->getUserPlaces(), 'user must be notified when userPlace is added');
     $this->assertSame($userPlace, $user->getUserPlaces()->first(), 'original userPlace can be retrieved from user');
     $this->assertCount(1, $place->getUserPlaces(), 'place must be notified when userPlace is added');
     $this->assertSame($userPlace, $place->getUserPlaces()->first(), 'original userPlace can be retrieved from place');
     $this->assertCount(1, $place->getUsers(), 'the user must now be the only one directly accessible');
     $this->assertSame($user, $place->getUsers()->first(), 'the user must be directly accessible');
 }
Ejemplo n.º 5
0
 public function testStuff()
 {
     $entityManagerMock = $this->getMock(\Doctrine\ORM\EntityManager::class, ['persist', 'flush'], [], '', false);
     $importer = new Importer();
     $importer->setEntityManager($entityManagerMock);
     $calendar = new Calendar();
     $calendar->setUrl('tests/data/calendar.ics');
     $importer->import($calendar);
     $place = new Place(['fr' => 'The Rock, Zamzibar']);
     $place->setLocation(new \CrEOF\Spatial\PHP\Types\Geography\Point(39.519313, -6.152079));
     $calendar->setPlace($place);
     $renderer = new CalendarRenderer();
     $viewModel = new CalendarModel($calendar);
     $actual = $renderer->render($viewModel);
     // Log actual result for easier comparison when debugging
     @mkdir('logs/tests');
     file_put_contents('logs/tests/export.ics', $actual);
     $expected = file_get_contents('tests/data/export.ics');
     $this->assertSame($expected, $actual);
 }
Ejemplo n.º 6
0
 /**
  * Render an event as vevent
  * @param VCalendar $vcalendar
  * @param Event $event
  * @param Place $place
  */
 private function renderEvent(VCalendar $vcalendar, Event $event, Place $place = null)
 {
     $vevent = $vcalendar->add('VEVENT', [], false);
     $this->addDate($event, $vevent, 'DTSTART', $event->getStart());
     $this->addDate($event, $vevent, 'DTEND', $event->getEnd());
     $properties = [];
     $properties['DTSTAMP'] = ['type' => 'DATE-TIME', 'value' => Utility::getNow()];
     $properties['UID'] = ['type' => 'UNKNOWN', 'value' => $event->getUid()];
     $properties['DESCRIPTION'] = ['type' => 'UNKNOWN', 'value' => $event->getDescription()];
     $properties['SUMMARY'] = ['type' => 'UNKNOWN', 'value' => $event->getName()];
     if ($place) {
         $properties['LOCATION'] = ['type' => 'UNKNOWN', 'value' => $place->getName()];
         $properties['GEO'] = ['type' => 'UNKNOWN', 'value' => $place->getLocation()->getLatitude() . ';' . $place->getLocation()->getLongitude()];
     }
     $allProperties = array_merge($properties, $event->getExtra());
     foreach ($allProperties as $key => $val) {
         $prop = $vevent->add($key, $val['value']);
         if ($val['type'] === 'DATE') {
             $prop['VALUE'] = $val['type'];
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Returns place
  * @return self
  */
 public function setPlace(Place $place)
 {
     $this->place = $place;
     $place->userPlaceAdded($this);
     return $this;
 }