function testEventInTwoGroupsAddedDirectlyThenOneGroupAdded()
 {
     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());
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("I don't need no stinking tests");
     $group2->setDescription("works first time");
     $group2->setUrl("http://www.soveryperfect.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group1, array($group2));
     // Test Before
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->isEventInListViaGroup());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     // Add group to list
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group1, $curatedList, $user);
     // Test After
     // .... we don't ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertFalse($eventWithInfo->getIsEventInCuratedList());
     // .... we Do ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList, true);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertEquals($group1->getId(), $eventWithInfo->getInCuratedListGroupId());
     $this->assertEquals($group1->getSlug(), $eventWithInfo->getInCuratedListGroupSlug());
     $this->assertEquals($group1->getTitle(), $eventWithInfo->getInCuratedListGroupTitle());
     $this->assertTrue($eventWithInfo->getIsEventInCuratedList());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->isEventInListViaGroup());
     $this->assertEquals($group1->getId(), $curatedListWithInfo->getEventInListViaGroupId());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     // Remove group from list
     TimeSource::mock(2014, 5, 1, 9, 0, 0);
     $clRepo->removeGroupFromCuratedList($group1, $curatedList, $user);
     $clRepo->removeEventFromCuratedList($event, $curatedList, $user);
     // Test After
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setGroupInformation($group1);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsGroupInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->isEventInListViaGroup());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group1);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsGroup($group2);
     $curatedListsContainsGroup = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsGroup));
 }
 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());
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     // Test Before
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
     // Add event to list
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     // Test After
     // ... we don't ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertFalse($eventWithInfo->getIsEventInCuratedList());
     // ... we DO ask for extra info
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList, true);
     $events = $eventRepositoryBuilder->fetchAll();
     $this->assertEquals(1, count($events));
     $eventWithInfo = $events[0];
     $this->assertNull($eventWithInfo->getInCuratedListGroupId());
     $this->assertNull($eventWithInfo->getInCuratedListGroupSlug());
     $this->assertNull($eventWithInfo->getInCuratedListGroupTitle());
     $this->assertTrue($eventWithInfo->getIsEventInCuratedList());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(true, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsContainsEvent));
     // Remove event to list
     TimeSource::mock(2014, 5, 1, 9, 0, 0);
     $clRepo->removeEventFromCuratedList($event, $curatedList, $user);
     // Test After
     $eventRepositoryBuilder = new \repositories\builders\EventRepositoryBuilder();
     $eventRepositoryBuilder->setCuratedList($curatedList);
     $this->assertEquals(0, count($eventRepositoryBuilder->fetchAll()));
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setEventInformation($event);
     $curatedListsWithInfo = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(1, count($curatedListsWithInfo));
     $curatedListWithInfo = $curatedListsWithInfo[0];
     $this->assertEquals(false, $curatedListWithInfo->getIsEventInlist());
     $curatedListRepoBuilder = new CuratedListRepositoryBuilder();
     $curatedListRepoBuilder->setContainsEvent($event);
     $curatedListsContainsEvent = $curatedListRepoBuilder->fetchAll();
     $this->assertEquals(0, count($curatedListsContainsEvent));
 }