/** * @test */ public function thatCommentPostsWithWithAttachments() { $ticket = $this->_dummyTicket; $author = $this->createDiamanteUser(); $comment = new Comment(self::DUMMY_COMMENT_CONTENT, $ticket, $author, false); $this->ticketRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_TICKET_ID))->will($this->returnValue($ticket)); $this->commentFactory->expects($this->once())->method('create')->with($this->equalTo(self::DUMMY_COMMENT_CONTENT), $this->equalTo($ticket), $this->equalTo($author))->will($this->returnValue($comment)); $this->ticketRepository->expects($this->once())->method('store')->with($this->equalTo($ticket)); $attachmentInputs = $this->attachmentInputs(); $this->attachmentManager->expects($this->exactly(count($attachmentInputs)))->method('createNewAttachment')->with($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING), $this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING), $this->equalTo($comment)); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('CREATE'), $this->equalTo('Entity:DiamanteDeskBundle:Comment'))->will($this->returnValue(true)); $command = new CommentCommand(); $command->content = self::DUMMY_COMMENT_CONTENT; $command->ticket = self::DUMMY_TICKET_ID; $command->author = $author; $command->ticketStatus = Status::IN_PROGRESS; $command->attachmentsInput = $attachmentInputs; $this->service->postNewCommentForTicket($command); $this->assertCount(1, $ticket->getComments()); $this->assertEquals($comment, $ticket->getComments()->get(0)); }
/** * Post Comment for Ticket * * @ApiDoc( * description="Post comment", * uri="/comments.{_format}", * method="POST", * resource=true, * statusCodes={ * 201="Returned when successful", * 403="Returned when the user is not authorized to post comment" * } * ) * * @param Command\CommentCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Comment */ public function postNewCommentForTicket(Command\CommentCommand $command) { $this->prepareAttachmentInput($command); return parent::postNewCommentForTicket($command); }