/** * Add a comment. * * @param Request $request Request * @param string $authorToken Author Token * @param string $context Context * @param string $source Source * * @return Response */ public function addCommentAction(Request $request, $authorToken, $context, $source) { $requestBag = $request->request; $content = $requestBag->get('content'); $authorName = $requestBag->get('author_name'); $authorEmail = $requestBag->get('author_email'); $parentId = $requestBag->get('parent'); /** * @var CommentInterface|null $parent */ $parent = $parentId > 0 ? $this->commentRepository->find($parentId) : null; $comment = $this->commentManager->addComment($source, $context, $content, $authorToken, $authorName, $authorEmail, $parent); $commentStructure = $this->commentCache->createCommentStructure($comment); return new Response(json_encode(['entity' => $commentStructure, 'children' => []])); }
/** * Test load. */ public function testLoad() { $this->commentRepository->expects($this->any())->method('getAllCommentsSortedByParentAndIdAsc')->with($this->equalTo('source'))->will($this->returnValue($this->getCommentsStructure())); $comments = $this->commentCache->load('source', 'context'); $this->assertEquals([['entity' => ['id' => 1, 'authorName' => 'Marc Morera', 'authorEmail' => '*****@*****.**', 'context' => 'admin', 'content' => 'comment1', 'nbVotes' => 2, 'nbUpVotes' => 1, 'nbDownVotes' => 1, 'createdAt' => '2015-01-01 00:00:00', 'updatedAt' => '2015-01-01 00:00:00'], 'children' => [['entity' => ['id' => 2, 'authorName' => 'Marc Morera', 'authorEmail' => '*****@*****.**', 'context' => 'admin', 'content' => 'comment2', 'nbVotes' => 2, 'nbUpVotes' => 1, 'nbDownVotes' => 1, 'createdAt' => '2015-01-01 00:00:00', 'updatedAt' => '2015-01-01 00:00:00'], 'children' => []], ['entity' => ['id' => 3, 'authorName' => 'Another guy', 'authorEmail' => '*****@*****.**', 'context' => 'admin', 'content' => 'comment3', 'nbVotes' => 2, 'nbUpVotes' => 1, 'nbDownVotes' => 1, 'createdAt' => '2015-01-01 00:00:00', 'updatedAt' => '2015-01-01 00:00:00'], 'children' => []]]], ['entity' => ['id' => 4, 'authorName' => 'Marc Morera', 'authorEmail' => '*****@*****.**', 'context' => 'admin', 'content' => 'comment4', 'nbVotes' => 2, 'nbUpVotes' => 1, 'nbDownVotes' => 1, 'createdAt' => '2015-01-01 00:00:00', 'updatedAt' => '2015-01-01 00:00:00'], 'children' => [['entity' => ['id' => 5, 'authorName' => 'Marc Morera', 'authorEmail' => '*****@*****.**', 'context' => 'admin', 'content' => 'comment5', 'nbVotes' => 2, 'nbUpVotes' => 1, 'nbDownVotes' => 1, 'createdAt' => '2015-01-01 00:00:00', 'updatedAt' => '2015-01-01 00:00:00'], 'children' => []]]]], $comments); }
/** * on Comment change * * @param AbstractCommentEvent $event Event */ public function onCommentChange(AbstractCommentEvent $event) { $comment = $event->getComment(); $this->commentCache->invalidateCache($comment->getSource(), $comment->getContext()); }