/** * @Route("/vote/{id}/{dir}/{token}", * name="fortune_vote", * requirements={ * "id"="\d+", * "dir"="up|down", * } * ) */ public function voteAction(Request $request, Fortune $fortune, $dir, $token) { if (!$this->isCsrfTokenValid('', $token)) { throw $this->createNotFoundException('Invalid CSRF.'); } $fortune->vote($dir); $this->getDoctrine()->getManager()->flush(); if ($request->isXmlHttpRequest()) { return new JsonResponse(array('votes' => $fortune->getVotes())); } return $this->redirect($this->generateUrl('fortune_list')); }
public function testGetQuotesAsArray() { $fortune = new Fortune(); $fortune->setQuotes(<<<EOL This line should not exist, expects when importing legacy fortune. <me> Hello <him> Hi ! <her> coucou => ca va ? EOL ); $expected = array(array('nick' => '', 'quote' => 'This line should not exist, expects when importing legacy fortune.'), array('nick' => 'me', 'quote' => 'Hello'), array('nick' => 'him', 'quote' => 'Hi !'), array('nick' => 'her', 'quote' => 'coucou => ca va ?')); $this->assertSame($expected, $fortune->getQuotesAsArray()); }