/** * Remove a comment * * @param CommentInterface $comment Comment * * @return $this Self object */ public function removeComment(CommentInterface $comment) { $this->commentEventDispatcher->dispatchCommentPreRemoveEvent($comment); $this->commentDirector->save($comment); $this->commentEventDispatcher->dispatchCommentOnRemoveEvent($comment); return $this; }
/** * Vote action * * @param CommentInterface $comment Comment * @param string $authorToken Author token * @param boolean $type Vote type * * @return VoteInterface Vote */ public function vote(CommentInterface $comment, $authorToken, $type) { /** * @var VoteInterface $vote */ $vote = $this->commentVoteObjectDirector->findOneBy(['authorToken' => $authorToken, 'comment' => $comment]); $edited = true; if (!$vote instanceof VoteInterface) { $vote = $this->commentVoteObjectDirector->create()->setAuthorToken($authorToken)->setComment($comment); $edited = false; } $vote->setType($type); $this->commentVoteObjectDirector->save($vote); $this->commentEventDispatcher->dispatchCommentOnVotedEvent($comment, $vote, $edited); return $vote; }
/** * Test vote when exists. */ public function testExistingVote() { $vote = new Vote(); $vote->setAuthorToken($this->authorToken)->setComment($this->comment)->setType(Vote::UP); $this->voteDirector->expects($this->any())->method('findOneBy')->will($this->returnValue($vote)); $this->voteDirector->expects($this->never())->method('create'); $this->commentEventDispatcher->expects($this->once())->method('dispatchCommentOnVotedEvent')->with($this->equalTo($this->comment), $this->equalTo($vote), $this->equalTo(true)); $vote = $this->voteManager->vote($this->comment, $this->authorToken, Vote::DOWN); $this->assertSame($this->authorToken, $vote->getAuthorToken()); $this->assertSame($this->comment, $vote->getComment()); $this->assertSame(Vote::DOWN, $vote->getType()); }