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 testUserAttendingEventPublicallyNoWatches()
 {
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $groupRepo = new GroupRepository();
     $eventRepository = new EventRepository();
     $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository();
     $userAtEventRepo = new \repositories\UserAtEventRepository();
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo->create($user);
     $userAttending = new UserAccountModel();
     $userAttending->setEmail("*****@*****.**");
     $userAttending->setUsername("test2");
     $userAttending->setPassword("password1");
     $userRepo->create($userAttending);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 11, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 11, 10, 21, 0, 0));
     $eventRepository->create($event, $site, $user);
     // test before
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userAttending, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userAttending, false, false, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     // test
     $userAtEvent = $userAtEventRepo->loadByUserAndEventOrInstanciate($userAttending, $event);
     $userAtEvent->setIsPlanAttending(true);
     $userAtEvent->setIsPlanPublic(true);
     $userAtEventRepo->save($userAtEvent);
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userAttending, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userAttending, false, false, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
 }
 function test1()
 {
     TimeSource::mock(2014, 5, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $user1 = new UserAccountModel();
     $user1->setEmail("*****@*****.**");
     $user1->setUsername("test1");
     $user1->setPassword("password");
     $user2 = new UserAccountModel();
     $user2->setEmail("*****@*****.**");
     $user2->setUsername("test2");
     $user2->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($user1);
     $userRepo->create($user2);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event1 = new EventModel();
     $event1->setSummary("test");
     $event1->setDescription("test test");
     $event1->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event1->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event1->setUrl("http://www.info.com");
     $event1->setTicketUrl("http://www.tickets.com");
     $event2 = new EventModel();
     $event2->setSummary("test this looks similar");
     $event2->setDescription("test test");
     $event2->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event2->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event2->setUrl("http://www.info.com");
     $event2->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event1, $site, $user);
     $eventRepository->create($event2, $site, $user);
     $userAtEventRepo = new \repositories\UserAtEventRepository();
     $user1AtEvent1 = $userAtEventRepo->loadByUserAndEventOrInstanciate($user1, $event1);
     $user1AtEvent1->setIsPlanAttending(true);
     $user1AtEvent1->setIsPlanPublic(true);
     $userAtEventRepo->save($user1AtEvent1);
     $user1AtEvent2 = $userAtEventRepo->loadByUserAndEventOrInstanciate($user1, $event2);
     $user1AtEvent2->setIsPlanMaybeAttending(true);
     $userAtEventRepo->save($user1AtEvent2);
     $user2AtEvent2 = $userAtEventRepo->loadByUserAndEventOrInstanciate($user2, $event2);
     $user2AtEvent2->setIsPlanMaybeAttending(true);
     $userAtEventRepo->save($user2AtEvent2);
     //=============================================== Test before
     $event2 = $eventRepository->loadBySlug($site, $event2->getSlug());
     $this->assertFalse($event2->getIsDeleted());
     $this->assertNull($event2->getIsDuplicateOfId());
     $user1AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user1, $event1);
     $this->assertNotNull($user1AtEvent1);
     $this->assertEquals(true, $user1AtEvent1->getIsPlanAttending());
     $this->assertEquals(false, $user1AtEvent1->getIsPlanMaybeAttending());
     $this->assertEquals(true, $user1AtEvent1->getIsPlanPublic());
     $user1AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user1, $event2);
     $this->assertNotNull($user1AtEvent2);
     $this->assertEquals(false, $user1AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user1AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user1AtEvent2->getIsPlanPublic());
     $user2AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user2, $event1);
     $this->assertNull($user2AtEvent1);
     $user2AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user2, $event2);
     $this->assertNotNull($user2AtEvent2);
     $this->assertEquals(false, $user2AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user2AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user2AtEvent2->getIsPlanPublic());
     //==================================================== Mark
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $eventRepository->markDuplicate($event2, $event1, $user);
     //==================================================== Test Duplicate
     $event2 = $eventRepository->loadBySlug($site, $event2->getSlug());
     $this->assertTrue($event2->getIsDeleted());
     $this->assertEquals($event1->getId(), $event2->getIsDuplicateOfId());
     // This should not have changed; as there already was data here we don't change it.
     $user1AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user1, $event1);
     $this->assertNotNull($user1AtEvent1);
     $this->assertEquals(true, $user1AtEvent1->getIsPlanAttending());
     $this->assertEquals(false, $user1AtEvent1->getIsPlanMaybeAttending());
     $this->assertEquals(true, $user1AtEvent1->getIsPlanPublic());
     $user1AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user1, $event2);
     $this->assertNotNull($user1AtEvent2);
     $this->assertEquals(false, $user1AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user1AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user1AtEvent2->getIsPlanPublic());
     // This should now change, the mark dupe function should have copied it.
     $user2AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user2, $event1);
     $this->assertNotNull($user2AtEvent1);
     $this->assertEquals(false, $user2AtEvent1->getIsPlanAttending());
     $this->assertEquals(true, $user2AtEvent1->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user2AtEvent1->getIsPlanPublic());
     $user2AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user2, $event2);
     $this->assertNotNull($user2AtEvent2);
     $this->assertEquals(false, $user2AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user2AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user2AtEvent2->getIsPlanPublic());
 }