function testUserWatchesGroup()
 {
     $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());
     $group = new \models\GroupModel();
     $group->setTitle("Test");
     $groupRepo = new \repositories\GroupRepository();
     $groupRepo->create($group, $site, $user);
     // Test user doesn't have it
     $srb = new \repositories\builders\SiteRepositoryBuilder();
     $srb->setUserInterestedIn($userTest);
     $sites = $srb->fetchAll();
     $this->assertEquals(0, count($sites));
     // watch group
     $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository();
     $userWatchesGroupRepo->startUserWatchingGroup($userTest, $group);
     // has it!
     $srb = new \repositories\builders\SiteRepositoryBuilder();
     $srb->setUserInterestedIn($userTest);
     $sites = $srb->fetchAll();
     $this->assertEquals(1, count($sites));
 }
 /**
  * @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 testUserWatchingGroupsWithAnEventInTwoGroups()
 {
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $groupRepo = new GroupRepository();
     $eventRepository = new EventRepository();
     $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository();
     $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);
     $userWatchesOther = new UserAccountModel();
     $userWatchesOther->setEmail("*****@*****.**");
     $userWatchesOther->setUsername("test2");
     $userWatchesOther->setPassword("password1");
     $userRepo->create($userWatchesOther);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     $groupMain = new GroupModel();
     $groupMain->setTitle("test");
     $groupRepo->create($groupMain, $site, $user);
     $groupOther = new GroupModel();
     $groupOther->setTitle("test");
     $groupRepo->create($groupOther, $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, $groupMain, array($groupOther));
     // 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));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, false);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     // test watching main group gets event
     $userWatchesGroupRepo->startUserWatchingGroup($userWatchesMain, $groupMain);
     $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));
     // test watching other group gets event
     $userWatchesGroupRepo->startUserWatchingGroup($userWatchesOther, $groupOther);
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, 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;
 }