function testIntegration1() { $this->addCountriesToTestDB(); \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()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); ## Create area \TimeSource::mock(2014, 1, 1, 13, 0, 0); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $area->setCountryId($gb->getId()); $areaRepo = new AreaRepository(); $areaRepo->create($area, null, $site, $gb, $user); ## Edit area \TimeSource::mock(2014, 1, 1, 14, 0, 0); $area = $areaRepo->loadById($area->getId()); $area->setDescription("testy"); $areaRepo->edit($area, $user); ## Now save changed flags on these ..... $areaHistoryRepo = new AreaHistoryRepository(); $stat = $this->app['db']->prepare("SELECT * FROM area_history"); $stat->execute(); while ($data = $stat->fetch()) { $areaHistory = new AreaHistoryModel(); $areaHistory->setFromDataBaseRow($data); $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory); } ## Now load and check $historyRepo = new HistoryRepositoryBuilder(); $historyRepo->setIncludeEventHistory(false); $historyRepo->setIncludeVenueHistory(false); $historyRepo->setIncludeGroupHistory(false); $historyRepo->setIncludeAreaHistory(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]->getCountryIdChanged()); $this->assertEquals(false, $histories[0]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[0]->getIsDeletedChanged()); #the create $this->assertEquals(true, $histories[1]->getTitleChanged()); $this->assertEquals(true, $histories[1]->getDescriptionChanged()); $this->assertEquals(true, $histories[1]->getCountryIdChanged()); $this->assertEquals(false, $histories[1]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[1]->getIsDeletedChanged()); }
public function postInfoJson($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Does not exist."); } $ourRequest = new \Request($request); $edits = false; if ($ourRequest->hasGetOrPost('title') && $this->area->setTitleIfDifferent($ourRequest->getGetOrPostString('title', ''))) { $edits = true; } if ($edits) { $repo = new AreaRepository(); $repo->edit($this->area, $app['apiUser']); $out = array('edited' => true); } else { $out = array('edited' => false); } return json_encode($out); }
function action($countryslug, Request $request, Application $app) { if (!$this->build($countryslug, $request, $app)) { $app->abort(404, "country does not exist."); } if ($request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $areaSlugs = is_array($request->request->get('area')) ? $request->request->get('area') : array(); $areaRepository = new AreaRepository(); if ($request->request->get('action') == 'delete') { foreach ($areaSlugs as $areaSlug) { $area = $areaRepository->loadBySlugAndCountry($app['currentSite'], $areaSlug, $this->parameters['country']); if ($area && !$area->getIsDeleted()) { $areaRepository->delete($area, $app['currentUser']); } $app['flashmessages']->addMessage("Deleted!"); } } else { if ($request->request->get('action') == 'undelete') { foreach ($areaSlugs as $areaSlug) { $area = $areaRepository->loadBySlugAndCountry($app['currentSite'], $areaSlug, $this->parameters['country']); if ($area) { $areaRepository->edit($area, $app['currentUser']); } $app['flashmessages']->addMessage("Undeleted!"); } } } } return $app->redirect("/admin/areas/" . $this->parameters['country']->getTwoCharCode()); }