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());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(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);
     $tag = new TagModel();
     $tag->setTitle("Test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     $tagRepo->addTagToEvent($tag, $event, $user);
     ## Test
     $this->assertNotNull($tagRepo->loadById($tag->getId()));
     $tagRepoBuilder = new repositories\builders\TagRepositoryBuilder();
     $tagRepoBuilder->setTagsForEvent($event);
     $this->assertEquals(1, count($tagRepoBuilder->fetchAll()));
     ## Purge!
     $tagRepo->purge($tag);
     ## Test
     $this->assertNull($tagRepo->loadById($tag->getId()));
     $tagRepoBuilder = new repositories\builders\TagRepositoryBuilder();
     $tagRepoBuilder->setTagsForEvent($event);
     $this->assertEquals(0, count($tagRepoBuilder->fetchAll()));
 }
 function test1()
 {
     $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());
     $tag = new TagModel();
     $tag->setTitle("test");
     $tag->setDescription("test test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     $this->checkTagInTest1($tagRepo->loadById($tag->getId()));
     $this->checkTagInTest1($tagRepo->loadBySlug($site, $tag->getSlug()));
 }
 function testIntegration2()
 {
     \TimeSource::mock(2014, 1, 1, 12, 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());
     ## Create tag
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $tag = new TagModel();
     $tag->setTitle("test");
     $tag->setDescription("test test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     ## Delete tag
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $tag = $tagRepo->loadById($tag->getId());
     $tagRepo->delete($tag, $user);
     ## Now save changed flags on these .....
     $tagHistoryRepo = new TagHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM tag_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $tagHistory = new TagHistoryModel();
         $tagHistory->setFromDataBaseRow($data);
         $tagHistoryRepo->ensureChangedFlagsAreSet($tagHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setTag($tag);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $historyRepo->setIncludeTagHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the Delete
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }