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");
     $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");
     $userStranger = new UserAccountModel();
     $userStranger->setEmail("*****@*****.**");
     $userStranger->setUsername("test2");
     $userStranger->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userStranger);
     $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);
     // check loading works
     $this->checkCuratedListInTest1($clRepo->loadBySlug($site, 1));
     // check user perms work
     $curatedList = $clRepo->loadBySlug($site, 1);
     $this->assertFalse($curatedList->canUserEdit(null));
     $this->assertTrue($curatedList->canUserEdit($user));
     $this->assertFalse($curatedList->canUserEdit($userStranger));
     $clb = new CuratedListRepositoryBuilder();
     $clb->setUserCanEdit($user);
     $this->assertEquals(1, count($clb->fetchAll()));
     $clb = new CuratedListRepositoryBuilder();
     $clb->setUserCanEdit($userStranger);
     $this->assertEquals(0, count($clb->fetchAll()));
 }
 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 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());
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $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);
     // Test Before
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     // Add event to list
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $clRepo->addEventtoCuratedList($event, $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->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertTrue($eventWithInfo->getIsEventInCuratedList());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsEvent));
     // Remove event to list
     TimeSource::mock(2014, 5, 1, 9, 0, 0);
     $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->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
 }