function testIntegration1()
 {
     \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);
     ## Edit tag
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $tag = $tagRepo->loadById($tag->getId());
     $tag->setDescription("testy");
     $tagRepo->edit($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 edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(true, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 function undelete($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Tag does not exist.");
     }
     if (!$this->parameters['tag']->getIsDeleted()) {
         die("No");
         // TODO
     }
     if ($request->request->get('undelete') == 'yes' && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
         $this->parameters['tag']->setIsDeleted(false);
         $tagRepository = new TagRepository();
         $tagRepository->edit($this->parameters['tag'], $app['currentUser']);
         return $app->redirect("/tag/" . $this->parameters['tag']->getSlugForUrl());
     }
     return $app['twig']->render('site/tag/undelete.html.twig', $this->parameters);
 }