/** * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * * @covers \Netgen\TagsBundle\Core\Repository\TagsService::createTag * @depends testNewTagCreateStruct */ public function testCreateTagThrowsUnauthorizedException() { $this->repository->setCurrentUser($this->getStubbedUser(10)); $createStruct = $this->tagsService->newTagCreateStruct(40, 'eng-GB'); $createStruct->remoteId = 'New remote ID'; $this->tagsService->createTag($createStruct); }
/** * Creates a new tag. * * @param \Symfony\Component\HttpFoundation\Request $request * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException If there was an error while creating the tag * * @return \Netgen\TagsBundle\Core\REST\Server\Values\CreatedTag */ public function createTag(Request $request) { $synonymCreateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent())); try { $createdTag = $this->tagsService->createTag($synonymCreateStruct); } catch (InvalidArgumentException $e) { throw new ForbiddenException($e->getMessage()); } return new Values\CreatedTag(new Values\RestTag($createdTag, 0, 0)); }
/** * Creates the new tag. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to create this tag * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the remote ID already exists * * @param \Netgen\TagsBundle\API\Repository\Values\Tags\TagCreateStruct $tagCreateStruct * * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag The newly created tag */ public function createTag(TagCreateStruct $tagCreateStruct) { $returnValue = $this->service->createTag($tagCreateStruct); $this->signalDispatcher->emit(new CreateTagSignal(array('tagId' => $returnValue->id, 'parentTagId' => $returnValue->parentTagId, 'keywords' => $returnValue->keywords, 'mainLanguageCode' => $returnValue->mainLanguageCode, 'alwaysAvailable' => $returnValue->alwaysAvailable))); return $returnValue; }