public function testGenerateGridFilterUrl() { $returnedFilter = new Filter('testFilter', 'testServiceId'); $this->filterRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_FILTER_ID))->will($this->returnValue($returnedFilter)); $this->container->expects($this->once())->method('get')->with($this->equalTo($returnedFilter->getServiceId()))->will($this->returnValue($this->filterUrlGenerator)); $this->filterUrlGenerator->expects($this->once())->method('generateFilterUrlPart'); $this->ticketGridFiltersService->generateGridFilterUrl(self::DUMMY_FILTER_ID); }
protected function setUp() { MockAnnotations::init($this); $factory = new TicketFactory('\\Diamante\\DeskBundle\\Model\\Ticket\\Ticket'); $this->builder = new CommonTicketBuilder($factory, $this->branchRepository, $this->userService); $this->branchRepository->expects($this->once())->method('get')->with(self::BRANCH_ID)->will($this->returnValue($this->createBranch())); $this->userService->expects($this->once())->method('getByUser')->with(new User(self::ASSIGNEE_ID, User::TYPE_ORO))->will($this->returnValue($this->createAssignee())); }
/** * @test */ public function testBranchDefaultAssigneeRetrieved() { $this->branchRepository->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->branch)); $this->branch->expects($this->once())->method('getDefaultAssigneeId')->will($this->returnValue(1)); $assignee = $this->branchEmailConfigurationServiceImpl->getBranchDefaultAssignee(1); $this->assertEquals(1, $assignee); }
/** * @param string $filterId * @return mixed */ public function generateGridFilterUrl($filterId) { /** * @var $filter \Diamante\DeskBundle\Model\Ticket\Filter */ $filter = $this->filterRepository->get($filterId); if (!$filter) { throw new \RuntimeException('Filter loading failed, filter not found.'); } $concreteFilterUrlGenerator = $this->container->get($filter->getServiceId()); if (!$concreteFilterUrlGenerator) { throw new \RuntimeException('Filter generator loading failed, filter generator not found.'); } if (!$concreteFilterUrlGenerator instanceof FilterUrlGeneratorInterface) { throw new \InvalidArgumentException(sprintf('Object should be an instance of FilterUrlGeneratorInterface.')); } return $concreteFilterUrlGenerator->generateFilterUrlPart(); }
/** * @test */ public function deleteAttachment() { $pathname = 'some/path/file.ext'; $filename = 'file.ext'; $attachment = new Attachment(new File($pathname)); $this->fileStorageService->expects($this->once())->method('remove')->with($this->equalTo($filename)); $this->repository->expects($this->once())->method('remove')->with($this->equalTo($attachment)); $this->manager->deleteAttachment($attachment); }
/** * @param int $id * @return $this */ public function setBranchId($id) { $branch = $this->branchRepository->get((int) $id); if (is_null($branch)) { throw new \LogicException('Branch loading failed, branch not found.'); } $this->branch = $branch; return $this; }
/** * @param $branchId * @return int */ public function getBranchDefaultAssignee($branchId) { /** * @var $branch \Diamante\DeskBundle\Model\Branch\Branch */ $branch = $this->branchRepository->get($branchId); if (empty($branch)) { throw new \RuntimeException('No branch with given ID found'); } return $branch->getDefaultAssigneeId(); }
/** * Create Ticket * * @ApiDoc( * description="Create ticket", * uri="/tickets.{_format}", * method="POST", * resource=true, * statusCodes={ * 201="Returned when successful", * 403="Returned when the user is not authorized to create ticket" * } * ) * * @param CreateTicketCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Ticket */ public function createTicket(CreateTicketCommand $command) { if (empty($command->assignee)) { $branch = $this->branchRepository->get((int) $command->branch); if ($branch) { $command->assignee = $branch->getDefaultAssigneeId(); } } $this->prepareAttachmentInput($command); return parent::createTicket($command); }
/** * Delete Branch * @param int $branchId * @return void */ public function deleteBranch($branchId) { $this->isGranted('DELETE', 'Entity:DiamanteDeskBundle:Branch'); $branch = $this->branchRepository->get($branchId); if (is_null($branch)) { throw new \RuntimeException('Branch loading failed, branch not found. '); } if ($branch->getLogo()) { $this->branchLogoHandler->remove($branch->getLogo()); } $this->branchRepository->remove($branch); }
/** * Remove Attachment from Comment * @param RemoveCommentAttachmentCommand $command * @return void * @throws \RuntimeException if Comment does not exists or Comment has no particular attachment */ public function removeAttachmentFromComment(RemoveCommentAttachmentCommand $command) { $comment = $this->loadCommentBy($command->commentId); $this->isGranted('EDIT', $comment); $attachment = $comment->getAttachment($command->attachmentId); if (!$attachment) { throw new \RuntimeException('Attachment loading failed. Comment has no such attachment.'); } $comment->removeAttachment($attachment); $this->commentRepository->store($comment); $this->attachmentManager->deleteAttachment($attachment); }
public function testRenderTicket() { $tags = array(array('id' => 1, 'name' => 'Ticket Tag')); $renderTagResult = '<span class="tag-inline">Ticket Tag</span>'; $this->registry->expects($this->once())->method('getRepository')->will($this->returnValue($this->sharedRepository)); $this->tagManager->expects($this->once())->method('loadTagging')->will($this->returnValue($this->tagManager)); $this->twig->expects($this->once())->method('render')->will($this->returnValue($renderTagResult)); $this->sharedRepository->expects($this->once())->method('get')->will($this->returnValue($this->ticket)); $this->ticket->expects($this->once())->method('getTags')->will($this->returnValue($this->commonCollection)); $this->commonCollection->expects($this->once())->method('getValues')->will($this->returnValue($tags)); $ticketResult = $this->renderTagExtensionExtension->renderTag($this->twig, 1, 'ticket'); $this->assertEquals($renderTagResult, $ticketResult); }
/** * @test */ public function thatCommentCreatesWithAttachments() { $author = $this->createAuthor(); $ticket = $this->createDummyTicket(); $this->messageReferenceRepository->expects($this->once())->method('getReferenceByMessageId')->with($this->equalTo(self::DUMMY_MESSAGE_ID))->will($this->returnValue($this->messageReference)); $this->messageReference->expects($this->once())->method('getTicket')->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($this->comment)); $this->attachmentManager->expects($this->once())->method('createNewAttachment')->with($this->equalTo(self::DUMMY_FILENAME), $this->equalTo(self::DUMMY_FILE_CONTENT), $this->equalTo($this->comment)); $this->ticketRepository->expects($this->once())->method('store')->with($this->equalTo($ticket)); $this->messageReferenceService->createCommentForTicket(self::DUMMY_COMMENT_CONTENT, (string) $author, self::DUMMY_MESSAGE_ID, $this->attachments()); $this->assertCount(1, $ticket->getComments()); $this->assertEquals($this->comment, $ticket->getComments()->get(0)); }
/** * Delete Branch * @param int $branchId * @return void */ public function deleteBranch($branchId) { $this->isGranted('DELETE', 'Entity:DiamanteDeskBundle:Branch'); /** @var Branch $branch */ $branch = $this->branchRepository->get($branchId); if (is_null($branch)) { throw new BranchNotFoundException(); } if ($branch->getLogo()) { $this->branchLogoHandler->remove($branch->getLogo()); } $this->branchRepository->remove($branch); }
/** * Create Ticket * * @ApiDoc( * description="Create ticket", * uri="/tickets.{_format}", * method="POST", * resource=true, * statusCodes={ * 201="Returned when successful", * 403="Returned when the user is not authorized to create ticket" * } * ) * * @param CreateTicketCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Ticket */ public function createTicket(CreateTicketCommand $command) { if (0 === $command->branch) { $command->branch = (int) $this->configManager->get('diamante_email_processing.default_branch'); } if (empty($command->assignee)) { $branch = $this->branchRepository->get((int) $command->branch); if ($branch) { $command->assignee = $branch->getDefaultAssigneeId(); } } $this->prepareAttachmentInput($command); return parent::createTicket($command); }
public function testUpdateProperties() { $this->branchRepository->expects($this->once())->method('get')->will($this->returnValue($this->branch)); $name = 'DUMMY_NAME_UPDT'; $description = 'DUMMY_DESC_UPDT'; $this->branch->expects($this->at(0))->method('updateProperty')->with($this->equalTo('name'), $this->equalTo($name)); $this->branch->expects($this->at(1))->method('updateProperty')->with($this->equalTo('description'), $this->equalTo($description)); $this->branchRepository->expects($this->once())->method('store')->with($this->equalTo($this->branch)); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo('Entity:DiamanteDeskBundle:Branch'))->will($this->returnValue(true)); $command = new UpdatePropertiesCommand(); $command->id = 1; $command->properties = ['name' => $name, 'description' => $description]; $this->branchServiceImpl->updateProperties($command); }
/** * @test */ public function thatAttachmentRemovesFromComment() { $attachment = new Attachment(new File('some/path/file.ext')); $this->commentRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_COMMENT_ID))->will($this->returnValue($this->comment)); $this->comment->expects($this->once())->method('getAttachment')->with($this->equalTo(1))->will($this->returnValue($attachment)); $this->comment->expects($this->once())->method('removeAttachment')->with($this->equalTo($attachment)); $this->attachmentManager->expects($this->once())->method('deleteAttachment')->with($this->equalTo($attachment)); $this->commentRepository->expects($this->once())->method('store')->with($this->equalTo($this->comment)); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo($this->comment))->will($this->returnValue(true)); $removeCommentAttachmentCommand = new RemoveCommentAttachmentCommand(); $removeCommentAttachmentCommand->attachmentId = 1; $removeCommentAttachmentCommand->commentId = self::DUMMY_COMMENT_ID; $this->service->removeAttachmentFromComment($removeCommentAttachmentCommand); }
/** * Post Comment for Ticket * @param Command\CommentCommand $command * @return Comment * * @throws ForbiddenException * @throws TicketNotFoundException */ public function postNewCommentForTicket(Command\CommentCommand $command) { $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Comment'); \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput'); /** * @var $ticket \Diamante\DeskBundle\Model\Ticket\Ticket */ $ticket = $this->loadTicketBy($command->ticket); $author = User::fromString($command->author); $comment = $this->commentFactory->create($command->content, $ticket, $author, $command->private); $this->createAttachments($command, $comment); $ticket->updateStatus(new Status($command->ticketStatus)); $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchWorkflowEvent($this->registry, $this->dispatcher, $comment); return $comment; }
/** * Creates Comment for Ticket * * @param $content * @param $authorId * @param $messageId * @param array $attachments * @return Ticket|null */ public function createCommentForTicket($content, $authorId, $messageId, array $attachments = null) { $reference = $this->messageReferenceRepository->getReferenceByMessageId($messageId); if (is_null($reference)) { $this->logger->error(sprintf('Ticket not found for message: %s', $messageId)); throw new \RuntimeException('Ticket loading failed, ticket not found.'); } $ticket = $reference->getTicket(); $author = User::fromString($authorId); if (empty($content)) { return null; } $comment = $this->commentFactory->create($content, $ticket, $author); if ($attachments) { $this->createAttachments($attachments, $comment); } $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchEvents($ticket); return $ticket; }
/** * Delete attachment * @param Attachment $attachment * @return void */ public function deleteAttachment(Attachment $attachment) { $this->fileStorageService->remove($attachment->getFilename()); $this->repository->remove($attachment); }