public function showFormAction(Request $request, $poi_id) { $user = $this->getUser(); // User is logged? if (isset($user)) { $em = $this->getDoctrine()->getManager(); // POI Exists? $poi = $em->getRepository('AppBundle:POI')->findOneById($poi_id); if (!$poi) { throw new NotFoundHttpException('Place not found.'); } $newComment = new POIComment(); $newComment->setPOI($poi); $newComment->setAuthor($user); $form = $this->createForm(new PoiCommentForm(), $newComment, array('action' => $this->generateUrl('poi_comment_form_submit', array('poi_id' => $poi->getId())))); return $this->render('themes/default/comments/POICommentForm.html.twig', array('form' => $form->createView())); } else { return $this->render('themes/default/comments/POICommentFormNotLogged.html.twig'); } }
public function testIndex() { $comment1 = new POIComment("El Perro de San Roque no Tiene Rabo", $this->em); $user = $this->em->getRepository('AppBundle:User')->findOneByUsername('xime'); $comment1->setAuthor($user); // The content of the first comment is correct $this->assertEquals("El Perro de San Roque no Tiene Rabo", $comment1->getContent()); // The route is correct $this->assertEquals(1, $comment1->getRoute()); // We will add 3 answers to this comment $comment_1_1 = new POIComment("Discrepo, pero si tiene Rabo", $this->em); $comment_1_2 = new POIComment("No estoy seguro de entenderte", $this->em); $comment_1_3 = new POIComment("No tengo opinion", $this->em); $comment1->addAnswer($comment_1_1); $comment1->addAnswer($comment_1_2); $comment1->addAnswer($comment_1_3); // The route for this answers is correct $this->assertEquals('1|1', $comment_1_1->getRoute()); $this->assertEquals('1|2', $comment_1_2->getRoute()); $this->assertEquals('1|3', $comment_1_3->getRoute()); // Lets see if answers are stored $answers = $comment1->getAnswers(); $ans = $answers[0]; $this->assertEquals("Discrepo, pero si tiene Rabo", $ans->getContent()); $ans = $answers[1]; $this->assertEquals("No estoy seguro de entenderte", $ans->getContent()); $ans = $answers[2]; $this->assertEquals("No tengo opinion", $ans->getContent()); // Let's test serializing and deserializing $comment2 = new POIComment('', $this->em); $comment2->fromJson($comment1->toJson()); $this->assertEquals($comment1, $comment2); // The same json? $this->assertEquals($comment1->toJson(), $comment2->toJson()); echo $comment1->toJson(); }