/**
  *
  */
 function test1()
 {
     $feature = new \sitefeatures\EditCommentsFeature();
     $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());
     $siteFeatureRepo = new SiteFeatureRepository($this->app);
     // Test Get Default Option
     $this->app['timesource']->mock(2015, 1, 1, 1, 1, 1);
     $data = $siteFeatureRepo->getForSiteAsTree($site);
     $this->assertEquals(false, $data[$feature->getExtensionId()][$feature->getFeatureId()]->isOn());
     // Test Set True
     $this->app['timesource']->mock(2015, 1, 1, 1, 1, 2);
     $siteFeatureRepo->setFeature($site, $feature, true, $user);
     $data = $siteFeatureRepo->getForSiteAsTree($site);
     $this->assertEquals(true, $data[$feature->getExtensionId()][$feature->getFeatureId()]->isOn());
     // Test Set False
     $this->app['timesource']->mock(2015, 1, 1, 1, 1, 3);
     $siteFeatureRepo->setFeature($site, $feature, false, $user);
     $data = $siteFeatureRepo->getForSiteAsTree($site);
     $this->assertEquals(false, $data[$feature->getExtensionId()][$feature->getFeatureId()]->isOn());
     // Test Set False whilst already false
     $this->app['timesource']->mock(2015, 1, 1, 1, 1, 4);
     $siteFeatureRepo->setFeature($site, $feature, false, $user);
     $data = $siteFeatureRepo->getForSiteAsTree($site);
     $this->assertEquals(false, $data[$feature->getExtensionId()][$feature->getFeatureId()]->isOn());
 }
 function features(Request $request, Application $app)
 {
     $siteFeatureRepository = new SiteFeatureRepository($app);
     if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('action') == 'on') {
         $ext = $app['extensions']->getExtensionById($request->request->get('extension'));
         if ($ext) {
             foreach ($ext->getSiteFeatures($app['currentSite']) as $feature) {
                 if ($feature->getFeatureId() == $request->request->get('feature')) {
                     $siteFeatureRepository->setFeature($app['currentSite'], $feature, true, $app['currentUser']);
                     $app['flashmessages']->addMessage("Feature turned on.");
                     return $app->redirect("/admin/features");
                 }
             }
         }
     } else {
         if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('action') == 'off') {
             $ext = $app['extensions']->getExtensionById($request->request->get('extension'));
             if ($ext) {
                 foreach ($ext->getSiteFeatures($app['currentSite']) as $feature) {
                     if ($feature->getFeatureId() == $request->request->get('feature')) {
                         $siteFeatureRepository->setFeature($app['currentSite'], $feature, false, $app['currentUser']);
                         $app['flashmessages']->addMessage("Feature turned off.");
                         return $app->redirect("/admin/features");
                     }
                 }
             }
         }
     }
     return $app['twig']->render('site/admin/features.html.twig', array());
 }
 function features(Request $request, Application $app)
 {
     // This is the legacy way .......
     if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('submitted') == 'yes') {
         $app['currentSite']->setIsFeatureGroup($request->request->get('isFeatureGroup') == '1');
         $app['currentSite']->setIsFeatureMap($request->request->get('isFeatureMap') == '1');
         $app['currentSite']->setIsFeatureCuratedList($request->request->get('isFeatureCuratedList') == '1');
         $app['currentSite']->setisFeatureVirtualEvents($request->request->get('isFeatureVirtualEvents') == '1');
         $app['currentSite']->setisFeaturePhysicalEvents($request->request->get('isFeaturePhysicalEvents') == '1');
         $app['currentSite']->setIsFeatureImporter($request->request->get('isFeatureImporter') == '1');
         $app['currentSite']->setIsFeatureTag($request->request->get('isFeatureTag') == '1');
         $siteRepository = new SiteRepository();
         $siteRepository->edit($app['currentSite'], $app['currentUser']);
         $app['flashmessages']->addMessage("Details saved.");
         return $app->redirect("/admin/");
     }
     // This is the new way .......
     $siteFeatureRepository = new SiteFeatureRepository($app);
     if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('action') == 'on') {
         $ext = $app['extensions']->getExtensionById($request->request->get('extension'));
         if ($ext) {
             foreach ($ext->getSiteFeatures($app['currentSite']) as $feature) {
                 if ($feature->getFeatureId() == $request->request->get('feature')) {
                     $siteFeatureRepository->setFeature($app['currentSite'], $feature, true, $app['currentUser']);
                     $app['flashmessages']->addMessage("Feature turned on.");
                     return $app->redirect("/admin/features");
                 }
             }
         }
     } else {
         if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('action') == 'off') {
             $ext = $app['extensions']->getExtensionById($request->request->get('extension'));
             if ($ext) {
                 foreach ($ext->getSiteFeatures($app['currentSite']) as $feature) {
                     if ($feature->getFeatureId() == $request->request->get('feature')) {
                         $siteFeatureRepository->setFeature($app['currentSite'], $feature, false, $app['currentUser']);
                         $app['flashmessages']->addMessage("Feature turned off.");
                         return $app->redirect("/admin/features");
                     }
                 }
             }
         }
     }
     return $app['twig']->render('site/admin/features.html.twig', array());
 }