function testUserWatchesArea() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userTest = new UserAccountModel(); $userTest->setEmail("*****@*****.**"); $userTest->setUsername("testtest"); $userTest->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $userRepo->create($userTest); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $area = new \models\AreaModel(); $area->setTitle("Test"); $areaRepo = new \repositories\AreaRepository(); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); // Test user doesn't have it $srb = new \repositories\builders\SiteRepositoryBuilder(); $srb->setUserInterestedIn($userTest); $sites = $srb->fetchAll(); $this->assertEquals(0, count($sites)); // watch area $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); $userWatchesAreaRepo->startUserWatchingArea($userTest, $area); // has it! $srb = new \repositories\builders\SiteRepositoryBuilder(); $srb->setUserInterestedIn($userTest); $sites = $srb->fetchAll(); $this->assertEquals(1, count($sites)); }
function testUserWatchingParentAreaWithVenue() { TimeSource::mock(2014, 01, 01, 9, 0, 0); $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $userRepo = new UserAccountRepository(); $siteRepo = new SiteRepository(); $venueRepo = new \repositories\VenueRepository(); $eventRepository = new EventRepository(); $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); $GB = $countryRepo->loadByTwoCharCode("GB"); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo->create($user); $userWatchesMain = new UserAccountModel(); $userWatchesMain->setEmail("*****@*****.**"); $userWatchesMain->setUsername("test1"); $userWatchesMain->setPassword("password1"); $userRepo->create($userWatchesMain); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area = new AreaModel(); $area->setTitle("Scotland"); $areaRepo->create($area, null, $site, $GB); $areaChild = new AreaModel(); $areaChild->setTitle("Edinburgh"); $areaRepo->create($areaChild, $area, $site, $GB); $venue = new \models\VenueModel(); $venue->setTitle("Castle"); $venue->setAreaId($areaChild->getId()); $venueRepo->create($venue, $site, $user); $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); $event->setVenueId($venue->getId()); TimeSource::mock(2014, 01, 01, 9, 1, 0); $eventRepository->edit($event); // have to update child cache $areaRepo->buildCacheAreaHasParent($area); $areaRepo->buildCacheAreaHasParent($areaChild); // test before $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, false); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); // test watching main group gets event $userWatchesAreaRepo->startUserWatchingArea($userWatchesMain, $area); $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, true); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $erb = new EventRepositoryBuilder(); $erb->setUserAccount($userWatchesMain, false, true, true, false); $events = $erb->fetchAll(); $this->assertEquals(0, count($events)); }
/** * @return array BaseUserWatchesNotifyContent */ public function getUserNotifyContents(SiteModel $site, UserAccountModel $userAccountModel) { $out = array(); $userWatchesSiteRepo = new \repositories\UserWatchesSiteRepository(); $data = $userWatchesSiteRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel); if ($data) { // no point carrying on; someone watching a site overrides any data contained within return array($data); } if ($site->getIsFeatureGroup()) { $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository(); $data = $userWatchesGroupRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel); if ($data) { $out = array_merge($out, $data); } } $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); $data = $userWatchesAreaRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel); if ($data) { $out = array_merge($out, $data); } return $out; }
/** * @return array BaseUserWatchesNotifyContent */ public function getUserNotifyContents(SiteModel $site, UserAccountModel $userAccountModel) { $out = array(); $userWatchesSiteRepo = new \repositories\UserWatchesSiteRepository(); $data = $userWatchesSiteRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel); if ($data) { // no point carrying on; someone watching a site overrides any data contained within return array($data); } $siteFeatureRepo = new \repositories\SiteFeatureRepository($this->app); if ($siteFeatureRepo->doesSiteHaveFeatureByExtensionAndId($site, 'org.openacalendar', 'Group')) { $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository(); $data = $userWatchesGroupRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel); if ($data) { $out = array_merge($out, $data); } } $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); $data = $userWatchesAreaRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel); if ($data) { $out = array_merge($out, $data); } return $out; }
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)); }