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(); \TimeSource::mock(2014, 10, 1, 1, 1, 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'); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo = new \repositories\AreaRepository(); $areaRepo->create($area, null, $site, $gb, $user); $venue = new VenueModel(); $venue->setTitle("test"); $venue->setDescription("test test"); $venue->setCountryId($gb->getId()); $venue->setAreaId($area->getId()); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); $venueDuplicate = new VenueModel(); $venueDuplicate->setTitle("test Duplicate"); $venueRepo->create($venueDuplicate, $site, $user); \TimeSource::mock(2014, 10, 1, 1, 2, 0); $venueRepo->markDuplicate($venueDuplicate, $venue, $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->setVenueId($venue->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); ## Test $this->assertNotNull($venueRepo->loadBySlug($site, $venue->getSlug())); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($venue->getId(), $event->getVenueId()); ## Now Purge! $venueRepo->purge($venue); ## Test $this->assertNull($venueRepo->loadBySlug($site, $venue->getSlug())); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertNull($event->getVenueId()); }
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 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 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()); }