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 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 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));
 }