public function testGenerate()
 {
     $g = new \Fgms\Bundle\SurveyBundle\Utility\RandomTokenGenerator(128);
     $a = $g->generate();
     $b = $g->generate();
     $this->assertNotSame($a, $b);
     $preg = '/^[a-f0-9]{32}$/u';
     $this->assertSame(1, preg_match($preg, $a));
     $this->assertSame(1, preg_match($preg, $b));
 }
 /**
  * route for the survey
  * @param string $slug
  * @param mixed $group
  */
 public function surveyAction($slug, $group = false)
 {
     //  TODO: This should be injected and the number of bits
     //  should be configurable
     $token = new \Fgms\Bundle\SurveyBundle\Utility\RandomTokenGenerator(128);
     $param = $this->getConfiguration($slug, $group);
     $room = $this->request->query->has('room') ? $this->request->query->get('room') : 'none';
     if ($this->has('request')) {
         $form = $this->getForm($slug, $group, $room);
     } else {
         $form = $this->getFormSymfony3($slug, $group, $room);
     }
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $q = $form->getData();
         //  Create Testimonial objects from responses user
         //  identified as being testimonials
         $ts = $q->getTestimonialData();
         $tests = [];
         if (!is_null($ts)) {
             foreach ($ts as $t) {
                 //	As far as we know each of these $t items
                 //	is raw data from the user, we expect an
                 //	object with a "field" property which is
                 //	a string, but we don't know that the item
                 //	actually has that form
                 if (!(is_object($t) && isset($t->field) && is_string($t->field))) {
                     $this->invalidTestimonialData($t);
                 }
                 if (!preg_match('/^question(\\d+)$/u', $t->field, $matches)) {
                     $this->invalidTestimonialData($t);
                 }
                 $num = intval($matches[1]);
                 $test = new \Fgms\Bundle\SurveyBundle\Entity\Testimonial();
                 $test->setQuestion($num);
                 $test->setApproved(false);
                 $test->setText($q->getQuestion($num));
                 $test->setQuestionnaire($q);
                 $test->setToken($token->generate());
                 $tests[] = $test;
             }
         }
         $em->persist($q);
         foreach ($tests as $t) {
             $em->persist($t);
         }
         foreach ($tests as $t) {
             $this->sendTestimonialEmail($t);
         }
         $this->checkSurveyResults($slug, $group, $form, $room);
         $em->flush();
         $conditional = $this->getConditionalFinish($form) ? '?conditional' : '';
         return $this->redirect("/" . $this->fullSlug . "/finish/" . $conditional);
     }
     $param['form'] = $form->createView();
     return $this->render('FgmsSurveyBundle:Default:survey.html.twig', $param);
 }