function test1()
 {
     TimeSource::mock(2014, 5, 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());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventDupe = new EventModel();
     $eventDupe->setSummary("test");
     $eventDupe->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $eventDupe->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     $eventRepository->create($eventDupe, $site, $user, $group);
     TimeSource::mock(2014, 5, 1, 7, 1, 0);
     $eventRepository->markDuplicate($eventDupe, $event);
     $userAtEvent = new \models\UserAtEventModel();
     $userAtEvent->setEventId($event->getId());
     $userAtEvent->setUserAccountId($user->getId());
     $userAtEvent->setIsPlanAttending(true);
     $userAtEventRepo = new \repositories\UserAtEventRepository();
     $userAtEventRepo->create($userAtEvent);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $tag = new TagModel();
     $tag->setTitle("Test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     $tagRepo->addTagToEvent($tag, $event, $user);
     ## TEST
     $this->assertNotNull($eventRepository->loadBySlug($site, $event->getSlug()));
     ## PURGE!
     $eventRepository->purge($event);
     ## TEST
     $this->assertNull($eventRepository->loadBySlug($site, $event->getSlug()));
 }
 function test1()
 {
     $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());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $this->checkGroupInTest1($groupRepo->loadById($group->getId()));
     $this->checkGroupInTest1($groupRepo->loadBySlug($site, $group->getSlug()));
     $grb = new GroupRepositoryBuilder();
     $grb->setFreeTextsearch('test');
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setFreeTextsearch('cats');
     $this->assertEquals(0, count($grb->fetchAll()));
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $user1 = new UserAccountModel();
     $user1->setEmail("*****@*****.**");
     $user1->setUsername("test");
     $user1->setPassword("password");
     $user2 = new UserAccountModel();
     $user2->setEmail("*****@*****.**");
     $user2->setUsername("test2");
     $user2->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user1);
     $userRepo->create($user2);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user1, array(), $this->getSiteQuotaUsedForTesting());
     $group1 = new GroupModel();
     $group1->setTitle("test1");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("test this looks similar");
     $group2->setDescription("test test");
     $group2->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $groupRepo->create($group1, $site, $user1);
     $groupRepo->create($group2, $site, $user2);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user1, $group2);
     $uwgr = new UserWatchesGroupRepository();
     // Test before
     $erb = new \repositories\builders\EventRepositoryBuilder();
     $erb->setGroup($group1);
     $this->assertEquals(0, count($erb->fetchAll()));
     $this->assertNull($uwgr->loadByUserAndGroup($user2, $group1));
     $group2 = $groupRepo->loadById($group2->getId());
     $this->assertFalse($group2->getIsDeleted());
     $this->assertNull($group2->getIsDuplicateOfId());
     // Mark
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $groupRepo->markDuplicate($group2, $group1, $user1);
     // Test Duplicate
     $erb = new \repositories\builders\EventRepositoryBuilder();
     $erb->setGroup($group1);
     $this->assertEquals(1, count($erb->fetchAll()));
     $uwg = $uwgr->loadByUserAndGroup($user2, $group1);
     $this->assertNotNull($uwg);
     $group2 = $groupRepo->loadById($group2->getId());
     $this->assertTrue($group2->getIsDeleted());
     $this->assertEquals($group1->getId(), $group2->getIsDuplicateOfId());
 }
 function testIntegration1()
 {
     \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());
     ## Create group
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     ## Edit group
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $group = $groupRepo->loadById($group->getId());
     $group->setTwitterUsername("testy");
     $groupRepo->edit($group, $user);
     ## Now save changed flags on these .....
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setGroup($group);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getUrlChanged());
     $this->assertEquals(true, $histories[0]->getTwitterUsernameChanged());
     $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]->getUrlChanged());
     $this->assertEquals(false, $histories[1]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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());
     $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->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Lanyrd1.ical');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $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("State of the Map Scotland 2013", $event->getSummary());
     $this->assertEquals('2013-10-11 00:00:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-14 23:59:59', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals("http://sotms.eventbrite.com/\n\nhttp://lanyrd.com/crkmt", $event->getDescription());
     $this->assertEquals('http://lanyrd.com/2013/sotmscot2013/', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
     // Look for event
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setImportURL($importURL);
     $this->assertEquals(1, count($erb->fetchAll()));
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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());
     $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->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Eventbrite1.ical');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $importURLRun->setFlag(ImportURLRun::$FLAG_SET_TICKET_URL_AS_URL);
     $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("Computing At School Scotland Conference 2013", $event->getSummary());
     $this->assertEquals('2013-10-26 07:30:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-26 16:00:00', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('For details, click here: https://casscot13.eventbrite.co.uk', $event->getDescription());
     $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getURL());
     $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getTicketURL());
     $this->assertFalse($event->getIsDeleted());
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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());
     $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->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Meetup1.ics');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $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("Talk & Build AngularJS", $event->getSummary());
     $this->assertEquals('2013-10-17 18:00:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-17 21:00:00', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals("AngularJS - Edinburgh\nThursday, October 17 at 7:00 PM\n\nDetails: http://www.meetup.com/AngularJS-Edinburgh/events/141654792/", $event->getDescription());
     $this->assertEquals('http://www.meetup.com/AngularJS-Edinburgh/events/141654792/', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
 }
 function testEventAndNotEvent1()
 {
     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());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 8, 1, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $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);
     ## Test event not in group
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
     ## Add event to group, test
     $groupRepo->addEventToGroup($event, $group, $user);
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     ## remove event from group
     $groupRepo->removeEventFromGroup($event, $group, $user);
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
 }
 function testMultiple()
 {
     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());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupDupe = new GroupModel();
     $groupDupe->setTitle("test DUPE");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $groupRepo->create($groupDupe, $site, $user);
     TimeSource::mock(2013, 7, 1, 7, 1, 0);
     $groupRepo->markDuplicate($groupDupe, $group);
     $ufgr = new UserWatchesGroupRepository();
     $ufgr->startUserWatchingGroupIdIfNotWatchedBefore($user, $group->getId());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 8, 1, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     ## TEST
     $this->assertNotNull($groupRepo->loadById($group->getId()));
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($event);
     $groups = $groupRB->fetchAll();
     $this->assertEquals(1, count($groups));
     ## PURGE!
     $groupRepo->purge($group);
     ## TEST
     $this->assertNull($groupRepo->loadById($group->getId()));
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($event);
     $groups = $groupRB->fetchAll();
     $this->assertEquals(0, count($groups));
 }
 function test1()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userOther = new UserAccountModel();
     $userOther->setEmail("*****@*****.**");
     $userOther->setUsername("test2");
     $userOther->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userOther);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEditorToCuratedList($userOther, $curatedList, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group, $curatedList, $user);
     ## Test
     $this->assertNotNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
     ## Purge!
     $clRepo->purge($curatedList);
     ## Test
     $this->assertNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
 }
 function test1()
 {
     $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());
     $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();
     $newImportURL = new ImportURLModel();
     $newImportURL->setIsEnabled(true);
     $newImportURL->setSiteId($site->getId());
     $newImportURL->setGroupId($group->getId());
     $newImportURL->setTitle("Test");
     $newImportURL->setUrl("http://test.com");
     # no clash
     $clash = $importURLRepository->loadClashForImportUrl($newImportURL);
     $this->assertNull($clash);
     # save import, now clash!
     $importURLRepository->create($newImportURL, $site, $user);
     $newImportURL2 = new ImportURLModel();
     $newImportURL2->setIsEnabled(true);
     $newImportURL2->setSiteId($site->getId());
     $newImportURL2->setGroupId($group->getId());
     $newImportURL2->setTitle("Test.com site");
     $newImportURL2->setUrl("http://TEST.com");
     # no clash
     $clash = $importURLRepository->loadClashForImportUrl($newImportURL2);
     $this->assertTrue($clash != null);
 }
 function testMultiple()
 {
     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());
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("cat");
     $group2->setDescription("cat cat");
     $group2->setUrl("http://www.cat.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $site, $user);
     $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group1, array($group1, $group2));
     // Check groups
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($event);
     $groups = $groupRB->fetchAll();
     $this->assertEquals(2, count($groups));
 }
 function testAddSet()
 {
     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());
     $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("test2");
     $group2->setDescription("test 2");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $site, $user);
     ## Add event to group1, test
     $groupRepo->addEventToGroup($event, $group1, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group1->getId(), $event->getGroupId());
     $this->assertEquals("test", $event->getGroupTitle());
     ## Add event to group2, test group1 is still main group
     $groupRepo->addEventToGroup($event, $group2, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group1->getId(), $event->getGroupId());
     $this->assertEquals("test", $event->getGroupTitle());
     ## set main group to group2, test
     $groupRepo->setMainGroupForEvent($group2, $event, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group2->getId(), $event->getGroupId());
     $this->assertEquals("test2", $event->getGroupTitle());
 }
 function testRRuleDeleteByExDate1()
 {
     global $CONFIG;
     \TimeSource::mock(2015, 1, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 77760000;
     $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());
     $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->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // ============================================= Import CREATE
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part1.ics');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(7);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Is it loaded on Imported Events?
     $ierb = new \repositories\builders\ImportedEventRepositoryBuilder();
     $importedEvents = $ierb->fetchAll();
     $this->assertEquals(1, count($importedEvents));
     $importedEvent = $importedEvents[0];
     $reoccur = $importedEvent->getReoccur();
     $this->assertEquals(true, is_array($reoccur));
     $this->assertEquals(true, isset($reoccur['ical_rrule']));
     $this->assertEquals(true, is_array($reoccur['ical_rrule']));
     $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]);
     $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]);
     // now test real events
     $erb = new EventRepositoryBuilder();
     $erb->setImportedEvent($importedEvent);
     $erb->setAfterNow();
     $events = $erb->fetchAll();
     $this->assertTrue(count($events) > 5);
     $event = $events[0];
     $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[1];
     $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[2];
     $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     \TimeSource::mock(2015, 1, 2, 1, 1, 1);
     // ============================================= Import With no changes
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part1.ics');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(7);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Is it loaded on Imported Events?
     $ierb = new \repositories\builders\ImportedEventRepositoryBuilder();
     $importedEvents = $ierb->fetchAll();
     $this->assertEquals(1, count($importedEvents));
     $importedEvent = $importedEvents[0];
     $reoccur = $importedEvent->getReoccur();
     $this->assertEquals(true, is_array($reoccur));
     $this->assertEquals(true, isset($reoccur['ical_rrule']));
     $this->assertEquals(true, is_array($reoccur['ical_rrule']));
     $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]);
     $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]);
     // now test real events
     $erb = new EventRepositoryBuilder();
     $erb->setImportedEvent($importedEvent);
     $erb->setAfterNow();
     $events = $erb->fetchAll();
     $this->assertTrue(count($events) > 5);
     $event = $events[0];
     $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[1];
     $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[2];
     $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     \TimeSource::mock(2015, 1, 3, 1, 1, 1);
     // ============================================= Import WITH ONE DELETED!
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part2.ics');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(7);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Is it loaded on Imported Events?
     $ierb = new \repositories\builders\ImportedEventRepositoryBuilder();
     $importedEvents = $ierb->fetchAll();
     $this->assertEquals(1, count($importedEvents));
     $importedEvent = $importedEvents[0];
     $reoccur = $importedEvent->getReoccur();
     $this->assertEquals(true, is_array($reoccur));
     $this->assertEquals(true, isset($reoccur['ical_rrule']));
     $this->assertEquals(true, is_array($reoccur['ical_rrule']));
     $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]);
     $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]);
     // now test real events
     $erb = new EventRepositoryBuilder();
     $erb->setImportedEvent($importedEvent);
     $erb->setAfterNow();
     $erb->setIncludeDeleted(true);
     $events = $erb->fetchAll();
     $this->assertTrue(count($events) > 5);
     $event = $events[0];
     $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[1];
     $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertTrue($event->getIsDeleted());
     $event = $events[2];
     $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
 }
 function testGroup()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     TimeSource::mock(2013, 7, 1, 7, 0, 0);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $this->assertTrue($userRepo->hasMadeAnyEdits($user));
 }
 function testLimits()
 {
     global $CONFIG;
     \TimeSource::mock(2012, 9, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 77760000;
     $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());
     $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->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ICALManyEvents.ical');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(2);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(2, count($events));
 }
 function testNotExists1()
 {
     $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());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event1 = new EventModel();
     $event1->setGroup($group);
     $event1->setStartAt($this->mktime(2013, 8, 1, 19, 0, 0));
     $event1->setEndAt($this->mktime(2013, 8, 1, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event1, $site, $user);
     $eventProposed = new EventModel();
     $eventProposed->setGroup($group);
     $eventProposed->setStartAt($this->mktime(2013, 8, 2, 19, 0, 0));
     $eventProposed->setEndAt($this->mktime(2013, 8, 2, 21, 0, 0));
     $ersm = new EventRecurSetModel();
     $events = $ersm->filterEventsForExisting($event1, array($eventProposed));
     $this->assertEquals(1, count($events));
 }
 function testIsGroupRunningOutOfFutureEvents()
 {
     \TimeSource::mock(2014, 1, 1, 1, 1, 1);
     $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");
     $site->setPromptEmailsDaysInAdvance(28);
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 4, 1, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 4, 1, 21, 0, 0, 'Europe/London'));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     ### TEST
     \TimeSource::mock(2014, 2, 1, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 2, 15, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 1, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 2, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 3, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 4, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 5, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 6, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 7, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 20, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 4, 1, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 4, 15, 1, 1, 1);
     $this->assertEquals(2, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 5, 1, 1, 1, 1);
     $this->assertEquals(2, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
 }
 function test3()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userOwner = new UserAccountModel();
     $userOwner->setEmail("*****@*****.**");
     $userOwner->setUsername("test2");
     $userOwner->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userOwner);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $userOwner, array(), $this->getSiteQuotaUsedForTesting());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $userOwner);
     $userWatchesgroupRepo = new UserWatchesGroupRepository();
     # Part 1: User does not watch group
     $t = $userWatchesgroupRepo->loadByUserAndGroup($user, $group);
     $this->assertNull($t);
     $b = new UserWatchesGroupRepositoryBuilder();
     $b->setGroup($group);
     $b->setUser($user);
     $t = $b->fetchAll();
     $this->assertEquals(0, count($t));
     # Part 2: Watches if not watched before!
     $userWatchesgroupRepo->startUserWatchingGroupIfNotWatchedBefore($user, $group);
     $t = $userWatchesgroupRepo->loadByUserAndGroup($user, $group);
     $this->assertEquals($user->getId(), $t->getUserAccountId());
     $this->assertEquals(true, $t->getIsWatching());
     $this->assertEquals(true, $t->getIsWasOnceWatching());
     $b = new UserWatchesGroupRepositoryBuilder();
     $b->setGroup($group);
     $b->setUser($user);
     $t = $b->fetchAll();
     $this->assertEquals(1, count($t));
     # Part 3: Stops Watching!
     $userWatchesgroupRepo->stopUserWatchingGroup($user, $group);
     $t = $userWatchesgroupRepo->loadByUserAndGroup($user, $group);
     $this->assertEquals(false, $t->getIsWatching());
     $this->assertEquals(true, $t->getIsWasOnceWatching());
     $b = new UserWatchesGroupRepositoryBuilder();
     $b->setGroup($group);
     $b->setUser($user);
     $t = $b->fetchAll();
     $this->assertEquals(0, count($t));
     # Part 4: Watches if not watched before! As they have watched before, nothing happens
     $userWatchesgroupRepo->startUserWatchingGroupIfNotWatchedBefore($user, $group);
     $t = $userWatchesgroupRepo->loadByUserAndGroup($user, $group);
     $this->assertEquals(false, $t->getIsWatching());
     $this->assertEquals(true, $t->getIsWasOnceWatching());
     $b = new UserWatchesGroupRepositoryBuilder();
     $b->setGroup($group);
     $b->setUser($user);
     $t = $b->fetchAll();
     $this->assertEquals(0, count($t));
 }
 function testEventInTwoGroupsAddedDirectlyThenOneGroupAdded()
 {
     TimeSource::mock(2014, 5, 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());
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("I don't need no stinking tests");
     $group2->setDescription("works first time");
     $group2->setUrl("http://www.soveryperfect.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group1, array($group2));
     // Test Before
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->isEventInListViaGroup());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     // Add group to list
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group1, $curatedList, $user);
     // Test After
     // .... we don't ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertFalse($eventWithInfo->getIsEventInCuratedList());
     // .... we Do ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList, true);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertEquals($group1->getId(), $eventWithInfo->getInCuratedListGroupId());
     $this->assertEquals($group1->getSlug(), $eventWithInfo->getInCuratedListGroupSlug());
     $this->assertEquals($group1->getTitle(), $eventWithInfo->getInCuratedListGroupTitle());
     $this->assertTrue($eventWithInfo->getIsEventInCuratedList());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->isEventInListViaGroup());
     $this->assertEquals($group1->getId(), $curatedListWithInfo->getEventInListViaGroupId());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     // Remove group from list
     TimeSource::mock(2014, 5, 1, 9, 0, 0);
     $clRepo->removeGroupFromCuratedList($group1, $curatedList, $user);
     $clRepo->removeEventFromCuratedList($event, $curatedList, $user);
     // Test After
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->isEventInListViaGroup());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
 }
    function testSetCountryAndTimeZone()
    {
        \TimeSource::mock(2014, 06, 01, 00, 00, 00);
        $this->addCountriesToTestDB();
        $countryRepo = new CountryRepository();
        $country = $countryRepo->loadByTwoCharCode("DE");
        $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());
        $group = new GroupModel();
        $group->setTitle("test");
        $group->setDescription("test test");
        $group->setUrl("http://www.group.com");
        $groupRepo = new GroupRepository();
        $groupRepo->create($group, $site, $user);
        $json = json_decode('{
	"event":{
		"summary":"Test",
		"description":"test test test",
		"url":"http://example.com",
		"start":{
			"str":"2014-07-01 10:00:00"
		},
		"end":{
			"str":"2014-07-01 17:00:00"
		},
		"country":{
			"code":"DE"
		},
		"timezone":"Europe/Berlin"
	},
	"site":{
		"slug":"test"
	},
	"group":{
		"slug":"' . $group->getSlug() . '"
	},
	"user":{
		"username":"******"
	}
}');
        $createEvent = new CreateEvent();
        $createEvent->setFromJSON($json);
        $this->assertEquals(true, $createEvent->canGo());
        $createEvent->go();
        $eventRepoBuilder = new EventRepositoryBuilder();
        $events = $eventRepoBuilder->fetchAll();
        $this->assertEquals(1, count($events));
        $event = $events[0];
        $this->assertEquals('Test', $event->getSummary());
        $this->assertEquals('test test test', $event->getDescription());
        $this->assertEquals('http://example.com', $event->getUrl());
        // Times above are Berlin, These are UTC
        $this->assertEquals('2014-07-01T09:00:00+00:00', $event->getStartAtInUTC()->format('c'));
        $this->assertEquals('2014-07-01T16:00:00+00:00', $event->getEndAtInUTC()->format('c'));
        $this->assertEquals($group->getId(), $event->getGroupId());
        $this->assertEquals('Europe/Berlin', $event->getTimeZone());
        $this->assertEquals($country->getId(), $event->getCountryId());
    }