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());
 }
 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));
 }