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())); }
/** * @dataProvider dataForTestScoreURLSame */ function testScoreURLSame($url1, $url2, $score) { $site = new SiteModel(); $eventNew = new models\EventModel(); $eventNew->setStartAt(new \DateTime("12th Feb 2012 10:00:00")); $eventNew->setEndAt(new \DateTime("12th Feb 2012 13:00:00")); $eventNew->setUrl($url1); $eventExisting = new models\EventModel(); $eventExisting->setStartAt(new \DateTime("12th March 2012 10:00:00")); $eventExisting->setEndAt(new \DateTime("12th March 2012 13:00:00")); $eventExisting->setUrl($url2); $sfde = new SearchForDuplicateEvents($eventNew, $site); $this->assertEquals($score, $sfde->getScoreForConsideredEvent($eventExisting)); }
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 testEventsVanish() { ## User, Site, Event \TimeSource::mock(2014, 1, 1, 1, 2, 3); $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(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); ## Event can be found $erb = new EventRepositoryBuilder(); $erb->setIncludeEventsFromClosedSites(true); $erb->fetchAll(); $this->assertEquals(1, count($erb->fetchAll())); $erb = new EventRepositoryBuilder(); $erb->setIncludeEventsFromClosedSites(false); $erb->fetchAll(); $this->assertEquals(1, count($erb->fetchAll())); ## Close Site \TimeSource::mock(2014, 2, 1, 1, 2, 3); $site->setIsClosedBySysAdmin(true); $site->setClosedBySysAdminreason('Testing'); $siteRepo->edit($site, $user); ## Event can not be found $erb = new EventRepositoryBuilder(); $erb->setIncludeEventsFromClosedSites(true); $erb->fetchAll(); $this->assertEquals(1, count($erb->fetchAll())); $erb = new EventRepositoryBuilder(); $erb->setIncludeEventsFromClosedSites(false); $erb->fetchAll(); $this->assertEquals(0, count($erb->fetchAll())); }
function testFreeTextSearch() { 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()); $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); ///////////// Test No Search $erb = new EventRepositoryBuilder(); $this->assertEquals(1, count($erb->fetchAll())); $erb = new EventRepositoryBuilder(); $this->assertEquals(1, $erb->fetchCount()); ///////////// Test Search Pass $erb = new EventRepositoryBuilder(); $erb->setFreeTextsearch("test"); $this->assertEquals(1, count($erb->fetchAll())); $erb = new EventRepositoryBuilder(); $erb->setFreeTextsearch("test"); $this->assertEquals(1, $erb->fetchCount()); ///////////// Test Search Fail $erb = new EventRepositoryBuilder(); $erb->setFreeTextsearch("eodueoth dlhtunkn ethh5f 8l79,35dheutn"); $this->assertEquals(0, count($erb->fetchAll())); $erb = new EventRepositoryBuilder(); $erb->setFreeTextsearch("eodueoth dlhtunkn ethh5f 8l79,35dheutn"); $this->assertEquals(0, $erb->fetchCount()); }
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()); $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); $tag = new TagModel(); $tag->setTitle("Test"); $tagRepo = new TagRepository(); $tagRepo->create($tag, $site, $user); $tagRepo->addTagToEvent($tag, $event, $user); ## Test $this->assertNotNull($tagRepo->loadById($tag->getId())); $tagRepoBuilder = new repositories\builders\TagRepositoryBuilder(); $tagRepoBuilder->setTagsForEvent($event); $this->assertEquals(1, count($tagRepoBuilder->fetchAll())); ## Purge! $tagRepo->purge($tag); ## Test $this->assertNull($tagRepo->loadById($tag->getId())); $tagRepoBuilder = new repositories\builders\TagRepositoryBuilder(); $tagRepoBuilder->setTagsForEvent($event); $this->assertEquals(0, count($tagRepoBuilder->fetchAll())); }
function testSummerTime() { 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()); $event = new EventModel(); $event->setSummary("test"); $event->setDescription("test test"); $event->setStartAt($this->mktime(2014, 5, 10, 19, 0, 0, 'Europe/London')); $event->setEndAt($this->mktime(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); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals("test test", $event->getDescription()); $this->assertEquals("test", $event->getSummary()); $this->assertEquals("http://www.info.com", $event->getUrl()); $this->assertEquals("http://www.tickets.com", $event->getTicketUrl()); $startAtShouldBe = $this->mktime(2014, 5, 10, 18, 0, 0, 'UTC'); // Not summer time so London is +1 UTC! $startAtIs = clone $event->getStartAt(); $startAtIs->setTimezone(new \DateTimeZone('UTC')); $this->assertEquals($startAtShouldBe->format("c"), $startAtIs->format("c")); $erb = new EventRepositoryBuilder(); $erb->setFreeTextsearch('cat'); $this->assertEquals(0, count($erb->fetchAll())); $erb = new EventRepositoryBuilder(); $erb->setFreeTextsearch('test'); $this->assertEquals(1, count($erb->fetchAll())); }
public function go() { $event = new EventModel(); $event->setSummary($this->summary); $event->setDescription($this->description); $event->setUrl($this->url); $event->setTimezone($this->timezone); $event->setStartAt($this->start_at); $event->setEndAt($this->end_at); $event->setCountryId($this->country->getId()); $eventRepo = new EventRepository(); $eventRepo->create($event, $this->site, $this->user, $this->group); }
function testAcrossBST1() { \TimeSource::mock(2015, 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()); $event = new EventModel(); $event->setSummary("test"); $event->setDescription("test test"); $event->setTimezone('Europe/London'); $start = new \DateTime("", new \DateTimeZone('Europe/London')); $start->setDate(2015, 5, 10); $start->setTime(19, 0, 0); $event->setStartAt($start); $end = new \DateTime("", new \DateTimeZone('Europe/London')); $end->setDate(2015, 5, 10); $end->setTime(21, 0, 0); $event->setEndAt($end); $event->setUrl("http://www.info.com"); $event->setTicketUrl("http://www.tickets.com"); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $eventRecurSetRepository = new EventRecurSetRepository(); $eventRecurSet = $eventRecurSetRepository->getForEvent($event); $eventRecurSet->setTimeZoneName($event->getTimezone()); $newStart = new \DateTime(); $newStart->setDate(2015, 11, 1); $newEvent = $eventRecurSet->getNewEventOnArbitraryDate($event, $newStart); // What we are really testing here is start and end times set correctly $this->assertEquals("2015-11-01T19:00:00+00:00", $newEvent->getStartAtInUTC()->format("c")); $this->assertEquals("2015-11-01T21:00:00+00:00", $newEvent->getEndAtInUTC()->format("c")); $this->assertEquals("2015-11-01T19:00:00+00:00", $newEvent->getStartAtInTimezone()->format("c")); $this->assertEquals("2015-11-01T21:00:00+00:00", $newEvent->getEndAtInTimezone()->format("c")); }
function addDataToEventBeforeCheck(EventModel $eventModel) { $eventModel->setSummary($this->draftEvent->getDetailsValue('event.summary')); $eventModel->setDescription($this->draftEvent->getDetailsValue('event.description')); $eventModel->setUrl($this->draftEvent->getDetailsValue('event.url')); $eventModel->setTicketUrl($this->draftEvent->getDetailsValue('event.ticket_url')); foreach ($this->site->getCachedEventCustomFieldDefinitionsAsModels() as $customField) { if ($this->draftEvent->hasDetailsValue('event.custom.' . $customField->getKey())) { $eventModel->setCustomField($customField, $this->draftEvent->getDetailsValue('event.custom.' . $customField->getKey())); } } if ($this->site->getIsFeaturePhysicalEvents() && $this->site->getIsFeatureVirtualEvents()) { $eventModel->setIsPhysical($this->draftEvent->getDetailsValue('event.is_physical')); $eventModel->setIsVirtual($this->draftEvent->getDetailsValue('event.is_virtual')); } else { if ($this->site->getIsFeaturePhysicalEvents()) { $eventModel->setIsPhysical(true); $eventModel->setIsVirtual(false); } else { if ($this->site->getIsFeatureVirtualEvents()) { $eventModel->setIsPhysical(false); $eventModel->setIsVirtual(true); } } } }
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()); }
function testEventInNoAreaHumanInCentre() { $this->addCountriesToTestDB(); TimeSource::mock(2014, 5, 1, 7, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userWatching = new UserAccountModel(); $userWatching->setEmail("*****@*****.**"); $userWatching->setUsername("test1"); $userWatching->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $userRepo->create($userWatching); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $countryRepo = new \repositories\CountryRepository(); $gb = $countryRepo->loadByTwoCharCode("GB"); $areaParent = new \models\AreaModel(); $areaParent->setTitle("Parent"); $areaChild = new \models\AreaModel(); $areaChild->setTitle("Child"); $areaOtherChild = new \models\AreaModel(); $areaOtherChild->setTitle("Other Child"); $areaRepo = new \repositories\AreaRepository(); $areaRepo->create($areaParent, null, $site, $gb); $areaRepo->create($areaChild, $areaParent, $site, $gb); $areaRepo->create($areaOtherChild, $areaParent, $site, $gb); $areaRepo->buildCacheAreaHasParent($areaParent); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaOtherChild); $event = new EventModel(); $event->setSummary("test"); $event->setDescription("test test"); $event->setStartAt($this->mktime(2014, 5, 10, 19, 0, 0, 'Europe/London')); $event->setEndAt($this->mktime(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); $human = new \com\meetyournextmp\models\HumanModel(); $human->setTitle("Bob"); $humanRepo = new \com\meetyournextmp\repositories\HumanRepository(); $humanRepo->create($human, $site, null); $humanRepo->addHumanToArea($human, $areaChild, null); $humanRepo->addHumanToEvent($human, $event, null); $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); //////////////////////////////// TEST ALL EVENTS $erb = new \repositories\builders\EventRepositoryBuilder(); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $hrb = new \repositories\builders\HistoryRepositoryBuilder(); $hrb->setIncludeAreaHistory(false); $hrb->setIncludeEventHistory(true); $histories = $hrb->fetchAll(); $this->assertEquals(1, count($histories)); //////////////////////////////// TEST OTHER CHILD $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setArea($areaOtherChild); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); $hrb = new \repositories\builders\HistoryRepositoryBuilder(); $hrb->getHistoryRepositoryBuilderConfig()->setArea($areaOtherChild); $hrb->setIncludeAreaHistory(false); $hrb->setIncludeEventHistory(true); $histories = $hrb->fetchAll(); $this->assertEquals(0, count($histories)); //////////////////////////////// TEST CHILD $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setArea($areaChild); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $hrb = new \repositories\builders\HistoryRepositoryBuilder(); $hrb->getHistoryRepositoryBuilderConfig()->setArea($areaChild); $hrb->setIncludeAreaHistory(false); $hrb->setIncludeEventHistory(true); $histories = $hrb->fetchAll(); $this->assertEquals(1, count($histories)); //////////////////////////////// TEST PARENT $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setArea($areaChild); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $hrb = new \repositories\builders\HistoryRepositoryBuilder(); $hrb->getHistoryRepositoryBuilderConfig()->setArea($areaChild); $hrb->setIncludeAreaHistory(false); $hrb->setIncludeEventHistory(true); $histories = $hrb->fetchAll(); $this->assertEquals(1, count($histories)); //////////////////////////////// USER WATCHES NOTHING $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setUserAccount($userWatching, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); //////////////////////////////// USER WATCHES PARENT $userWatchesAreaRepo->startUserWatchingArea($userWatching, $areaParent); $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setUserAccount($userWatching, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); //////////////////////////////// USER WATCHES CHILD $userWatchesAreaRepo->stopUserWatchingArea($userWatching, $areaParent); $userWatchesAreaRepo->startUserWatchingArea($userWatching, $areaChild); $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setUserAccount($userWatching, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); }
public function testAddCustomFieldThenCreateEventWithContent() { 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()); $customFieldDefinition1 = new EventCustomFieldDefinitionModel(); $customFieldDefinition1->setSiteId($site->getId()); $customFieldDefinition1->setExtensionId('org.openacalendar'); $customFieldDefinition1->setType('TextSingleLine'); $customFieldDefinition1->setKey('cats'); $customFieldDefinition1->setLabel('cats'); $customFieldDefinition2 = new EventCustomFieldDefinitionModel(); $customFieldDefinition2->setSiteId($site->getId()); $customFieldDefinition2->setExtensionId('org.openacalendar'); $customFieldDefinition2->setType('TextSingleLine'); $customFieldDefinition2->setKey('dogs'); $customFieldDefinition2->setLabel('dogs'); $ecfRepo = new EventCustomFieldDefinitionRepository(); $ecfRepo->create($customFieldDefinition1, $user); $ecfRepo->create($customFieldDefinition2, $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"); $event->setCustomField($customFieldDefinition1, "CATS"); // CREATE WITH TimeSource::mock(2014, 5, 1, 7, 1, 0); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); $event = $eventRepository->loadByID($event->getId()); $this->assertEquals(true, $event->hasCustomField($customFieldDefinition1)); $this->assertEquals(false, $event->hasCustomField($customFieldDefinition2)); $this->assertFalse($event->getIsDeleted()); // LET's CHECK HISTORY $eventHistoryRepo = new EventHistoryRepository(); $stat = $this->app['db']->prepare("SELECT * FROM event_history"); $stat->execute(); while ($data = $stat->fetch()) { $eventHistory = new EventHistoryModel(); $eventHistory->setFromDataBaseRow($data); $eventHistoryRepo->ensureChangedFlagsAreSet($eventHistory); } $eventHistoryRepoBuilder = new EventHistoryRepositoryBuilder(); $eventHistoryRepoBuilder->setEvent($event); $histories = $eventHistoryRepoBuilder->fetchAll(); $this->assertEquals(1, count($histories)); $historyCreate = $histories[0]; $this->assertTrue($historyCreate->getCustomFieldChangedKnown($customFieldDefinition1)); $this->assertTrue($historyCreate->getCustomFieldChanged($customFieldDefinition1)); $this->assertFalse($historyCreate->getCustomFieldChanged($customFieldDefinition2)); }