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)); }
$areaMapItInfo = $areaMapItInfoRepo->getByCodeGSS($json_blob->codes->gss); if ($areaMapItInfo) { print " ... found area ID " . $areaMapItInfo->getAreaId() . "\n"; $areaMapItInfo->setName($json_blob->name); $areaMapItInfo->setCodeGss($json_blob->codes->gss); if (isset($json_blob->codes->unit_id)) { $areaMapItInfo->setCodeUnitId($json_blob->codes->unit_id); } $areaMapItInfo->setMapitId($json_blob->id); $areaMapItInfoRepo->edit($areaMapItInfo); } else { print " ... creating!\n"; if (!array_key_exists($json_blob->country_name, $parentAreas)) { die("No Parent Area: " . $json_blob->country_name . "\n"); } $area = new \models\AreaModel(); $area->setTitle($json_blob->name); $area->setCountryId($gb->getId()); $area->setSiteId($CONFIG->singleSiteID); $areaRepo->create($area, $parentAreas[$json_blob->country_name], $site, $gb, null); $areaMapItInfo = new \com\meetyournextmp\models\AreaMapItInfoModel(); $areaMapItInfo->setName($json_blob->name); $areaMapItInfo->setCodeGss($json_blob->codes->gss); if (isset($json_blob->codes->unit_id)) { $areaMapItInfo->setCodeUnitId($json_blob->codes->unit_id); } $areaMapItInfo->setMapitId($json_blob->id); $areaMapItInfo->setAreaId($area->getId()); $areaMapItInfoRepo->create($areaMapItInfo); } }
function testParentChildSearches() { $this->addCountriesToTestDB(); 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()); $countryRepo = new \repositories\CountryRepository(); $gb = $countryRepo->loadByTwoCharCode("GB"); $areaParent = new \models\AreaModel(); $areaParent->setTitle("Parent"); $areaCentre = new \models\AreaModel(); $areaCentre->setTitle("Centre"); $areaChild = new \models\AreaModel(); $areaChild->setTitle("Child"); $areaRepo = new \repositories\AreaRepository(); $areaRepo->create($areaParent, null, $site, $gb); $areaRepo->create($areaCentre, $areaParent, $site, $gb); $areaRepo->create($areaChild, $areaCentre, $site, $gb); $areaRepo->buildCacheAreaHasParent($areaParent); $areaRepo->buildCacheAreaHasParent($areaCentre); $areaRepo->buildCacheAreaHasParent($areaChild); $commentParent = new \org\openacalendar\comments\models\AreaCommentModel(); $commentParent->setTitle("Parent"); $commentCentre = new \org\openacalendar\comments\models\AreaCommentModel(); $commentCentre->setTitle("Centre"); $commentChild = new \org\openacalendar\comments\models\AreaCommentModel(); $commentChild->setTitle("Child"); $areaCommentRepo = new \org\openacalendar\comments\repositories\AreaCommentRepository(); TimeSource::mock(2014, 5, 1, 7, 0, 0); $areaCommentRepo->create($commentParent, $areaParent, $user); TimeSource::mock(2014, 5, 1, 7, 0, 1); $areaCommentRepo->create($commentCentre, $areaCentre, $user); TimeSource::mock(2014, 5, 1, 7, 0, 2); $areaCommentRepo->create($commentChild, $areaChild, $user); ##################################### Test Centre $areaCommentRepoBuilder = new \org\openacalendar\comments\repositories\builders\AreaCommentRepositoryBuilder(); $areaCommentRepoBuilder->setArea($areaCentre, false, false); $areaComments = $areaCommentRepoBuilder->fetchAll(); $this->assertEquals(1, count($areaComments)); $this->assertEquals($commentCentre->getId(), $areaComments[0]->getId()); ##################################### Test Centre + Parents $areaCommentRepoBuilder = new \org\openacalendar\comments\repositories\builders\AreaCommentRepositoryBuilder(); $areaCommentRepoBuilder->setArea($areaCentre, true, false); $areaComments = $areaCommentRepoBuilder->fetchAll(); $this->assertEquals(2, count($areaComments)); $this->assertEquals($commentParent->getId(), $areaComments[0]->getId()); $this->assertEquals($commentCentre->getId(), $areaComments[1]->getId()); ##################################### Test Centre + Children $areaCommentRepoBuilder = new \org\openacalendar\comments\repositories\builders\AreaCommentRepositoryBuilder(); $areaCommentRepoBuilder->setArea($areaCentre, false, true); $areaComments = $areaCommentRepoBuilder->fetchAll(); $this->assertEquals(2, count($areaComments)); $this->assertEquals($commentCentre->getId(), $areaComments[0]->getId()); $this->assertEquals($commentChild->getId(), $areaComments[1]->getId()); ##################################### Test Centre + Parents + Children $areaCommentRepoBuilder = new \org\openacalendar\comments\repositories\builders\AreaCommentRepositoryBuilder(); $areaCommentRepoBuilder->setArea($areaCentre, true, true); $areaComments = $areaCommentRepoBuilder->fetchAll(); $this->assertEquals(3, count($areaComments)); $this->assertEquals($commentParent->getId(), $areaComments[0]->getId()); $this->assertEquals($commentCentre->getId(), $areaComments[1]->getId()); $this->assertEquals($commentChild->getId(), $areaComments[2]->getId()); ##################################### Test Child + Children $areaCommentRepoBuilder = new \org\openacalendar\comments\repositories\builders\AreaCommentRepositoryBuilder(); $areaCommentRepoBuilder->setArea($areaChild, false, true); $areaComments = $areaCommentRepoBuilder->fetchAll(); $this->assertEquals(1, count($areaComments)); $this->assertEquals($commentChild->getId(), $areaComments[0]->getId()); }
print "\n"; } } } } sleep(10); die; $countryRepo = new \repositories\CountryRepository(); $areaRepo = new \repositories\AreaRepository(); $gb = $countryRepo->loadByTwoCharCode("GB"); $siteRepo = new \repositories\SiteRepository(); $site = $siteRepo->loadById($CONFIG->singleSiteID); foreach ($parentAreas as $parentArea) { print "In: " . $parentArea->getTitle() . "\n\n"; if (isset($workToDo[$parentArea->getTitle()])) { foreach ($workToDo[$parentArea->getTitle()] as $newParentAreaTitle => $newParentAreaAreas) { if (count($newParentAreaAreas) > 1) { print "Make: " . $newParentAreaTitle . "\n"; $newParentAreaModel = new \models\AreaModel(); $newParentAreaModel->setTitle($newParentAreaTitle); $areaRepo->create($newParentAreaModel, $parentArea, $site, $gb); foreach ($newParentAreaAreas as $area) { print " - Area: " . $area->getTitle() . "\n"; $area->setParentAreaId($newParentAreaModel->getId()); $areaRepo->editParentArea($area); } print "\n"; } } } }
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)); }