function test1() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); ### No areas $this->assertFalse($areaRepo->doesCountryHaveAnyNotDeletedAreas($site, $countryRepo->loadByTwoCharCode('GB'))); ### Area 1 $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area); $this->checkAreaInTest1($areaRepo->loadById($area->getId())); $this->checkAreaInTest1($areaRepo->loadBySlug($site, $area->getSlug())); // no parents. Cache should be empty. $stat = $this->app['db']->prepare("SELECT * FROM cached_area_has_parent"); $stat->execute(); $this->assertEquals(0, $stat->rowCount()); $this->assertTrue($areaRepo->doesCountryHaveAnyNotDeletedAreas($site, $countryRepo->loadByTwoCharCode('GB'))); ### Area child $areaChild = new AreaModel(); $areaChild->setTitle("test child"); $areaChild->setDescription("test test child"); $areaRepo->create($areaChild, $area, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($areaChild); // calling this multiple times should not crash $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $this->checkChildAreaInTest1($areaRepo->loadById($areaChild->getId())); $this->checkChildAreaInTest1($areaRepo->loadBySlug($site, $areaChild->getSlug())); // Check Cache $stat = $this->app['db']->prepare("SELECT * FROM cached_area_has_parent WHERE area_id=" . $areaChild->getId() . " AND has_parent_area_id=" . $area->getId()); $stat->execute(); $this->assertEquals(1, $stat->rowCount()); }
function testFilterAreaAndIncludeAreaAndIncludeVenue() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $userRepo = new UserAccountRepository(); $siteRepo = new SiteRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area); ######################## For now just test it doesn't crash, I commited a bug that did crash here $erb = new EventRepositoryBuilder(); $erb->setArea($area); $erb->setIncludeVenueInformation(true); $erb->setIncludeAreaInformation(true); $erb->fetchAll(); }
function testIntegration1() { $this->addCountriesToTestDB(); \TimeSource::mock(2014, 1, 1, 12, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); ## Create area \TimeSource::mock(2014, 1, 1, 13, 0, 0); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $area->setCountryId($gb->getId()); $areaRepo = new AreaRepository(); $areaRepo->create($area, null, $site, $gb, $user); ## Edit area \TimeSource::mock(2014, 1, 1, 14, 0, 0); $area = $areaRepo->loadById($area->getId()); $area->setDescription("testy"); $areaRepo->edit($area, $user); ## Now save changed flags on these ..... $areaHistoryRepo = new AreaHistoryRepository(); $stat = $this->app['db']->prepare("SELECT * FROM area_history"); $stat->execute(); while ($data = $stat->fetch()) { $areaHistory = new AreaHistoryModel(); $areaHistory->setFromDataBaseRow($data); $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory); } ## Now load and check $historyRepo = new HistoryRepositoryBuilder(); $historyRepo->setIncludeEventHistory(false); $historyRepo->setIncludeVenueHistory(false); $historyRepo->setIncludeGroupHistory(false); $historyRepo->setIncludeAreaHistory(true); $histories = $historyRepo->fetchAll(); $this->assertEquals(2, count($histories)); #the edit $this->assertEquals(FALSE, $histories[0]->getTitleChanged()); $this->assertEquals(true, $histories[0]->getDescriptionChanged()); $this->assertEquals(false, $histories[0]->getCountryIdChanged()); $this->assertEquals(false, $histories[0]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[0]->getIsDeletedChanged()); #the create $this->assertEquals(true, $histories[1]->getTitleChanged()); $this->assertEquals(true, $histories[1]->getDescriptionChanged()); $this->assertEquals(true, $histories[1]->getCountryIdChanged()); $this->assertEquals(false, $histories[1]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[1]->getIsDeletedChanged()); }
function test1() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); \TimeSource::mock(2014, 10, 1, 1, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaDuplicate = new AreaModel(); $areaDuplicate->setTitle("test Duplicate"); $areaRepo->create($areaDuplicate, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); \TimeSource::mock(2014, 10, 1, 2, 0, 0); $areaRepo->markDuplicate($areaDuplicate, $area, $user); $areaChild = new AreaModel(); $areaChild->setTitle("test Child"); $areaRepo->create($areaChild, $area, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $event = new EventModel(); $event->setSummary("test"); $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London')); $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London')); $event->setAreaId($area->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); ## Test $this->assertNotNull($areaRepo->loadById($area->getId())); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($area->getId(), $event->getAreaId()); ## Now Purge! $areaRepo->purge($area); ## Test $this->assertNull($areaRepo->loadById($area->getId())); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertNull($event->getAreaId()); }
function editDetails($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Venue does not exist."); } if ($this->parameters['venue']->getIsDeleted()) { die("No"); // TODO } $form = $app['form.factory']->create(new VenueEditForm($app), $this->parameters['venue']); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $area = null; if (is_array($request->request->get('areas'))) { $areaRepository = new AreaRepository(); $countryRepository = new CountryRepository(); foreach ($request->request->get('areas') as $areaCode) { if (substr($areaCode, 0, 9) == 'EXISTING:') { $area = $areaRepository->loadBySlug($app['currentSite'], substr($areaCode, 9)); } else { if (substr($areaCode, 0, 4) == 'NEW:' && $app['currentUserPermissions']->hasPermission('org.openacalendar', 'AREAS_CHANGE')) { $newArea = new AreaModel(); $newArea->setTitle(substr($areaCode, 4)); $areaRepository->create($newArea, $area, $app['currentSite'], $this->parameters['country'], $app['currentUser']); $areaRepository->buildCacheAreaHasParent($newArea); $area = $newArea; } } } } if ($area) { $this->parameters['venue']->setAreaId($area->getId()); } else { $this->parameters['venue']->setAreaId(null); } foreach ($app['extensions']->getExtensionsIncludingCore() as $extension) { $extension->addDetailsToVenue($this->parameters['venue']); } $venueEditMetaData = new VenueEditMetaDataModel(); $venueEditMetaData->setUserAccount($app['currentUser']); if ($form->has('edit_comment')) { $venueEditMetaData->setEditComment($form->get('edit_comment')->getData()); } $venueEditMetaData->setFromRequest($request); $venueRepository = new VenueRepository(); $venueRepository->editWithMetaData($this->parameters['venue'], $venueEditMetaData); return $app->redirect("/venue/" . $this->parameters['venue']->getSlugForURL()); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/venue/edit.html.twig', $this->parameters); }
function newVenue(Request $request, Application $app) { $areaRepository = new AreaRepository(); $countryRepository = new CountryRepository(); $venue = new VenueModel(); $this->parameters = array('country' => null, 'parentAreas' => array(), 'area' => null, 'childAreas' => array(), 'startAreaBrowserFromScratch' => true); if (isset($_GET['area_id'])) { $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $_GET['area_id']); if ($this->parameters['area']) { $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null; while ($checkArea) { array_unshift($this->parameters['parentAreas'], $checkArea); $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null; } $cr = new CountryRepository(); $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID()); $venue->setCountryId($this->parameters['country']->getId()); $areaRepoBuilder = new AreaRepositoryBuilder(); $areaRepoBuilder->setSite($app['currentSite']); $areaRepoBuilder->setCountry($this->parameters['country']); $areaRepoBuilder->setParentArea($this->parameters['area']); $areaRepoBuilder->setIncludeDeleted(false); $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll(); $this->parameters['startAreaBrowserFromScratch'] = false; } } $form = $app['form.factory']->create(new VenueNewForm($app['currentTimeZone'], $app), $venue); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $postAreas = $request->request->get('areas'); if (is_array($postAreas)) { $area = null; foreach ($postAreas as $areaCode) { if (substr($areaCode, 0, 9) == 'EXISTING:') { $area = $areaRepository->loadBySlug($app['currentSite'], substr($areaCode, 9)); } else { if (substr($areaCode, 0, 4) == 'NEW:' && $app['currentUserPermissions']->hasPermission('org.openacalendar', 'AREAS_CHANGE')) { $newArea = new AreaModel(); $newArea->setTitle(substr($areaCode, 4)); $areaRepository->create($newArea, $area, $app['currentSite'], $countryRepository->loadById($venue->getCountryId()), $app['currentUser']); $areaRepository->buildCacheAreaHasParent($newArea); $area = $newArea; } } } if ($area) { $venue->setAreaId($area->getId()); } } foreach ($app['extensions']->getExtensionsIncludingCore() as $extension) { $extension->addDetailsToVenue($venue); } $venueEditMetaData = new VenueEditMetaDataModel(); $venueEditMetaData->setUserAccount($app['currentUser']); if ($form->has('edit_comment')) { $venueEditMetaData->setEditComment($form->get('edit_comment')->getData()); } $venueRepository = new VenueRepository(); $venueRepository->createWithMetaData($venue, $app['currentSite'], $venueEditMetaData); return $app->redirect("/venue/" . $venue->getSlug()); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/venuenew/new.html.twig', $this->parameters); }
function testUserWatchingParentAreaWithVenue() { TimeSource::mock(2014, 01, 01, 9, 0, 0); $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $userRepo = new UserAccountRepository(); $siteRepo = new SiteRepository(); $venueRepo = new \repositories\VenueRepository(); $eventRepository = new EventRepository(); $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); $GB = $countryRepo->loadByTwoCharCode("GB"); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo->create($user); $userWatchesMain = new UserAccountModel(); $userWatchesMain->setEmail("*****@*****.**"); $userWatchesMain->setUsername("test1"); $userWatchesMain->setPassword("password1"); $userRepo->create($userWatchesMain); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area = new AreaModel(); $area->setTitle("Scotland"); $areaRepo->create($area, null, $site, $GB); $areaChild = new AreaModel(); $areaChild->setTitle("Edinburgh"); $areaRepo->create($areaChild, $area, $site, $GB); $venue = new \models\VenueModel(); $venue->setTitle("Castle"); $venue->setAreaId($areaChild->getId()); $venueRepo->create($venue, $site, $user); $event = new EventModel(); $event->setSummary("test"); $event->setDescription("test test"); $event->setStartAt(getUTCDateTime(2014, 11, 10, 19, 0, 0)); $event->setEndAt(getUTCDateTime(2014, 11, 10, 21, 0, 0)); $eventRepository->create($event, $site, $user); $event->setVenueId($venue->getId()); TimeSource::mock(2014, 01, 01, 9, 1, 0); $eventRepository->edit($event); // have to update child cache $areaRepo->buildCacheAreaHasParent($area); $areaRepo->buildCacheAreaHasParent($areaChild); // test before $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, false); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); // test watching main group gets event $userWatchesAreaRepo->startUserWatchingArea($userWatchesMain, $area); $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, false); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); }
function newArea($countryslug, Request $request, Application $app) { if (!$this->build($countryslug, $request, $app)) { $app->abort(404, "country does not exist."); } $areaRepository = new AreaRepository(); $parentArea = null; $parentAreas = array(); if (isset($_GET['parentAreaSlug'])) { $parentArea = $areaRepository->loadBySlugAndCountry($app['currentSite'], $_GET['parentAreaSlug'], $this->parameters['country']); // build parent tree, including this area $checkArea = $parentArea; while ($checkArea) { array_unshift($parentAreas, $checkArea); $checkArea = $checkArea->getParentAreaId() ? $areaRepository->loadById($checkArea->getParentAreaId()) : null; } } $area = new AreaModel(); $form = $parentArea ? $app['form.factory']->create(new AreaNewInAreaForm(), $area) : $app['form.factory']->create(new AreaNewInCountryForm(), $area); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $areaRepository->create($area, $parentArea, $app['currentSite'], $this->parameters['country'], $app['currentUser']); $areaRepository->buildCacheAreaHasParent($area); return $app->redirect("/admin/areas/" . $this->parameters['country']->getTwoCharCode()); } } $this->parameters['parentAreas'] = $parentAreas; $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/adminareas/newarea.html.twig', $this->parameters); }
function testBasicThenDeletedByVanishing() { global $CONFIG; \TimeSource::mock(2013, 10, 1, 1, 1, 1); $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000; // 90 days $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $areaRepo = new AreaRepository(); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $importURL = new ImportURLModel(); $importURL->setIsEnabled(true); $importURL->setSiteId($site->getId()); $importURL->setGroupId($group->getId()); $importURL->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId()); $importURL->setAreaId($area->getId()); $importURL->setTitle("Test"); $importURL->setUrl("http://test.com"); $importURLRepository->create($importURL, $site, $user); // Import $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/BasicICAL.ical'); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Load! $erb = new EventRepositoryBuilder(); $erb->setSite($site); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $event = $events[0]; $this->assertEquals("Test 3 SpecFic Writing Group", $event->getSummary()); $this->assertEquals('2013-11-12 18:00:00', $event->getStartAtInUTC()->format('Y-m-d H:i:s')); $this->assertEquals('2013-11-12 20:30:00', $event->getEndAtInUTC()->format('Y-m-d H:i:s')); $this->assertEquals('http://opentechcalendar.co.uk/index.php/event/166', $event->getDescription()); $this->assertEquals('http://opentechcalendar.co.uk/index.php/event/166', $event->getURL()); $this->assertFalse($event->getIsDeleted()); $this->assertEquals($countryRepo->loadByTwoCharCode('GB')->getId(), $event->getCountryId()); $this->assertEquals($area->getId(), $event->getAreaId()); $this->assertEquals("Europe/London", $event->getTimezone()); // Import again \TimeSource::mock(2013, 10, 1, 1, 1, 2); $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/BasicICALNoEvents.ical'); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Load! $erb = new EventRepositoryBuilder(); $erb->setSite($site); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $event = $events[0]; $this->assertTrue($event->getIsDeleted()); }
function testInChildArea() { $this->addCountriesToTestDB(); TimeSource::mock(2013, 7, 1, 7, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $area1 = new AreaModel(); $area1->setTitle("scotland"); $area1child = new AreaModel(); $area1child->setTitle("edinburgh"); $area2 = new AreaModel(); $area2->setTitle("england"); $areaRepo = new AreaRepository(); $countryRepo = new CountryRepository(); $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area1); $areaRepo->create($area1child, $area1, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area1child); $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area2); $event = new EventModel(); $event->setSummary("test"); $event->setDescription("test test"); $event->setStartAt($this->mktime(2013, 8, 1, 19, 0, 0)); $event->setEndAt($this->mktime(2013, 8, 1, 21, 0, 0)); $event->setAreaId($area1child->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); #test - find in erb $erb = new EventRepositoryBuilder(); $erb->setSite($site); $erb->setArea($area1); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $this->assertEquals($event->getId(), $events[0]->getId()); #test - find in erb $erb = new EventRepositoryBuilder(); $erb->setSite($site); $erb->setArea($area1child); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $this->assertEquals($event->getId(), $events[0]->getId()); #test - don't find in erb $erb = new EventRepositoryBuilder(); $erb->setSite($site); $erb->setArea($area2); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); }
function test1() { \TimeSource::mock(2014, 1, 1, 0, 0, 0); $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area1 = new AreaModel(); $area1->setTitle("test"); $area1->setDescription("test test"); $area2 = new AreaModel(); $area2->setTitle("test this looks similar"); $area2->setDescription("test test"); $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaChild = new AreaModel(); $areaChild->setTitle("child"); $areaChild->setDescription("child"); $areaRepo->create($areaChild, $area2, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $area1 = $areaRepo->loadById($area1->getId()); $area2 = $areaRepo->loadById($area2->getId()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); $venue = new VenueModel(); $venue->setTitle("test"); $venue->setDescription("test test"); $venue->setCountryId($gb->getId()); $venue->setAreaId($area2->getId()); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); $event = new EventModel(); $event->setSummary("test"); $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0)); $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0)); $event->setAreaId($area2->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); // Test before $venue = $venueRepo->loadById($venue->getId()); $this->assertEquals($area2->getId(), $venue->getAreaId()); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($area2->getId(), $event->getAreaId()); $areaChild = $areaRepo->loadById($areaChild->getId()); $this->assertEquals($area2->getId(), $areaChild->getParentAreaId()); $area2 = $areaRepo->loadById($area2->getId()); $this->assertFalse($area2->getIsDeleted()); $this->assertNull($area2->getIsDuplicateOfId()); // Mark \TimeSource::mock(2014, 1, 1, 2, 0, 0); $areaRepo->markDuplicate($area2, $area1, $user); // Test Duplicate $venue = $venueRepo->loadById($venue->getId()); $this->assertEquals($area1->getId(), $venue->getAreaId()); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($area1->getId(), $event->getAreaId()); $areaChild = $areaRepo->loadById($areaChild->getId()); $this->assertEquals($area1->getId(), $areaChild->getParentAreaId()); $area2 = $areaRepo->loadById($area2->getId()); $this->assertTrue($area2->getIsDeleted()); $this->assertEquals($area1->getId(), $area2->getIsDuplicateOfId()); }
function testMoveAllFutureEventsAtVenueToNoSetVenue() { $this->addCountriesToTestDB(); TimeSource::mock(2013, 7, 1, 7, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $area = new AreaModel(); $area->setTitle("scotland"); $areaRepo = new AreaRepository(); $countryRepo = new CountryRepository(); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $venue = new VenueModel(); $venue->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId()); $venue->setTitle("edinburgh hall"); $venue->setAreaId($area->getId()); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); #### Event To Change $event = new EventModel(); $event->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId()); $event->setSummary("test"); $event->setDescription("test test"); $event->setStartAt($this->mktime(2013, 8, 1, 19, 0, 0)); $event->setEndAt($this->mktime(2013, 8, 1, 21, 0, 0)); $event->setVenueId($venue->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); #### Load Event, Check in Venue $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals(false, $event->getIsDeleted()); $this->assertNull($event->getAreaId()); $this->assertEquals($venue->getId(), $event->getVenueId()); #### In preperation for deleting event, call moveAllFutureEventsAtVenueToNoSetVenue() TimeSource::mock(2013, 7, 1, 8, 0, 0); $eventRepository->moveAllFutureEventsAtVenueToNoSetVenue($venue, $user); #### Load event, check in area $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals(false, $event->getIsDeleted()); $this->assertNull($event->getVenueId()); $this->assertEquals($area->getId(), $event->getAreaId()); }
function newArea($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Area does not exist."); } $area = new AreaModel(); $form = $app['form.factory']->create(new AreaNewInAreaForm(), $area); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $areaRepository = new AreaRepository(); $areaRepository->create($area, $this->parameters['area'], $app['currentSite'], $this->parameters['country'], $app['currentUser']); $areaRepository->buildCacheAreaHasParent($area); return $app->redirect("/area/" . $area->getSlug()); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/area/newarea.html.twig', $this->parameters); }